【问题标题】:Custom AuthenticationFilter with token-based authentication具有基于令牌的身份验证的自定义 AuthenticationFilter
【发布时间】:2015-09-13 00:11:23
【问题描述】:

我正在使用基于令牌的身份验证。我有一个自定义身份验证过滤器,它执行 REST 调用来对用户进行身份验证。我设法创建和配置自定义身份验证提供程序,但无法设置提供程序的顺序。我希望默认 DaoAuthenticationProvider 是默认值,而 customProvider 是次要的。

这就是我配置 customAuthenticationProvider 的方式

@Inject
private CustomAuthenticationProvider customAuthenticationProvider;

@Inject
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth.authenticationProvider(customAuthenticationProvider)
        .userDetailsService(userDetailsService)
        .passwordEncoder(passwordEncoder());
}

如何将 customAuthenticationProvider 配置为第二个提供者?

PS:我无法将 customAuthenticationProvider 注入 SecurityConfiguration.java,因为在我将以下范围添加到 customAuthenticationProvider 之前无法创建代理。

@Component("alfrescoAuthenticationProvider")
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS, value = "prototype")
public class AlfrescoAuthenticationProvider implements AuthenticationProvider {
   ....
}

【问题讨论】:

    标签: jhipster


    【解决方案1】:

    我不明白你说的为什么不能注射。我的 SecurityConfiguration 类如下:

    @配置 @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true, secureEnabled = true) 公共类 SecurityConfiguration 扩展 WebSecurityConfigurerAdapter {

    @Inject
    private Http401UnauthorizedEntryPoint authenticationEntryPoint;
    
    @Inject
    private UserDetailsService userDetailsService;
    
    @Inject
    private TokenProvider tokenProvider;
    
    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
    
    @Inject
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .userDetailsService(userDetailsService)
                .passwordEncoder(passwordEncoder());
        auth.authenticationProvider(weixinAuthenticationProvider());
    }
    
    @Bean
    public WeixinAuthenticationProvider weixinAuthenticationProvider() {
        WeixinAuthenticationProvider provider = new WeixinAuthenticationProvider(userDetailsService, passwordEncoder());
        return provider;
    }
    
    @Override
    public void configure(WebSecurity web) throws Exception {
        ......
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2017-03-10
      • 1970-01-01
      • 2011-03-18
      • 2021-01-25
      • 1970-01-01
      • 2016-01-23
      • 2016-01-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多