(Un) lucky, I had a similar problem;) This happens when CAS tries to call your application to exit the system. On the one hand, CAS is trying to pass sessionId to perform a logout, on the other hand, SpringSecurity expects to receive a CSRF token that has not been sent by CAS, since it only sends a GET request. CsrfFilter does not find the csrf token and breaks the filter chain. The user is unaware of this because the CAS invokes the logout request implicitly. The request is sent directly from the CAS server to the application server, and not by redirecting the user in a web browser.
To do this, you need to configure HttpSecurity to exclude / not enable LogoutFilter filterProcessesUrl (which is located in j_spring_security_logout in your case when you use it by default).
Assuming you want to check the CSRF when trying to create a new administrator, for insatnce you need to configure it like this:
@Override protected void configure(HttpSecurity http) throws Exception { http.addFilter(casAuthenticationFilter()); http.addFilterBefore(requestLogoutFilter(), LogoutFilter.class); http.addFilterBefore(singleSignOutFilter(), CasAuthenticationFilter.class); http.exceptionHandling() .authenticationEntryPoint(casAuthenticationEntryPoint()); http.authorizeRequests() .antMatchers("/admin/**").access("hasRole('ROLE_ADMIN')") .antMatchers("/dba/**").access("hasRole('ROLE_ADMIN') or hasRole('ROLE_DBA')"); http.csrf() .requireCsrfProtectionMatcher(new AntPathRequestMatcher("/admin/create")); http.logout() .addLogoutHandler(handler) .deleteCookies("remove") .invalidateHttpSession(true) .logoutUrl("/logout") .logoutSuccessUrl("/"); }
Just to indicate I added
http.csrf().requireCsrfProtectionMatcher(new AntPathRequestMatcher("/admin/create")); .
Note that you cannot use match all pattern (/ admin / **), since you probably want to also trigger some receive requests, and the CSRF filter will wait for them to send a token.
This problem does not occur when using Spring Security prior to 3.2.x, since it introduced support for the cross-site request request routine (CSRF).
Hope this help :)
source share