diff --git a/src/main/java/de/thm/arsnova/config/SecurityConfig.java b/src/main/java/de/thm/arsnova/config/SecurityConfig.java index 95f1088333fa7231acfc900f01915aa7efdd6b15..fb30308d5e7d760ebd3b1f2f63312228f4019087 100644 --- a/src/main/java/de/thm/arsnova/config/SecurityConfig.java +++ b/src/main/java/de/thm/arsnova/config/SecurityConfig.java @@ -34,11 +34,15 @@ import org.springframework.security.ldap.authentication.LdapAuthenticator; import org.springframework.security.ldap.authentication.NullLdapAuthoritiesPopulator; import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.security.web.authentication.Http403ForbiddenEntryPoint; +import org.springframework.security.web.authentication.logout.LogoutFilter; +import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; +import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler; import com.github.leleuj.ss.oauth.client.authentication.OAuthAuthenticationProvider; import com.github.leleuj.ss.oauth.client.web.OAuthAuthenticationEntryPoint; import com.github.leleuj.ss.oauth.client.web.OAuthAuthenticationFilter; +import de.thm.arsnova.CASLogoutSuccessHandler; import de.thm.arsnova.CasUserDetailsService; import de.thm.arsnova.LoginAuthenticationFailureHandler; import de.thm.arsnova.LoginAuthenticationSucessHandler; @@ -70,6 +74,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { protected void configure(HttpSecurity http) throws Exception { http.exceptionHandling().authenticationEntryPoint(restAuthenticationEntryPoint()); http.addFilter(casAuthenticationFilter()); + http.addFilter(casLogoutFilter()); http.addFilterAfter(googleFilter(), CasAuthenticationFilter.class); http.addFilterAfter(facebookFilter(), CasAuthenticationFilter.class); http.addFilterAfter(twitterFilter(), CasAuthenticationFilter.class); @@ -148,6 +153,11 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { return new DbUserDetailsService(); } + @Bean + public SecurityContextLogoutHandler logoutHandler() { + return new SecurityContextLogoutHandler(); + } + // LDAP Authentication Configuration @Bean @@ -212,6 +222,23 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { return filter; } + @Bean + public LogoutFilter casLogoutFilter() { + LogoutFilter filter = new LogoutFilter(casLogoutSuccessHandler(), logoutHandler()); + filter.setFilterProcessesUrl("/j_spring_cas_security_logout"); + + return filter; + } + + @Bean + public LogoutSuccessHandler casLogoutSuccessHandler() { + CASLogoutSuccessHandler handler = new CASLogoutSuccessHandler(); + handler.setCasUrl(casUrl); + handler.setDefaultTarget(rootUrl); + + return handler; + } + // Facebook Authentication Configuration @Bean