From 97a7508382566a916202da0986b47dc1cd49d24d Mon Sep 17 00:00:00 2001 From: "Kristen.Herum" Date: Wed, 18 Dec 2024 10:45:50 +0100 Subject: [PATCH] Remove OAUTH2 from ResourceServerType and update logic. #deploy-idporten-frontend The OAUTH2 enum entry has been removed from ResourceServerType, and related logic was updated to use TOKEN_X for OAuth2AuthenticationToken cases. This ensures consistency in attribute handling and streamlines authentication token processing. --- .../action/GetAuthenticatedResourceServerType.java | 2 +- .../libs/reactivesecurity/action/GetAuthenticatedUserId.java | 4 ++-- .../testnav/libs/securitycore/domain/ResourceServerType.java | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/libs/reactive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/action/GetAuthenticatedResourceServerType.java b/libs/reactive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/action/GetAuthenticatedResourceServerType.java index dfbdfe9d83d..b6b72f5802d 100644 --- a/libs/reactive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/action/GetAuthenticatedResourceServerType.java +++ b/libs/reactive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/action/GetAuthenticatedResourceServerType.java @@ -40,7 +40,7 @@ public Mono call() { .map(Mono::just) .orElseGet(Mono::empty); } else if (authentication instanceof OAuth2AuthenticationToken) { - return Mono.just(ResourceServerType.OAUTH2); + return Mono.just(ResourceServerType.TOKEN_X); } return Mono.empty(); }); diff --git a/libs/reactive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/action/GetAuthenticatedUserId.java b/libs/reactive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/action/GetAuthenticatedUserId.java index 761c65b818f..e5b514f1fb3 100644 --- a/libs/reactive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/action/GetAuthenticatedUserId.java +++ b/libs/reactive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/action/GetAuthenticatedUserId.java @@ -21,7 +21,7 @@ public Mono call() { return getAuthenticatedResourceServerType .call() .flatMap(serverType -> switch (serverType) { - case TOKEN_X, OAUTH2 -> getTokenAttribute("pid"); + case TOKEN_X -> getTokenAttribute("pid"); case AZURE_AD -> getTokenAttribute("oid"); }); } @@ -38,7 +38,7 @@ private Mono getTokenAttribute(String attribute) { jwtAuthenticationToken.getTokenAttributes().get(attribute).toString(); case OAuth2AuthenticationToken oauth2AuthenticationToken -> - oauth2AuthenticationToken.getPrincipal().getAttributes().get(attribute).toString(); + oauth2AuthenticationToken.getPrincipal().getAttribute("pid"); default -> ""; }; diff --git a/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/ResourceServerType.java b/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/ResourceServerType.java index 645b9354d95..ee579cb3018 100644 --- a/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/ResourceServerType.java +++ b/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/ResourceServerType.java @@ -2,6 +2,5 @@ public enum ResourceServerType { TOKEN_X, - AZURE_AD, - OAUTH2 + AZURE_AD }