Changed CORS code & Alloed All origins
This commit is contained in:
+9
-3
@@ -63,10 +63,12 @@ public class SecurityConfiguration {
|
|||||||
.authenticationProvider(authenticationProvider)
|
.authenticationProvider(authenticationProvider)
|
||||||
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class)
|
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class)
|
||||||
.csrf(csrf -> csrf.disable())
|
.csrf(csrf -> csrf.disable())
|
||||||
|
.cors(cors -> {}) // 🔥 This line enables CORS and connects to your CorsConfigurationSource bean
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// @Bean
|
// @Bean
|
||||||
// CorsConfigurationSource corsConfigurationSource() {
|
// CorsConfigurationSource corsConfigurationSource() {
|
||||||
// CorsConfiguration configuration = new CorsConfiguration();
|
// CorsConfiguration configuration = new CorsConfiguration();
|
||||||
@@ -85,15 +87,19 @@ public class SecurityConfiguration {
|
|||||||
@Bean
|
@Bean
|
||||||
CorsConfigurationSource corsConfigurationSource() {
|
CorsConfigurationSource corsConfigurationSource() {
|
||||||
CorsConfiguration configuration = new CorsConfiguration();
|
CorsConfiguration configuration = new CorsConfiguration();
|
||||||
configuration.setAllowedOrigins(List.of("http://localhost:5173")); // Replace with your frontend origin(s)
|
|
||||||
configuration.setAllowedMethods(List.of("GET", "PUT", "DELETE", "POST", "OPTIONS"));
|
// 🔥 Allow all origins (wildcard) safely with credentials
|
||||||
|
configuration.setAllowedOriginPatterns(List.of("*"));
|
||||||
|
|
||||||
|
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS"));
|
||||||
configuration.setAllowedHeaders(List.of("*"));
|
configuration.setAllowedHeaders(List.of("*"));
|
||||||
configuration.setExposedHeaders(List.of("Authorization"));
|
configuration.setExposedHeaders(List.of("Authorization"));
|
||||||
configuration.setAllowCredentials(true); // Important when using Authorization headers
|
configuration.setAllowCredentials(true); // Needed for cookies / Authorization headers
|
||||||
|
|
||||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||||
source.registerCorsConfiguration("/**", configuration);
|
source.registerCorsConfiguration("/**", configuration);
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user