From 94a14913100b60b98f637d702bd3e809fee55409 Mon Sep 17 00:00:00 2001 From: Slawomir Wieczorek Date: Thu, 23 Jan 2025 16:31:20 +0100 Subject: [PATCH] HELLODATA-1881 - cloudbeaver gateway adjustments --- .../AddCbAuthGatewayFilterFactory.java | 31 +++++++++++-------- .../src/main/resources/application.yml | 6 ++-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/hello-data-subsystems/hello-data-cloudbeaver-gateway/src/main/java/ch/bedag/dap/hellodata/cloudbeaver/gateway/filters/AddCbAuthGatewayFilterFactory.java b/hello-data-subsystems/hello-data-cloudbeaver-gateway/src/main/java/ch/bedag/dap/hellodata/cloudbeaver/gateway/filters/AddCbAuthGatewayFilterFactory.java index 6b740496..f74c020c 100644 --- a/hello-data-subsystems/hello-data-cloudbeaver-gateway/src/main/java/ch/bedag/dap/hellodata/cloudbeaver/gateway/filters/AddCbAuthGatewayFilterFactory.java +++ b/hello-data-subsystems/hello-data-cloudbeaver-gateway/src/main/java/ch/bedag/dap/hellodata/cloudbeaver/gateway/filters/AddCbAuthGatewayFilterFactory.java @@ -57,23 +57,28 @@ public static String toCbRolesHeader(Collection authorities) { } public static ServerWebExchange addCbAuthHeaders(ServerWebExchange exchange, JwtAuthenticationToken authenticationToken) { - return exchange.mutate().request((r) -> { - r.headers((httpHeaders) -> { + return exchange.mutate().request((builder) -> { + builder.headers((httpHeaders) -> { + String email = (String) authenticationToken.getToken().getClaims().get("email"); + Object givenName = authenticationToken.getToken().getClaims().get("given_name"); + Object familyName = authenticationToken.getToken().getClaims().get("family_name"); + String cbRolesHeader = toCbRolesHeader(authenticationToken.getAuthorities()); + log.warn("Requested URI Path: {}", exchange.getRequest().getURI().getPath()); log.warn("\taddCbAuthHeaders for user {}", authenticationToken); - log.warn("\temail: {}", authenticationToken.getToken().getClaims().get("email")); - log.warn("\tgiven_name: {}", authenticationToken.getToken().getClaims().get("given_name")); - log.warn("\tfamily_name: {}", authenticationToken.getToken().getClaims().get("family_name")); - log.warn("\tauthorities: {}", toCbRolesHeader(authenticationToken.getAuthorities())); + log.warn("\temail: {}", email); + log.warn("\tgiven_name: {}", givenName); + log.warn("\tfamily_name: {}", familyName); + log.warn("\tauthorities: {}", cbRolesHeader); - httpHeaders.set("X-User", (String) authenticationToken.getToken().getClaims().get("email")); - log.warn("\tX-User header: {}", authenticationToken.getToken().getClaims().get("email")); - httpHeaders.set("X-Role", toCbRolesHeader(authenticationToken.getAuthorities())); - log.warn("\tX-Role header: {}", toCbRolesHeader(authenticationToken.getAuthorities())); - httpHeaders.set("X-First-name", (String) authenticationToken.getToken().getClaims().get("given_name")); - httpHeaders.set("X-Last-name", (String) authenticationToken.getToken().getClaims().get("family_name")); + httpHeaders.set("X-User", email); + log.warn("\tX-User header: {}", email); + httpHeaders.set("X-Role", cbRolesHeader); + log.warn("\tX-Role header: {}", cbRolesHeader); + httpHeaders.set("X-First-name", (String) givenName); + httpHeaders.set("X-Last-name", (String) familyName); log.debug("Added headers to request {}", httpHeaders); - }); + }).build(); }).build(); } diff --git a/hello-data-subsystems/hello-data-cloudbeaver-gateway/src/main/resources/application.yml b/hello-data-subsystems/hello-data-cloudbeaver-gateway/src/main/resources/application.yml index 3fc5bfec..1ec5596b 100644 --- a/hello-data-subsystems/hello-data-cloudbeaver-gateway/src/main/resources/application.yml +++ b/hello-data-subsystems/hello-data-cloudbeaver-gateway/src/main/resources/application.yml @@ -121,10 +121,10 @@ server: management: endpoint: health: - enabled: true + access: read_only # show-details: always #if we need some details info: - enabled: true + access: read_only endpoints: web: exposure: @@ -157,7 +157,7 @@ management: logging: level: - org.springframework.cloud.gateway: INFO + org.springframework.cloud.gateway: DEBUG org.springframework.cloud.gateway.handler.RoutePredicateHandlerMapping: INFO org.springframework.web.HttpLogging: INFO reactor.netty.http.server: INFO