From f5e3a20a4a2b14906a1412b7440760adedda5e05 Mon Sep 17 00:00:00 2001 From: Cato Olsen Date: Fri, 23 Feb 2024 15:01:32 +0100 Subject: [PATCH] Reintrodusert (custom) log filter, POST only. --- apps/inntektsmelding-service/build.gradle | 5 +-- .../config/RequestLoggingFilterConfig.java | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 apps/inntektsmelding-service/src/main/java/no/nav/registre/testnav/inntektsmeldingservice/config/RequestLoggingFilterConfig.java diff --git a/apps/inntektsmelding-service/build.gradle b/apps/inntektsmelding-service/build.gradle index 17ffd69cc5e..3060873a840 100644 --- a/apps/inntektsmelding-service/build.gradle +++ b/apps/inntektsmelding-service/build.gradle @@ -47,10 +47,7 @@ dependencies { implementation 'no.nav.testnav.libs:servlet-security' implementation 'org.springframework.cloud:spring-cloud-vault-config-databases' - implementation('org.springframework.boot:spring-boot-starter-web') { - exclude group: 'org.springframework.boot', module: 'org.springframework.boot' - } - implementation 'org.springframework.boot:spring-boot-starter-undertow' + implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-webflux' diff --git a/apps/inntektsmelding-service/src/main/java/no/nav/registre/testnav/inntektsmeldingservice/config/RequestLoggingFilterConfig.java b/apps/inntektsmelding-service/src/main/java/no/nav/registre/testnav/inntektsmeldingservice/config/RequestLoggingFilterConfig.java new file mode 100644 index 00000000000..47d3f1e87a1 --- /dev/null +++ b/apps/inntektsmelding-service/src/main/java/no/nav/registre/testnav/inntektsmeldingservice/config/RequestLoggingFilterConfig.java @@ -0,0 +1,38 @@ +package no.nav.registre.testnav.inntektsmeldingservice.config; + +import jakarta.servlet.http.HttpServletRequest; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.web.FilterChainProxy; +import org.springframework.web.filter.CommonsRequestLoggingFilter; + +@Configuration +@Slf4j +class RequestLoggingFilterConfig { + + @Bean + PostOnlyRequestLoggingFilter logFilter(FilterChainProxy filterChainProxy) { + + log.info("Filter chain: {}", filterChainProxy.getFilterChains()); + + var filter = new PostOnlyRequestLoggingFilter(); + filter.setIncludeClientInfo(true); + filter.setIncludeHeaders(true); + filter.setIncludePayload(true); + filter.setIncludeQueryString(true); + filter.setMaxPayloadLength(10000); + filter.setAfterMessagePrefix("REQUEST: "); + return filter; + } + + private static class PostOnlyRequestLoggingFilter extends CommonsRequestLoggingFilter { + + @Override + protected boolean shouldLog(HttpServletRequest request) { + return "POST".equalsIgnoreCase(request.getMethod()); + } + + } + +} \ No newline at end of file