|
15 | 15 | import org.springframework.context.annotation.Bean;
|
16 | 16 | import org.springframework.context.annotation.Configuration;
|
17 | 17 | import org.springframework.http.HttpMethod;
|
| 18 | +import org.springframework.security.config.Customizer; |
18 | 19 | import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity;
|
19 | 20 | import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
|
20 | 21 | import org.springframework.security.config.web.server.SecurityWebFiltersOrder;
|
@@ -66,27 +67,24 @@ public class SecurityConfig {
|
66 | 67 | AuthRequestFactory<AuthRequestContext> authRequestFactory;
|
67 | 68 |
|
68 | 69 | @Bean
|
69 |
| - public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) { |
| 70 | + SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) { |
70 | 71 |
|
71 | 72 | if (!commonConfig.getSecurity().getForbiddenEndpoints().isEmpty())
|
72 | 73 | {
|
73 |
| - http.authorizeExchange() |
74 |
| - .matchers( |
75 |
| - commonConfig.getSecurity().getForbiddenEndpoints().stream() |
| 74 | + http.authorizeExchange(customizer -> customizer |
| 75 | + .matchers(commonConfig.getSecurity().getForbiddenEndpoints().stream() |
76 | 76 | .map(apiEndpoint -> ServerWebExchangeMatchers.pathMatchers(apiEndpoint.getMethod(), apiEndpoint.getUri()))
|
77 | 77 | .toArray(size -> new ServerWebExchangeMatcher[size])
|
78 |
| - ).denyAll(); |
| 78 | + ).denyAll() |
| 79 | + ); |
79 | 80 | }
|
80 | 81 |
|
81 |
| - http.cors() |
82 |
| - .configurationSource(buildCorsConfigurationSource()) |
83 |
| - .and() |
84 |
| - .csrf().disable() |
85 |
| - .anonymous().principal(createAnonymousUser()) |
86 |
| - .and() |
87 |
| - .httpBasic() |
88 |
| - .and() |
89 |
| - .authorizeExchange() |
| 82 | + http |
| 83 | + .cors(cors -> cors.configurationSource(buildCorsConfigurationSource())) |
| 84 | + .csrf(csrf -> csrf.disable()) |
| 85 | + .anonymous(anonymous -> anonymous.principal(createAnonymousUser())) |
| 86 | + .httpBasic(Customizer.withDefaults()) |
| 87 | + .authorizeExchange(customizer -> customizer |
90 | 88 | .matchers(
|
91 | 89 | ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, CUSTOM_AUTH + "/otp/send"), // sms verification
|
92 | 90 | ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, CUSTOM_AUTH + "/phone/login"),
|
@@ -134,19 +132,21 @@ public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
|
134 | 132 | ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.DATASOURCE_URL + "/jsDatasourcePlugins"),
|
135 | 133 | ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, "/api/docs/**")
|
136 | 134 | )
|
137 |
| - .permitAll() |
| 135 | + .permitAll() |
138 | 136 | .pathMatchers("/api/**")
|
139 |
| - .authenticated() |
| 137 | + .authenticated() |
140 | 138 | .pathMatchers("/test/**")
|
141 |
| - .authenticated() |
| 139 | + .authenticated() |
142 | 140 | .pathMatchers("/**")
|
143 |
| - .permitAll() |
| 141 | + .permitAll() |
144 | 142 | .anyExchange()
|
145 |
| - .authenticated(); |
| 143 | + .authenticated() |
| 144 | + ); |
146 | 145 |
|
147 |
| - http.exceptionHandling() |
| 146 | + http.exceptionHandling(customizer -> customizer |
148 | 147 | .authenticationEntryPoint(serverAuthenticationEntryPoint)
|
149 |
| - .accessDeniedHandler(accessDeniedHandler); |
| 148 | + .accessDeniedHandler(accessDeniedHandler) |
| 149 | + ); |
150 | 150 |
|
151 | 151 | http.addFilterBefore(new UserSessionPersistenceFilter(sessionUserService, cookieHelper, authenticationService, authenticationApiService, authRequestFactory), SecurityWebFiltersOrder.AUTHENTICATION);
|
152 | 152 |
|
|
0 commit comments