Skip to content

Commit

Permalink
Redirect to correct context on logout in Reactive security example (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ViliusS committed Jul 8, 2022
1 parent 568d102 commit d8913e8
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package de.codecentric.boot.admin;

import java.net.URI;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
Expand All @@ -24,6 +26,8 @@
import org.springframework.security.config.Customizer;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;
import org.springframework.security.web.server.authentication.logout.RedirectServerLogoutSuccessHandler;
import org.springframework.security.web.server.authentication.logout.ServerLogoutSuccessHandler;

import de.codecentric.boot.admin.server.config.AdminServerProperties;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
Expand Down Expand Up @@ -61,10 +65,18 @@ public SecurityWebFilterChain securityWebFilterChainSecure(ServerHttpSecurity ht
.pathMatchers("/actuator/health/**").permitAll().pathMatchers(this.adminServer.path("/login"))
.permitAll().anyExchange().authenticated())
.formLogin((formLogin) -> formLogin.loginPage(this.adminServer.path("/login")))
.logout((logout) -> logout.logoutUrl(this.adminServer.path("/logout")))
.logout((logout) -> logout
.logoutUrl(this.adminServer.path("/logout"))
.logoutSuccessHandler(logoutSuccessHandler(this.adminServer.path("/login?logout"))))
.httpBasic(Customizer.withDefaults()).csrf(ServerHttpSecurity.CsrfSpec::disable).build();
}

public ServerLogoutSuccessHandler logoutSuccessHandler(String uri) {
RedirectServerLogoutSuccessHandler successHandler = new RedirectServerLogoutSuccessHandler();
successHandler.setLogoutSuccessUrl(URI.create(uri));
return successHandler;
}

@Bean
public LoggingNotifier loggerNotifier(InstanceRepository repository) {
return new LoggingNotifier(repository);
Expand Down

0 comments on commit d8913e8

Please sign in to comment.