diff --git a/src/main/java/com/olympus/hermione/security/controllers/AuthController.java b/src/main/java/com/olympus/hermione/security/controllers/AuthController.java index be223ce..c30c99a 100644 --- a/src/main/java/com/olympus/hermione/security/controllers/AuthController.java +++ b/src/main/java/com/olympus/hermione/security/controllers/AuthController.java @@ -1,6 +1,9 @@ package com.olympus.hermione.security.controllers; import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.ResponseEntity; import org.springframework.security.oauth2.jwt.Jwt; import org.springframework.security.core.annotation.AuthenticationPrincipal; @@ -12,6 +15,7 @@ import com.olympus.hermione.security.services.JwtService; @RequestMapping("/msauth") public class AuthController { + private static final Logger logger = LoggerFactory.getLogger(AuthController.class); private final JwtService jwtService; @@ -21,6 +25,11 @@ public class AuthController { @PostMapping("/exchange") public ResponseEntity exchangeToken(@AuthenticationPrincipal Jwt azureJwt) { + if (azureJwt == null) { + logger.info("azureJwt is null! Authentication failed."); + return ResponseEntity.status(401).body(Map.of("error", "Invalid or missing JWT")); + } + logger.info("Received JWT: " + azureJwt.getTokenValue()); String internalToken = jwtService.generateInternalToken(azureJwt); return ResponseEntity.ok(Map.of("token", internalToken)); }