Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-britton-moj committed Oct 30, 2023
1 parent 34bd07e commit 02580b1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion libs/commons/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import uk.gov.justice.digital.hmpps.extensions.ClassPathExtension

dependencies {
api(libs.bundles.telemetry)
compileOnly("org.springframework.boot:spring-boot-starter-data-ldap")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation(libs.bundles.telemetry)
implementation(libs.flipt)

testImplementation("org.springframework.boot:spring-boot-starter-data-ldap")
Expand Down
1 change: 0 additions & 1 deletion libs/messaging/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ dependencies {
implementation(project(":libs:commons"))
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation(libs.bundles.telemetry)
compileOnly(libs.openfeign)
compileOnly("org.springframework.boot:spring-boot-starter-data-jpa")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package uk.gov.justice.digital.hmpps.config.telemetry

import com.nimbusds.jwt.SignedJWT
import io.opentelemetry.api.trace.Span
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpHeaders
import org.springframework.web.servlet.HandlerInterceptor

@Configuration
class ClientTrackingInterceptor : HandlerInterceptor {
override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean {
val token = request.getHeader(HttpHeaders.AUTHORIZATION)
if (token.startsWith(BEARER)) {
try {
val jwtBody = SignedJWT.parse(token.replace(BEARER, "")).jwtClaimsSet
Span.current().setAttribute("clientId", jwtBody.getClaim("client_id").toString())
} catch (ignored: Exception) {
// Do nothing - don't create client id span
}
}
return true
}

companion object {
private const val BEARER = "Bearer "
}
}
1 change: 0 additions & 1 deletion projects/domain-events-and-delius/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation(libs.bundles.telemetry)

dev(project(":libs:dev-tools"))
dev("com.h2database:h2")
Expand Down

0 comments on commit 02580b1

Please sign in to comment.