Skip to content

Commit bcde50c

Browse files
committed
fix: update syntax for spring security 6
1 parent 8f85d57 commit bcde50c

File tree

1 file changed

+21
-21
lines changed
  • server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/framework/security

1 file changed

+21
-21
lines changed

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/framework/security/SecurityConfig.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.springframework.context.annotation.Bean;
1616
import org.springframework.context.annotation.Configuration;
1717
import org.springframework.http.HttpMethod;
18+
import org.springframework.security.config.Customizer;
1819
import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity;
1920
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
2021
import org.springframework.security.config.web.server.SecurityWebFiltersOrder;
@@ -66,27 +67,24 @@ public class SecurityConfig {
6667
AuthRequestFactory<AuthRequestContext> authRequestFactory;
6768

6869
@Bean
69-
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
70+
SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
7071

7172
if (!commonConfig.getSecurity().getForbiddenEndpoints().isEmpty())
7273
{
73-
http.authorizeExchange()
74-
.matchers(
75-
commonConfig.getSecurity().getForbiddenEndpoints().stream()
74+
http.authorizeExchange(customizer -> customizer
75+
.matchers(commonConfig.getSecurity().getForbiddenEndpoints().stream()
7676
.map(apiEndpoint -> ServerWebExchangeMatchers.pathMatchers(apiEndpoint.getMethod(), apiEndpoint.getUri()))
7777
.toArray(size -> new ServerWebExchangeMatcher[size])
78-
).denyAll();
78+
).denyAll()
79+
);
7980
}
8081

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
9088
.matchers(
9189
ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, CUSTOM_AUTH + "/otp/send"), // sms verification
9290
ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, CUSTOM_AUTH + "/phone/login"),
@@ -134,19 +132,21 @@ public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
134132
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, NewUrl.DATASOURCE_URL + "/jsDatasourcePlugins"),
135133
ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, "/api/docs/**")
136134
)
137-
.permitAll()
135+
.permitAll()
138136
.pathMatchers("/api/**")
139-
.authenticated()
137+
.authenticated()
140138
.pathMatchers("/test/**")
141-
.authenticated()
139+
.authenticated()
142140
.pathMatchers("/**")
143-
.permitAll()
141+
.permitAll()
144142
.anyExchange()
145-
.authenticated();
143+
.authenticated()
144+
);
146145

147-
http.exceptionHandling()
146+
http.exceptionHandling(customizer -> customizer
148147
.authenticationEntryPoint(serverAuthenticationEntryPoint)
149-
.accessDeniedHandler(accessDeniedHandler);
148+
.accessDeniedHandler(accessDeniedHandler)
149+
);
150150

151151
http.addFilterBefore(new UserSessionPersistenceFilter(sessionUserService, cookieHelper, authenticationService, authenticationApiService, authRequestFactory), SecurityWebFiltersOrder.AUTHENTICATION);
152152

0 commit comments

Comments
 (0)