请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

AuthenticationManagerBuilder 注册 Provider问题

老师, 您好, 在使用了自定义的AuthenticationFilter之后, 我尝试者使用了三个Provider

@Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(authenticationProvider())
            .authenticationProvider(sudoAuthenticationProvider)
            .authenticationProvider(customAdminAuthenticationProvider);
    }

发现了仅DaoAuthenticationProvider 和 CustomAdminAuthenticationProvider 会生效, 而SudoAuthenticationProvider不会生效, 是什么原因造成的呢?

正在回答

1回答

嗨同学你好,很抱歉回复的晚了些。
你提出的问题是因为CustomAuthenticationFilter中定义authToken类型为CustomAuthenticationToken, 所以在SudoAuthenticationProvider中判断支持的条件authentication.equals(UsernamePasswordAuthenticationToken.class)就会返回false;相比较下,CustomAdminAuthenticationProvider判断的条件为authentication.equals(CustomAuthenticationToken.class) [返回true], DaoAuthenticationProvider判断条件为UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication) [返回true],所以这两者都可以生效。如果你也想让SudoAuthenticationProvider在CustomAuthenticationFilter中生效,修改判断条件为UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication) 即可。

1 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号