updated code for cors
This commit is contained in:
@@ -39,10 +39,13 @@ import net.gepafin.tendermanagement.config.jwt.TokenProvider;
|
||||
public class SecurityConfig {
|
||||
|
||||
private final TokenProvider tokenProvider;
|
||||
|
||||
private final CorsFilter corsFilter;
|
||||
|
||||
@Autowired
|
||||
public SecurityConfig(TokenProvider tokenProvider) {
|
||||
public SecurityConfig(TokenProvider tokenProvider, CorsFilter corsFilter) {
|
||||
this.tokenProvider = tokenProvider;
|
||||
this.corsFilter = corsFilter;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -70,17 +73,17 @@ public class SecurityConfig {
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public CorsConfigurationSource corsConfigurationSource() {
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
config.setAllowCredentials(true);
|
||||
config.addAllowedOrigin("http://localhost:3000"); // Change this to your frontend URL
|
||||
config.addAllowedHeader("*");
|
||||
config.addAllowedMethod("*");
|
||||
source.registerCorsConfiguration("/**", config);
|
||||
return source;
|
||||
}
|
||||
// @Bean
|
||||
// public CorsConfigurationSource corsConfigurationSource() {
|
||||
// UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
// CorsConfiguration config = new CorsConfiguration();
|
||||
// config.setAllowCredentials(true);
|
||||
// config.addAllowedOrigin("http://localhost:3000"); // Change this to your frontend URL
|
||||
// config.addAllowedHeader("*");
|
||||
// config.addAllowedMethod("*");
|
||||
// source.registerCorsConfiguration("/**", config);
|
||||
// return source;
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain securityFilterChain(HttpSecurity http, MvcRequestMatcher.Builder mvc) throws Exception {
|
||||
@@ -96,7 +99,7 @@ public class SecurityConfig {
|
||||
.sessionManagement(session -> session
|
||||
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
||||
)
|
||||
.addFilterBefore(new CorsFilter(corsConfigurationSource()), AuthorizationFilter.class)
|
||||
.addFilterBefore(corsFilter, UsernamePasswordAuthenticationFilter.class)
|
||||
.addFilterBefore(new JWTFilter(tokenProvider), UsernamePasswordAuthenticationFilter.class);
|
||||
|
||||
return http.build();
|
||||
|
||||
Reference in New Issue
Block a user