首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在使用AuthenticationManager添加自定义提供程序时获得AuthenticationManagerBuilder?

如何在使用AuthenticationManager添加自定义提供程序时获得AuthenticationManagerBuilder?
EN

Stack Overflow用户
提问于 2018-03-21 15:54:07
回答 1查看 6.7K关注 0票数 5

我正在使用SpringBoot2.0(利用SpringSecurity5.0)。我正在尝试在我的AuthenticationProvider子类中向AuthenticationManager添加一个自定义的WebSecurityConfigurerAdapter。如果我重写configure(AuthenticationManagerBuilder)方法来提供新的提供程序,那么我就不知道如何以bean的形式检索AuthenticationManager。

例如:

代码语言:javascript
运行
复制
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception 
    {
        auth.authenticationProvider(customAuthenticationProvider);
    }
}

其中customAuthenticationProvider实现了AuthenticationProvider

春季医生中,它似乎指定这两者是不兼容的:

5.8.4 AuthenticationProvider您可以通过将自定义AuthenticationProvider公开为bean来定义自定义身份验证。例如,假设SpringAuthenticationProvider实现了AuthenticationProvider,下面将定制身份验证: 注意,只有在未填充AuthenticationManagerBuilder的情况下才使用此方法。

实际上,如果我尝试使用以下方法检索AuthenticationManager bean:

代码语言:javascript
运行
复制
@Bean
public AuthenticationManager authenticationManager() throws Exception {
    return super.authenticationManagerBean();
}

那么configure()方法甚至从未被调用过。

那么,如何将自己的自定义提供程序添加到默认的提供程序列表中,并且仍然能够检索AuthenticationManager?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-21 16:14:10

您只需重写WebSecurityConfigurerAdapter.authenticationManagerBean()方法并用@Bean注释对其进行注释。

代码语言:javascript
运行
复制
 @Bean
 @Override
 public AuthenticationManager authenticationManagerBean() throws Exception {
     return super.authenticationManagerBean();
 }

而且没有SpringBoot5.0,最新的版本是SpringBoot2.0。我相信你说的是SpringSecurity5.0。

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49410977

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档