From d28b4a2b6216253d20fa18cc8e25c9745d33ba3f Mon Sep 17 00:00:00 2001 From: akastijn Date: Tue, 5 Aug 2025 23:49:11 +0200 Subject: [PATCH] Refactor `LoginController` to use pattern matching for `Jwt` type check, simplify `uuid` extraction, and adjust debug logs. --- .../altitudeweb/controllers/login/LoginController.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/com/alttd/altitudeweb/controllers/login/LoginController.java b/backend/src/main/java/com/alttd/altitudeweb/controllers/login/LoginController.java index a8c666d..71b36ee 100644 --- a/backend/src/main/java/com/alttd/altitudeweb/controllers/login/LoginController.java +++ b/backend/src/main/java/com/alttd/altitudeweb/controllers/login/LoginController.java @@ -96,16 +96,15 @@ 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 { - uuid = UUID.fromString(stringUuid); - log.debug("Loaded username for logged in user {}", uuid); + uuid = UUID.fromString(stringUuid); + log.debug("Loaded username for logged in user {}", uuid); } catch (IllegalArgumentException e) { return ResponseEntity.badRequest().build(); }