1616import org .springframework .security .crypto .password .PasswordEncoder ;
1717import org .springframework .security .web .SecurityFilterChain ;
1818import org .springframework .security .web .authentication .UsernamePasswordAuthenticationFilter ;
19- import org . springframework . web . cors . CorsConfiguration ;
20- import org .springframework .web .cors .CorsConfigurationSource ;
21- import org .springframework .web .cors .UrlBasedCorsConfigurationSource ;
22-
23- import java .util .Arrays ;
19+ // CorsConfiguration and related imports are no longer needed
20+ // import org.springframework.web.cors.CorsConfiguration ;
21+ // import org.springframework.web.cors.CorsConfigurationSource ;
22+ // import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
23+ // import java.util.Arrays;
2424
2525@ Configuration
2626@ EnableWebSecurity
@@ -56,38 +56,37 @@ public AuthenticationManager authenticationManager(AuthenticationConfiguration a
5656 return authConfig .getAuthenticationManager ();
5757 }
5858
59- // NOTE: The WebSecurityCustomizer bean has been completely removed.
60-
6159 @ Bean
6260 public SecurityFilterChain filterChain (HttpSecurity http ) throws Exception {
6361 http
6462 .csrf (AbstractHttpConfigurer ::disable )
65- .cors (cors -> cors .configurationSource (corsConfigurationSource ()))
63+ // =====================================================================
64+ // CORS CONFIGURATION HAS BEEN REMOVED FROM THE SPRING BOOT SERVICE
65+ // The Go API Gateway is now solely responsible for handling CORS.
66+ // .cors(cors -> cors.configurationSource(corsConfigurationSource()))
67+ // =====================================================================
6668 .exceptionHandling (exception -> exception .authenticationEntryPoint (unauthorizedHandler ))
6769 .sessionManagement (session -> session .sessionCreationPolicy (SessionCreationPolicy .STATELESS ))
6870 .authorizeHttpRequests (auth -> auth
69- .requestMatchers (
70- // Public API endpoints
71- "/api/v1/auth/**" , // Fixed: more specific auth path
72- "/api/auth/**" , // Keep both for backward compatibility
73-
74- // Public controller endpoints
75- "/favicon.ico" ,
76- "/error" , // Add error page
71+ .requestMatchers (
72+ // Permit the paths AS SEEN BY THE JAVA SERVICE after the gateway strips the prefixes.
73+ "/login" ,
74+ "/register" ,
75+ "/health" ,
7776
78- // Health check and actuator endpoints (if needed)
77+ // Backwards-compatible patterns (if any clients bypass the gateway)
78+ "/api/v1/auth/**" ,
79+ "/api/auth/**" ,
80+ "/favicon.ico" ,
81+ "/error" ,
7982 "/actuator/**" ,
80-
81- // All OpenAPI and Swagger UI resources
8283 "/v3/api-docs/**" ,
8384 "/swagger-ui/**" ,
8485 "/swagger-ui.html" ,
85- "/swagger-resources/**" , // Include swagger-resources
86- "/webjars/**" , // Include webjars
87- "/api-docs/**" // Additional swagger endpoint pattern
86+ "/swagger-resources/**" ,
87+ "/webjars/**" ,
88+ "/api-docs/**"
8889 ).permitAll ()
89-
90- // All other requests require authentication.
9190 .anyRequest ().authenticated ()
9291 );
9392
@@ -97,33 +96,21 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
9796 return http .build ();
9897 }
9998
99+ // =====================================================================
100+ // THE CORS CONFIGURATION BEAN HAS BEEN COMPLETELY REMOVED.
101+ // =====================================================================
102+ /*
100103 @Bean
101104 public CorsConfigurationSource corsConfigurationSource() {
102105 CorsConfiguration configuration = new CorsConfiguration();
103-
104- // Allow specific origins
105- configuration .setAllowedOrigins (Arrays .asList (
106- "http://localhost:3000" , // Next.js dev server
107- "http://127.0.0.1:3000" // Alternative localhost
108- ));
109-
110- // Allow all headers
106+ configuration.setAllowedOrigins(Arrays.asList("http://localhost:3000", "http://127.0.0.1:3000"));
111107 configuration.setAllowedHeaders(Arrays.asList("*"));
112-
113- // Allow specific HTTP methods
114- configuration .setAllowedMethods (Arrays .asList (
115- "GET" , "POST" , "PUT" , "DELETE" , "OPTIONS" , "PATCH"
116- ));
117-
118- // Allow credentials (important for cookies/auth tokens)
108+ configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"));
119109 configuration.setAllowCredentials(true);
120-
121- // Cache preflight response for 1 hour
122110 configuration.setMaxAge(3600L);
123-
124111 UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
125112 source.registerCorsConfiguration("/**", configuration);
126-
127113 return source;
128114 }
115+ */
129116}
0 commit comments