Skip to content
This repository was archived by the owner on Nov 23, 2025. It is now read-only.

Commit 64f5400

Browse files
authored
Merge pull request #3 from TechTorque-2025/feature/upgrade_to_microservice
Feature/upgrade to microservice
2 parents 164023c + 2c2d9ac commit 64f5400

4 files changed

Lines changed: 41 additions & 48 deletions

File tree

auth-service/src/main/java/com/techtorque/auth_service/config/SecurityConfig.java

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
import org.springframework.security.crypto.password.PasswordEncoder;
1717
import org.springframework.security.web.SecurityFilterChain;
1818
import 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
}

auth-service/src/main/java/com/techtorque/auth_service/controller/AuthController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
* Handles login, registration, and health check requests
2727
*/
2828
@RestController
29-
@RequestMapping("/api/v1/auth")
30-
@CrossOrigin(origins = "*", maxAge = 3600)
29+
// Class-level request mapping removed — gateway strips prefixes before forwarding
30+
// @RequestMapping("/api/v1/auth")
31+
// CORS handled at the API Gateway; remove @CrossOrigin to avoid conflicts
32+
// @CrossOrigin(origins = "*", maxAge = 3600)
3133
@Tag(name = "Authentication", description = "Authentication and user management endpoints")
3234
public class AuthController {
3335

auth-service/src/main/java/com/techtorque/auth_service/controller/UserController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
* Endpoints in this controller are accessible to users with ADMIN or SUPER_ADMIN roles.
2626
*/
2727
@RestController
28-
@RequestMapping("/api/v1/users")
29-
@CrossOrigin(origins = "*", maxAge = 3600)
28+
// Class-level request mapping removed — endpoints are exposed as internal paths
29+
// @RequestMapping("/api/v1/users")
30+
// CORS handled by API Gateway; remove @CrossOrigin to avoid conflicts
31+
// @CrossOrigin(origins = "*", maxAge = 3600)
3032
@PreAuthorize("hasRole('ADMIN') or hasRole('SUPER_ADMIN')")
3133
@Tag(name = "User Management", description = "User management endpoints (Admin/Super Admin only)")
3234
@SecurityRequirement(name = "bearerAuth")

auth-service/src/main/java/com/techtorque/auth_service/util/JwtUtil.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.springframework.stereotype.Component;
1616

1717
import javax.crypto.SecretKey;
18+
import java.nio.charset.StandardCharsets;
1819
import java.util.Date;
1920
import java.util.HashMap;
2021
import java.util.List;
@@ -123,7 +124,8 @@ public boolean validateJwtToken(String token) {
123124
* Generates a SecretKey object from the Base64 encoded secret string.
124125
*/
125126
private SecretKey getSignInKey() {
126-
byte[] keyBytes = Decoders.BASE64.decode(jwtSecret);
127+
// Use the raw UTF-8 bytes of the secret string, just like the Go gateway.
128+
byte[] keyBytes = jwtSecret.getBytes(StandardCharsets.UTF_8);
127129
return Keys.hmacShaKeyFor(keyBytes);
128130
}
129131
}

0 commit comments

Comments
 (0)