使用XML配置就像
<custom-filter position="FORM_LOGIN_FILTER" ref="SCAAuthenticationFilter" />.
没有XML就像:
httpSecurity.addFilter(new SCAAthenticationFilter())
似乎spring不会取代 UsernamePasswordAuthenticationFilter ,但之前会添加我的过滤器。
答案 0 :(得分:2)
如果您查看 FormLoginConfigurer ,您将看到 UsernamePasswordAuthenticationFilter 已创建并插入 AbstractAuthenticationFilterConfigurer 构造函数,然后将其分配给 final F authFilter 所以无法在Spring Security 4.1中替换它
addFilter()只会添加另一个过滤器来过滤列表
答案 1 :(得分:0)
我猜您的配置中必须有<form-login>
或<http auto-config="true">
。除非其中任何一个存在,否则Spring Security不会自动添加UsernamePasswordAuthenticationFilter
。提交表单的URL和参数名称都是过滤器的可配置属性,您的自定义版本没有覆盖,因此存在差异。