|
1 | 1 | package io.kafbat.ui.config.auth; |
2 | 2 |
|
3 | | -import static io.kafbat.ui.config.auth.AbstractAuthSecurityConfig.AUTH_WHITELIST; |
4 | | - |
5 | 3 | import io.kafbat.ui.service.rbac.AccessControlService; |
6 | 4 | import io.kafbat.ui.service.rbac.extractor.RbacLdapAuthoritiesExtractor; |
7 | 5 | import io.kafbat.ui.util.StaticFileWebFilter; |
|
15 | 13 | import org.springframework.context.ApplicationContext; |
16 | 14 | import org.springframework.context.annotation.Bean; |
17 | 15 | import org.springframework.context.annotation.Configuration; |
| 16 | +import org.springframework.http.HttpMethod; |
18 | 17 | import org.springframework.ldap.core.DirContextOperations; |
19 | 18 | import org.springframework.ldap.core.support.BaseLdapPathContextSource; |
20 | 19 | import org.springframework.ldap.core.support.LdapContextSource; |
21 | 20 | import org.springframework.security.authentication.AuthenticationManager; |
22 | 21 | import org.springframework.security.authentication.ProviderManager; |
23 | 22 | import org.springframework.security.authentication.ReactiveAuthenticationManager; |
24 | 23 | import org.springframework.security.authentication.ReactiveAuthenticationManagerAdapter; |
25 | | -import org.springframework.security.config.Customizer; |
26 | 24 | import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; |
27 | 25 | import org.springframework.security.config.web.server.SecurityWebFiltersOrder; |
28 | 26 | import org.springframework.security.config.web.server.ServerHttpSecurity; |
|
38 | 36 | import org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator; |
39 | 37 | import org.springframework.security.ldap.userdetails.LdapUserDetailsMapper; |
40 | 38 | import org.springframework.security.web.server.SecurityWebFilterChain; |
| 39 | +import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatchers; |
41 | 40 |
|
42 | 41 | @Configuration |
43 | 42 | @EnableWebFluxSecurity |
44 | 43 | @ConditionalOnProperty(value = "auth.type", havingValue = "LDAP") |
45 | 44 | @EnableConfigurationProperties(LdapProperties.class) |
46 | 45 | @RequiredArgsConstructor |
47 | 46 | @Slf4j |
48 | | -public class LdapSecurityConfig { |
| 47 | +public class LdapSecurityConfig extends AbstractAuthSecurityConfig { |
49 | 48 |
|
50 | 49 | private final LdapProperties props; |
51 | 50 |
|
@@ -129,8 +128,13 @@ public SecurityWebFilterChain configureLdap(ServerHttpSecurity http) { |
129 | 128 | .anyExchange() |
130 | 129 | .authenticated() |
131 | 130 | ) |
132 | | - .formLogin(Customizer.withDefaults()) |
133 | | - .logout(Customizer.withDefaults()) |
| 131 | + .formLogin(form -> form |
| 132 | + .loginPage(LOGIN_URL) |
| 133 | + .authenticationSuccessHandler(emptyRedirectSuccessHandler()) |
| 134 | + ) |
| 135 | + .logout(spec -> spec |
| 136 | + .logoutSuccessHandler(redirectLogoutSuccessHandler()) |
| 137 | + .requiresLogout(ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, "/logout"))) |
134 | 138 | .csrf(ServerHttpSecurity.CsrfSpec::disable); |
135 | 139 |
|
136 | 140 | builder.addFilterAt(new StaticFileWebFilter(), SecurityWebFiltersOrder.LOGIN_PAGE_GENERATING); |
|
0 commit comments