Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 73163540 authored by Jean Claude Correale's avatar Jean Claude Correale
Browse files

Add LoggingRule with default message

parent 80f38c37
No related branches found
No related tags found
3 merge requests!69Update version to 1.2.0,!60Hotfix,!59Fix LoggingFilter constructor
Pipeline #247744 failed
package com.aruba.simpl.tlsgateway.configurations;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import lombok.Data;
import org.springframework.http.HttpMethod;
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher;
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatchers;
import org.springframework.util.MultiValueMap;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
public record LoggingRule(
HttpMethod method, String path, List<MultiMapRule> query, List<MultiMapRule> header, Config config) {
public record MultiMapRule(String name, String value, List<String> values) {
public Boolean matches(MultiValueMap<String, String> queryParams) {
return queryParams.containsKey(name)
&& (values().isEmpty()
|| values().stream()
.anyMatch(value -> queryParams.get(name).contains(value)));
}
@Override
public List<String> values() {
return Optional.ofNullable(values)
.orElse(Optional.ofNullable(value).map(List::of).orElse(List.of()));
}
}
@Data
public static class Config {
private String message = "${method} ${path} ${responseStatus}";
private List<String> operations;
}
public Mono<Boolean> matches(ServerWebExchange exchange) {
return ServerWebExchangeMatchers.pathMatchers(method(), path)
.matches(exchange)
.map(ServerWebExchangeMatcher.MatchResult::isMatch)
.map(isMatch -> isMatch && matchQuery(exchange) && matchHeaders(exchange));
}
private boolean matchQuery(ServerWebExchange exchange) {
return Optional.ofNullable(query())
.map(Collection::stream)
.map(query -> query.map(q -> q.matches(exchange.getRequest().getQueryParams()))
.reduce(Boolean::logicalAnd)
.orElse(true))
.orElse(true);
}
private boolean matchHeaders(ServerWebExchange exchange) {
return Optional.ofNullable(header())
.map(Collection::stream)
.map(header -> header.map(h -> h.matches(exchange.getRequest().getHeaders()))
.reduce(Boolean::logicalAnd)
.orElse(true))
.orElse(true);
}
}
package com.aruba.simpl.tlsgateway.configurations.security;
import com.aruba.simpl.common.logging.LoggingRule;
import com.aruba.simpl.tlsgateway.configurations.LoggingRule;
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
......
......@@ -2,9 +2,9 @@ package com.aruba.simpl.tlsgateway.filters;
import static eu.simpl.MessageBuilder.buildMessage;
import com.aruba.simpl.common.logging.LoggingRule;
import com.aruba.simpl.common.model.dto.CredentialDTO;
import com.aruba.simpl.common.utils.JwtUtil;
import com.aruba.simpl.tlsgateway.configurations.LoggingRule;
import com.aruba.simpl.tlsgateway.configurations.security.RouteConfig;
import com.aruba.simpl.tlsgateway.utils.ExchangeUtil;
import eu.simpl.types.LogMessage;
......@@ -79,12 +79,12 @@ public class LoggingFilter implements GlobalFilter, Ordered {
Map<String, String> templateContext = getTemplateContext(messageType, user);
var messageTemplate = config.message();
var messageTemplate = config.getMessage();
log.log(
Level.getLevel("BUSINESS"),
buildMessage(LogMessage.builder()
.businessOperations(config.operations())
.businessOperations(config.getOperations())
.messageType(messageType)
.origin(getOrigin(messageType))
.destination(getDestination(messageType))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment