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)) {