This commit is contained in:
root
2025-09-14 17:41:07 +05:00
parent 3a7abdbc7e
commit 005cd0d906
2 changed files with 2 additions and 49 deletions
@@ -1,44 +0,0 @@
package kz.konturai.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import java.util.Arrays;
@Configuration
public class CorsConfig {
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
// Allow requests from your frontend
configuration.setAllowedOriginPatterns(Arrays.asList(
"http://localhost:*",
"https://localhost:*",
"http://127.0.0.1:*",
"https://127.0.0.1:*", "https://konturai.kz:*"));
// Allow all HTTP methods
configuration.setAllowedMethods(Arrays.asList(
"GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"));
// Allow all headers
configuration.setAllowedHeaders(Arrays.asList("*"));
// Allow credentials (cookies, authorization headers)
configuration.setAllowCredentials(true);
// Cache preflight response for 1 hour
configuration.setMaxAge(3600L);
// Apply this configuration to all paths
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
}
@@ -20,12 +20,10 @@ import org.springframework.web.cors.CorsConfigurationSource;
public class SecurityConfig { public class SecurityConfig {
private final JwtAuthenticationFilter jwtAuthenticationFilter; private final JwtAuthenticationFilter jwtAuthenticationFilter;
private final CorsConfigurationSource corsConfigurationSource;
public SecurityConfig(JwtAuthenticationFilter jwtAuthenticationFilter, public SecurityConfig(JwtAuthenticationFilter jwtAuthenticationFilter) {
CorsConfigurationSource corsConfigurationSource) {
this.jwtAuthenticationFilter = jwtAuthenticationFilter; this.jwtAuthenticationFilter = jwtAuthenticationFilter;
this.corsConfigurationSource = corsConfigurationSource;
} }
@Bean @Bean
@@ -41,7 +39,6 @@ public class SecurityConfig {
response.getWriter().write("{\"message\":\"Forbidden\"}"); response.getWriter().write("{\"message\":\"Forbidden\"}");
}; };
http http
.cors(cors -> cors.configurationSource(corsConfigurationSource))
.csrf(csrf -> csrf.disable()) .csrf(csrf -> csrf.disable())
.sessionManagement(sm -> sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) .sessionManagement(sm -> sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(auth -> auth .authorizeHttpRequests(auth -> auth