Skip to content

Commit

Permalink
HELLODATA-1881 - change log level
Browse files Browse the repository at this point in the history
  • Loading branch information
Slawomir Wieczorek committed Jan 23, 2025
1 parent 7c1a001 commit bca7a64
Showing 1 changed file with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
package ch.bedag.dap.hellodata.cloudbeaver.gateway.filters;

import ch.bedag.dap.hellodata.cloudbeaver.gateway.config.SecurityConfig;
import java.util.Collection;
import java.util.Locale;
import java.util.Objects;
import java.util.logging.Level;
import lombok.extern.log4j.Log4j2;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
Expand All @@ -40,6 +36,11 @@
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.Collection;
import java.util.Locale;
import java.util.Objects;
import java.util.logging.Level;

@Log4j2
@Component
public class AddCbAuthGatewayFilterFactory extends AbstractGatewayFilterFactory<Object> {
Expand All @@ -58,17 +59,18 @@ public static String toCbRolesHeader(Collection<GrantedAuthority> authorities) {
public static ServerWebExchange addCbAuthHeaders(ServerWebExchange exchange, JwtAuthenticationToken authenticationToken) {
return exchange.mutate().request((r) -> {
r.headers((httpHeaders) -> {
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.debug("Requested URI Path: {}", exchange.getRequest().getURI().getPath());
log.debug("\taddCbAuthHeaders for user {}", authenticationToken);
log.debug("\temail: {}", authenticationToken.getToken().getClaims().get("email"));
log.debug("\tgiven_name: {}", authenticationToken.getToken().getClaims().get("given_name"));
log.debug("\tfamily_name: {}", authenticationToken.getToken().getClaims().get("family_name"));
log.debug("\tauthorities: {}", toCbRolesHeader(authenticationToken.getAuthorities()));

httpHeaders.add("X-User", (String) authenticationToken.getToken().getClaims().get("email"));
httpHeaders.add("X-Role", toCbRolesHeader(authenticationToken.getAuthorities()));
httpHeaders.add("X-First-name", (String) authenticationToken.getToken().getClaims().get("given_name"));
httpHeaders.add("X-Last-name", (String) authenticationToken.getToken().getClaims().get("family_name"));
log.info("Added headers to request {}", httpHeaders);
});
}).build();
}
Expand All @@ -84,12 +86,12 @@ public static ServerWebExchange removeAuthorizationHeader(ServerWebExchange exch
public GatewayFilter apply(Object config) {
return (exchange, chain) -> {
Mono<ServerWebExchange> webExchange = exchange.getPrincipal()
.log("auth-gateway-filter-factory", Level.INFO)
.filter((principal) -> principal instanceof JwtAuthenticationToken)
.cast(JwtAuthenticationToken.class)
.map((token) -> addCbAuthHeaders(exchange, token))
.map((token) -> removeAuthorizationHeader(exchange))
.defaultIfEmpty(exchange);
.log("auth-gateway-filter-factory", Level.INFO)
.filter((principal) -> principal instanceof JwtAuthenticationToken)
.cast(JwtAuthenticationToken.class)
.map((token) -> addCbAuthHeaders(exchange, token))
.map((token) -> removeAuthorizationHeader(exchange))
.defaultIfEmpty(exchange);
Objects.requireNonNull(chain);
return webExchange.flatMap(chain::filter);
};
Expand Down

0 comments on commit bca7a64

Please sign in to comment.