Java 配置 Spring Security FORM_LOGIN_FILTER
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23922025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java Config Spring Security FORM_LOGIN_FILTER
提问by crownedzero
I'm working through some of the Spring Security tutorials and trying to implement them without xml and I can't seem to find a anything about replacing the default UsernamePasswordAuthenticationFilter.
我正在阅读一些 Spring Security 教程并尝试在没有 xml 的情况下实现它们,但我似乎找不到任何关于替换默认UsernamePasswordAuthenticationFilter 的内容。
Similar to this questionI'd like to retrieve an extra parameter from the login form. Where I'm having difficulty is:
与这个问题类似,我想从登录表单中检索一个额外的参数。我遇到困难的地方是:
<custom-filter ref="customAuthenticationProcessingFilter" position="FORM_LOGIN_FILTER"/>
In order to set this up properly do I need to build from the AuthenticationManagerBuilder down? or am I missing something?
为了正确设置它,我是否需要从 AuthenticationManagerBuilder 向下构建?或者我错过了什么?
回答by Juan Francisco Navarrete Martn
According to the Spring Security documentation found here:
根据此处找到的 Spring Security 文档:
http://docs.spring.io/spring-security/site/docs/3.0.x/reference/ns-config.html#filter-stack
http://docs.spring.io/spring-security/site/docs/3.0.x/reference/ns-config.html#filter-stack
FORM_LOGIN_FILTER is just an alias for the class UsernamePasswordAuthenticationFilter.
FORM_LOGIN_FILTER 只是 UsernamePasswordAuthenticationFilter 类的别名。
So
所以
http.addFilterBefore(new YourFilter(), UsernamePasswordAuthenticationFilter.class);
Should do the trick
应该做的伎俩
回答by Prabhat Choudhary
Thanks @Juan for good doc link. But you must use addFilterAt
instead of addFilterBefore
.
感谢@Juan 提供良好的文档链接。但是您必须使用addFilterAt
代替addFilterBefore
.
So, this is correct :
所以,这是正确的:
http.addFilterAt(new YourFilter(),UsernamePasswordAuthenticationFilter.class);
This will replace the existing default implementation with your CustomFilter.
这将用您的 CustomFilter 替换现有的默认实现。