Frühling 3.3.1 CORs Problem mit mehreren HerkunftJava

Java-Forum
Anonymous
 Frühling 3.3.1 CORs Problem mit mehreren Herkunft

Post by Anonymous »

Ich habe ein Backend in Java Spring 3.3.1, dies ist ein Multi -Mieter -Setup, was bedeutet, dass mehrere Frontenden auf das Backend zugreifen können. Meine erste React -Web -App funktioniert perfekt. Jetzt bekommt mein 2. Ausgabe von 403 Cors.
org.springframework.boot
spring-boot-starter-web
3.3.1



org.springframework.boot
spring-boot-starter-security
3.3.1

< /code>
Ein Teil der AppConfig: < /p>
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.csrf(AbstractHttpConfigurer::disable)
.addFilterBefore(firebaseAuthenticationFilter, UsernamePasswordAuthenticationFilter.class)
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED))
.authorizeHttpRequests(authorizeRequests -> authorizeRequests
.requestMatchers("/api/whoami").permitAll()
.requestMatchers(HttpMethod.GET, "/api/products/**").permitAll()
.requestMatchers(HttpMethod.POST, "/api/messages").permitAll()
.requestMatchers(HttpMethod.POST, "/api/email").permitAll()
.requestMatchers("/api/**").authenticated()
.anyRequest().authenticated()
)
.logout(LogoutConfigurer::permitAll)
.cors(cors -> cors.configurationSource(corsConfigurationSource()));

return http.build();
}

@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOriginPatterns(List.of("*"));
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS"));
configuration.setAllowedHeaders(List.of("Content-Type", "X-Tenant-ID", "Authorization", "Ocp-Apim-Subscription-Key"));
configuration.setExposedHeaders(List.of("Authorization", "Ocp-Apim-Subscription-Key"));
configuration.setAllowCredentials(true);
configuration.setMaxAge(3600L);

UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
< /code>
Anfangs habe ich die spezifischen Domänen festgelegt, die Zugriff auf das Backend benötigten. Ich bin jetzt an dem Punkt, an dem ich mich nicht um Sicherheit kümmere. Ich möchte, dass es funktioniert :) Deshalb habe ich es gesetzt, um alle Ursprünge zuzulassen. Entpackte die JAR -Datei in Azure, um zu finden, wenn der AppConfig irgendwie beschädigt wurde, so sieht dies genauso aus, als hätte ich erwartet, dass
die Endpunkte im Postboten testen, wenn ich den Ursprung des ersten Apps verwendet habe, sobald ich den Ursprung meines neuen Apps verwendet habe. Vite) werden auch auf Azure als statische Web -App gehostet. < /P>
Was fehlt mir? Irgendwelche Tipps oder andere Schecks, die ich durchführen muss?>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post