I have the following Spring Security configuration:
@Bean
public SecurityWebFilterChain springSecurityFilterChain (ServerHttpSecurity http) {
http.csrf().disable()
.authorizeExchange()
.pathMatchers("/api/**")
.permitAll()
.anyExchange()
.authenticated()
.and()
.oauth2Login(); // to redirect to oauth2 login page.
http.cors().configurationSource(request-> {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(Arrays.asList("http://localhost:3000");
configuration.setAllowedMethods(Arrays.asList("GET","POST", "OPTIONS"));
configuration.setAllowedHeaders(List.of("*"));
return configuration;
});
return http.build();
}
I get multiple errors in Spring Cloud 2023.0.1:
'csrf()' is deprecated since version 6.1 and marked for removal
'authorizeExchange()' is deprecated since version 6.1 and marked for removal
'and()' is deprecated since version 6.1 and marked for removal
'oauth2Login()' is deprecated since version 6.1 and marked for removal
'cors()' is deprecated since version 6.1 and marked for removal
I tried to migrate the code this way:
http.csrf(CsrfConfigurer::disable)
.authorizeExchange((authz) -> authz
.pathMatchers("/")
.permitAll()
.anyExchange()
.authenticated()
.and()
.oauth2Login() // to redirect to oauth2 login page.
);
http.cors().configurationSource(request-> {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(Arrays.asList("http://localhost:3000");
configuration.setAllowedMethods(Arrays.asList("GET","POST", "OPTIONS"));
configuration.setAllowedHeaders(List.of("*"));
return configuration;
});
I get:
CsrfConfigurer::disable -> Non-static method cannot be referenced from a static context
'oauth2Login()' is deprecated since version 6.1 and marked for removal
Do you know what is the proper way to migrate the code?