|
26 | 26 | import org.springframework.security.config.Customizer; |
27 | 27 | import org.springframework.security.config.web.server.ServerHttpSecurity; |
28 | 28 | import org.springframework.security.web.server.SecurityWebFilterChain; |
| 29 | +import org.springframework.security.web.server.authentication.RedirectServerAuthenticationSuccessHandler; |
| 30 | +import org.springframework.security.web.server.authentication.ServerAuthenticationSuccessHandler; |
29 | 31 | import org.springframework.security.web.server.authentication.logout.RedirectServerLogoutSuccessHandler; |
30 | 32 | import org.springframework.security.web.server.authentication.logout.ServerLogoutSuccessHandler; |
31 | 33 |
|
@@ -64,19 +66,27 @@ public SecurityWebFilterChain securityWebFilterChainSecure(ServerHttpSecurity ht |
64 | 66 | .pathMatchers(this.adminServer.path("/assets/**")).permitAll() |
65 | 67 | .pathMatchers("/actuator/health/**").permitAll().pathMatchers(this.adminServer.path("/login")) |
66 | 68 | .permitAll().anyExchange().authenticated()) |
67 | | - .formLogin((formLogin) -> formLogin.loginPage(this.adminServer.path("/login"))) |
68 | | - .logout((logout) -> logout |
69 | | - .logoutUrl(this.adminServer.path("/logout")) |
| 69 | + .formLogin((formLogin) -> formLogin.loginPage(this.adminServer.path("/login")) |
| 70 | + .authenticationSuccessHandler(loginSuccessHandler(this.adminServer.path("/")))) |
| 71 | + .logout((logout) -> logout.logoutUrl(this.adminServer.path("/logout")) |
70 | 72 | .logoutSuccessHandler(logoutSuccessHandler(this.adminServer.path("/login?logout")))) |
71 | 73 | .httpBasic(Customizer.withDefaults()).csrf(ServerHttpSecurity.CsrfSpec::disable).build(); |
72 | 74 | } |
73 | 75 |
|
74 | | - public ServerLogoutSuccessHandler logoutSuccessHandler(String uri) { |
| 76 | + // The following two methods are only required when setting a custom base-path (see |
| 77 | + // 'basepath' profile in application.yml) |
| 78 | + private ServerLogoutSuccessHandler logoutSuccessHandler(String uri) { |
75 | 79 | RedirectServerLogoutSuccessHandler successHandler = new RedirectServerLogoutSuccessHandler(); |
76 | 80 | successHandler.setLogoutSuccessUrl(URI.create(uri)); |
77 | 81 | return successHandler; |
78 | 82 | } |
79 | 83 |
|
| 84 | + private ServerAuthenticationSuccessHandler loginSuccessHandler(String uri) { |
| 85 | + RedirectServerAuthenticationSuccessHandler successHandler = new RedirectServerAuthenticationSuccessHandler(); |
| 86 | + successHandler.setLocation(URI.create(uri)); |
| 87 | + return successHandler; |
| 88 | + } |
| 89 | + |
80 | 90 | @Bean |
81 | 91 | public LoggingNotifier loggerNotifier(InstanceRepository repository) { |
82 | 92 | return new LoggingNotifier(repository); |
|
0 commit comments