From e677dc58e56c06233d6c9d1039a20d1a74d2d402 Mon Sep 17 00:00:00 2001 From: Anthony Britton Date: Tue, 31 Oct 2023 08:19:20 +0000 Subject: [PATCH] PI-1597 --- .../config/telemetry/ClientTrackingInterceptor.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libs/oauth-server/src/main/kotlin/uk/gov/justice/digital/hmpps/config/telemetry/ClientTrackingInterceptor.kt b/libs/oauth-server/src/main/kotlin/uk/gov/justice/digital/hmpps/config/telemetry/ClientTrackingInterceptor.kt index 29f6e53e08..4eedafe2cd 100644 --- a/libs/oauth-server/src/main/kotlin/uk/gov/justice/digital/hmpps/config/telemetry/ClientTrackingInterceptor.kt +++ b/libs/oauth-server/src/main/kotlin/uk/gov/justice/digital/hmpps/config/telemetry/ClientTrackingInterceptor.kt @@ -6,10 +6,21 @@ import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse import org.springframework.context.annotation.Configuration import org.springframework.http.HttpHeaders +import org.springframework.stereotype.Component import org.springframework.web.servlet.HandlerInterceptor +import org.springframework.web.servlet.config.annotation.InterceptorRegistry +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer @Configuration +class ClientTrackingConfiguration(private val clientTrackingInterceptor: ClientTrackingInterceptor) : WebMvcConfigurer { + override fun addInterceptors(registry: InterceptorRegistry) { + registry.addInterceptor(clientTrackingInterceptor).addPathPatterns("/**") + } +} + +@Component class ClientTrackingInterceptor : HandlerInterceptor { + override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean { val token = request.getHeader(HttpHeaders.AUTHORIZATION) if (token.startsWith(BEARER)) {