diff --git a/gateway-service/src/main/java/com/posthub/gateway/controller/AuthController.java b/gateway-service/src/main/java/com/posthub/gateway/controller/AuthController.java index 0db3239..b1b16e2 100644 --- a/gateway-service/src/main/java/com/posthub/gateway/controller/AuthController.java +++ b/gateway-service/src/main/java/com/posthub/gateway/controller/AuthController.java @@ -60,6 +60,12 @@ public class AuthController { .map(ResponseEntity::ok); } + @PostMapping("/devops-guest-token") + public Mono>> devopsGuestToken() { + return authService.devopsGuestToken() + .map(ResponseEntity::ok); + } + private void addAuthCookie(ServerHttpResponse response, String token) { ResponseCookie cookie = ResponseCookie.from("Authorization", token) .httpOnly(true) diff --git a/gateway-service/src/main/java/com/posthub/gateway/service/AuthService.java b/gateway-service/src/main/java/com/posthub/gateway/service/AuthService.java index 6db969d..fee4613 100644 --- a/gateway-service/src/main/java/com/posthub/gateway/service/AuthService.java +++ b/gateway-service/src/main/java/com/posthub/gateway/service/AuthService.java @@ -34,9 +34,13 @@ public class AuthService { private final RefreshTokenRepository refreshTokenRepository; private final JwtTokenProvider jwtTokenProvider; private final PasswordEncoder passwordEncoder; + @Value("${hr-guest.email}") private String hrGuestEmail; + @Value("${devops-guest.email}") + private String devopsGuestEmail; + public Mono> login(LoginRequest request) { return userRepository.findByEmail(request.getEmail().toLowerCase()) .switchIfEmpty(Mono.error(new ResponseStatusException( @@ -118,6 +122,17 @@ public class AuthService { }); } + public Mono> devopsGuestToken() { + return userRepository.findByEmail(devopsGuestEmail) + .switchIfEmpty(Mono.error(new ResponseStatusException( + HttpStatus.NOT_FOUND, "DevOps guest user not found"))) + .map(user -> { + String accessToken = jwtTokenProvider.generateHrGuestToken(user); + UserProfileDTO dto = toUserProfileDto(user, accessToken, null); + return RagResponse.createSuccessfulWithNewToken(dto); + }); + } + private Mono> generateTokensAndBuildResponse(User user) { return refreshTokenRepository.findByUserId(user.getId()) .flatMap(existing -> { diff --git a/gateway-service/src/main/resources/application.yml b/gateway-service/src/main/resources/application.yml index a326886..da26d88 100644 --- a/gateway-service/src/main/resources/application.yml +++ b/gateway-service/src/main/resources/application.yml @@ -31,6 +31,8 @@ spring: # ---- Guest user (portfolio chat) ---- hr-guest: email: ${HR_GUEST_EMAIL:} + devops-guest: + email: ${DEVOPS_GUEST_EMAIL:} # ---- R2DBC (reactive DB) ---- r2dbc: @@ -120,6 +122,7 @@ auth: - /api/*/v3/api-docs/** - /api/*/swagger-ui/** - /api/auth/hr-guest-token + - /api/auth/devops-guest-token admin-paths: - /api/*/admin/**