Refactor LoginController to use pattern matching for Jwt type check, simplify uuid extraction, and adjust debug logs.

This commit is contained in:
akastijn 2025-08-05 23:49:11 +02:00
parent 56f4ccf40e
commit d28b4a2b62

View File

@ -96,11 +96,10 @@ public class LoginController implements LoginApi {
log.debug("Loading username for logged in user");
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
log.debug("Loaded authentication for logged in user {}", authentication);
if (authentication == null || !(authentication.getPrincipal() instanceof OAuth2ResourceServerProperties.Jwt)) {
if (authentication == null || !(authentication.getPrincipal() instanceof Jwt jwt)) {
log.debug("Loaded authentication for logged in user is null or not a jwt");
return ResponseEntity.status(401).build();
}
Jwt jwt = (Jwt) authentication.getPrincipal();
String stringUuid = jwt.getSubject();
UUID uuid;
try {