From e472269af34b12f5448d296597a35467967cac71 Mon Sep 17 00:00:00 2001 From: "Michal J. Sladek" Date: Sat, 6 Jul 2024 00:18:29 +0200 Subject: [PATCH] =?UTF-8?q?TG:=20Fjerner=20cookie=20auth=20st=C3=B8tte.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jaxrs/AuthenticationFilterDelegate.java | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/felles/auth-filter/src/main/java/no/nav/vedtak/sikkerhet/jaxrs/AuthenticationFilterDelegate.java b/felles/auth-filter/src/main/java/no/nav/vedtak/sikkerhet/jaxrs/AuthenticationFilterDelegate.java index 27cf45483..e4feba99f 100644 --- a/felles/auth-filter/src/main/java/no/nav/vedtak/sikkerhet/jaxrs/AuthenticationFilterDelegate.java +++ b/felles/auth-filter/src/main/java/no/nav/vedtak/sikkerhet/jaxrs/AuthenticationFilterDelegate.java @@ -11,7 +11,6 @@ import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.container.ContainerRequestContext; import jakarta.ws.rs.container.ResourceInfo; -import jakarta.ws.rs.core.Cookie; import jakarta.ws.rs.core.HttpHeaders; import jakarta.ws.rs.core.Response; import no.nav.vedtak.exception.TekniskException; @@ -38,18 +37,12 @@ public class AuthenticationFilterDelegate { private static final Logger LOG = LoggerFactory.getLogger(AuthenticationFilterDelegate.class); - private static final String ID_TOKEN_COOKIE_NAME = "ID_token"; private static final String AUTHORIZATION_HEADER = HttpHeaders.AUTHORIZATION; private AuthenticationFilterDelegate() { } - public static void validerSettKontekst(ResourceInfo resourceInfo, ContainerRequestContext ctx) { - validerSettKontekst(resourceInfo, ctx, null); - } - - public static void validerSettKontekst(ResourceInfo resourceInfo, ContainerRequestContext ctx, String cookiePath) { try { Method method = resourceInfo.getResourceMethod(); var utenAutentiseringRessurs = method.getAnnotation(UtenAutentisering.class); @@ -66,7 +59,7 @@ public static void validerSettKontekst(ResourceInfo resourceInfo, ContainerReque KontekstHolder.setKontekst(BasisKontekst.ikkeAutentisertRequest(MDCOperations.getConsumerId())); LOG.trace("{} er whitelisted", metodenavn); } else { - var tokenString = getToken(ctx, cookiePath) + var tokenString = getTokenFromHeader(ctx) .orElseThrow(() -> new ValideringsFeil("Mangler token")); validerTokenSetKontekst(tokenString); setUserAndConsumerId(KontekstHolder.getKontekst().getUid()); @@ -104,10 +97,6 @@ private static void setUserAndConsumerId(String subject) { } } - private static Optional getToken(ContainerRequestContext request, String cookiePath) { - return getTokenFromHeader(request).or(() -> getCookieToken(request, cookiePath)); - } - private static Optional getTokenFromHeader(ContainerRequestContext request) { String headerValue = request.getHeaderString(AUTHORIZATION_HEADER); return headerValue != null && headerValue.startsWith(OpenIDToken.OIDC_DEFAULT_TOKEN_TYPE) @@ -115,14 +104,6 @@ private static Optional getTokenFromHeader(ContainerRequestContext : Optional.empty(); } - private static Optional getCookieToken(ContainerRequestContext request, String cookiePath) { - var idTokenCookie = Optional.ofNullable(request.getCookies()).map(c -> c.get(ID_TOKEN_COOKIE_NAME)); - return idTokenCookie.filter(c -> cookiePath != null && cookiePath.equalsIgnoreCase(c.getPath())) - .or(() -> idTokenCookie) - .map(Cookie::getValue) - .map(TokenString::new); - } - public static void validerTokenSetKontekst(TokenString tokenString) { // Sett opp OpenIDToken var claims = JwtUtil.getClaims(tokenString.token());