I'm migrating a Spring 3 webapp to a Spring 4 Spring Boot webapp.
In Spring 3 I used the XML based configuration of Spring Security and defined something like this:
<sec:http pattern="/**/*.css" security="none" />
<sec:http pattern="/**/*.js" security="none" />
<sec:http pattern="^.*\?basic-auth=on$" request-matcher="regex" create-session="never">
<sec:intercept-url pattern="/**" access="IS_AUTHENTICATED_FULLY" />
<sec:http-basic />
</sec:http>
<sec:http name="formAuth" pattern="^(.*(\?|&)form-auth=on)|/servlet/login\.html|/servlet/!login\.html$" request-matcher="regex"
entry-point-ref="security.formLogin.entryPoint">
<sec:intercept-url pattern="/servlet/login.html" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<sec:intercept-url pattern="/servlet/!login.html" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<sec:intercept-url pattern="/**" access="IS_AUTHENTICATED_FULLY" />
<sec:form-login login-page="/servlet/login.html"
login-processing-url="/servlet/!login.html"
default-target-url="/" authentication-failure-handler-ref="accessDeniedHandler"></sec:form-login>
</sec:http>
Some explanations: The entire page (excluding CSS, JS) is access protected. There are multiple login mechanism like Kerberos (not shown), basic auth and form login. If the preferred login mechanism Kerberos fails, the user is redirected to the form login. This happens when the same url with '&form-auth=on' appendix is requested, so the filter chain named 'formAuth' is activted.
Problem: If I trying to access a JS or CSS file (not protected resource) I got the excepetion AuthenticationCredentialsNotFoundException
org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext
at org.springframework.security.access.intercept.AbstractSecurityInterceptor.credentialsNotFound(AbstractSecurityInterceptor.java:379)
at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:223)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:124)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:208)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.boot.web.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:115)
My Assumption Spring Boot adds every GenericFilterBean automatically to the filter chain (see here). So every of my beans of type GenericFilterBean is added to the ApplicationFilterChain and to the SpringSecurityFilterChain. To deny Spring Boot to add this filters to the ApplicationFilterChain I have to create a bean of type FilterRegistrationBean and set it to disabled.
But how can I create such a bean for the XML elements sec:intercept-url, sec:http-basic, sec:form-login which implicitly creates GenericFilterBeans like UsernamePasswordAuthenticationFilter or BasicAuthenticationFilter. The XML elements have no name or id attribute which I can use to create a FilterRegistrationBean.