Hello together, i hope someone can help me here.
Informations:
I have a spring boot application depolyed on google cloud and there for i need to enable CORS, that my local frontend can send rest calls to this springboot application (backend). I also use Spring Security
SecurityConfiguration class:
https://hastebin.skyra.pw/qocuyosubu.java
Those Methode are in the SecurityConfiguration
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
HttpSecurity httpSecurity = http
.csrf(AbstractHttpConfigurer::disable)
.requiresChannel(channel -> channel.anyRequest().requiresSecure())
.authorizeHttpRequests(request -> request.requestMatchers("/api/v1/auth/**")
.permitAll().anyRequest().authenticated())
.sessionManagement(manager -> manager.sessionCreationPolicy(STATELESS))
.authenticationProvider(authenticationProvider())
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
return httpSecurity.build();
}
@Bean
public CorsConfigurationSource configurationSource() {
log.info("Load CorsConfigurationSource");
UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setAllowCredentials(true);
corsConfiguration.setAllowedOrigins(Collections.singletonList("*"));
corsConfiguration.setAllowedMethods(Collections.singletonList("*"));
corsConfiguration.setAllowedHeaders(Collections.singletonList("*"));
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
return urlBasedCorsConfigurationSource;
}
Here is an example of RestController (LoginController):
https://hastebin.skyra.pw/otopoxukem.kotlinHere