#BAEL-5443: add logout config

This commit is contained in:
h_sharifi 2022-09-14 11:02:02 +04:30
parent bca12a0764
commit 898661f142
1 changed files with 11 additions and 1 deletions

View File

@ -13,6 +13,12 @@ import org.springframework.security.web.authentication.session.SessionAuthentica
@EnableWebSecurity @EnableWebSecurity
class SecurityConfig extends WebSecurityConfigurerAdapter { class SecurityConfig extends WebSecurityConfigurerAdapter {
private final KeycloakLogoutHandler keycloakLogoutHandler;
SecurityConfig(KeycloakLogoutHandler keycloakLogoutHandler) {
this.keycloakLogoutHandler = keycloakLogoutHandler;
}
@Bean @Bean
protected SessionAuthenticationStrategy sessionAuthenticationStrategy() { protected SessionAuthenticationStrategy sessionAuthenticationStrategy() {
return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl()); return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl());
@ -25,7 +31,11 @@ class SecurityConfig extends WebSecurityConfigurerAdapter {
.hasRole("USER") .hasRole("USER")
.anyRequest() .anyRequest()
.permitAll(); .permitAll();
http.oauth2Login(); http.oauth2Login()
.and()
.logout()
.addLogoutHandler(keycloakLogoutHandler)
.logoutSuccessUrl("/");
} }
} }