How to replace UsernamePasswordAuthenticationFilter in Spring Security
java, spring, spring-security
Solution
If you take a look to FormLoginConfigurer you will see that the UsernamePasswordAuthenticationFilter is created and inserted to AbstractAuthenticationFilterConfigurer constructor then there it is assigned to final F authFilter so there is no way to replace it in Spring Security 4.1
addFilter() will simply add another filter to filter list
Problem
Using XML configuration would be like ``` <custom-filter position="FORM_LOGIN_FILTER" ref="SCAAuthenticationFilter" />. ``` Without XML would be like: ``` httpSecurity.addFilter(new SCAAthenticationFilter()) ``` It seems that spring doesn't replace UsernamePasswordAuthenticationFilter, but adds my filter before.