Skip to content

Commit

Permalink
HELLODATA-1881 - cloudbeaver gateway adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Slawomir Wieczorek committed Jan 23, 2025
1 parent 5c39039 commit 94a1491
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,28 @@ public static String toCbRolesHeader(Collection<GrantedAuthority> 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 94a1491

Please sign in to comment.