Skip to content

Commit 4067f34

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents ece1f5c + 593fbc6 commit 4067f34

File tree

12 files changed

+126
-56
lines changed

12 files changed

+126
-56
lines changed

build.gradle.kts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
22

3-
val mockkVersion = "1.13.2"
3+
val mockkVersion = "1.13.4"
44
val logstashVersion = "7.2"
5-
val springVersion = "2.5.5"
6-
val springSleuthVersion = "3.1.5"
7-
val testContainersVersion = "1.17.5"
8-
val springDocVersion = "1.6.12"
9-
val tokenValidationVersion = "2.1.7"
10-
val problemSpringWebStartVersion = "0.27.0"
5+
val testContainersVersion = "1.17.6"
6+
val springDocVersion = "2.0.2"
7+
val tokenValidationVersion = "3.0.2"
8+
val kotlinVersion = "1.8.10"
119

1210
repositories {
1311
mavenCentral()
1412
}
1513

1614
plugins {
17-
val kotlinVersion = "1.7.21"
18-
id("org.springframework.boot") version "2.7.5"
15+
val kotlinVersion = "1.8.0"
16+
id("org.springframework.boot") version "3.0.2"
1917
kotlin("jvm") version kotlinVersion
2018
kotlin("plugin.spring") version kotlinVersion
2119
kotlin("plugin.jpa") version kotlinVersion
@@ -25,37 +23,35 @@ plugins {
2523
apply(plugin = "io.spring.dependency-management")
2624

2725
dependencies {
28-
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.7.21")
26+
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.8.10")
2927

3028
implementation("org.springframework.boot:spring-boot-starter-web")
3129
implementation("org.springframework.boot:spring-boot-starter-actuator")
3230
implementation("org.springframework.boot:spring-boot-starter-webflux")
3331
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
3432
implementation("org.springframework.boot:spring-boot-starter-validation")
35-
implementation("org.springframework.cloud:spring-cloud-starter-sleuth:$springSleuthVersion")
36-
37-
implementation("org.zalando:problem-spring-web-starter:$problemSpringWebStartVersion")
3833

3934
implementation("no.nav.security:token-validation-spring:$tokenValidationVersion")
4035

41-
implementation("org.springdoc:springdoc-openapi-ui:$springDocVersion")
36+
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:$springDocVersion")
4237

4338
implementation("org.flywaydb:flyway-core")
4439
implementation("com.zaxxer:HikariCP")
4540
implementation("org.postgresql:postgresql")
4641

4742
implementation("io.micrometer:micrometer-registry-prometheus")
43+
implementation("io.micrometer:micrometer-tracing-bridge-brave")
44+
4845
implementation("ch.qos.logback:logback-classic")
4946
implementation("net.logstash.logback:logstash-logback-encoder:$logstashVersion")
50-
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.14.0")
47+
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.14.2")
5148

5249
testImplementation("org.testcontainers:testcontainers:$testContainersVersion")
5350
testImplementation("org.testcontainers:junit-jupiter:$testContainersVersion")
5451
testImplementation("org.testcontainers:postgresql:$testContainersVersion")
5552
testImplementation("io.mockk:mockk:$mockkVersion")
56-
testImplementation("org.springframework:spring-mock:2.0.8")
5753
testImplementation("org.springframework.boot:spring-boot-starter-test")
58-
testImplementation("org.mockito:mockito-inline:4.8.1")
54+
testImplementation("org.mockito:mockito-inline:5.1.1")
5955
}
6056

6157
tasks.withType<KotlinCompile> {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

gradlew

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

33
#
4-
# Copyright © 2015-2021 the original authors.
4+
# Copyright © 2015-2021 the original authors.
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -32,10 +32,10 @@
3232
# Busybox and similar reduced shells will NOT work, because this script
3333
# requires all of these POSIX shell features:
3434
# * functions;
35-
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
36-
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
37-
# * compound commands having a testable exit status, especially «case»;
38-
# * various built-in commands including «command», «set», and «ulimit».
35+
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
36+
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
37+
# * compound commands having a testable exit status, especially «case»;
38+
# * various built-in commands including «command», «set», and «ulimit».
3939
#
4040
# Important for patching:
4141
#
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package no.nav.klage.document.config
2+
3+
import io.micrometer.tracing.Tracer
4+
import jakarta.servlet.FilterChain
5+
import jakarta.servlet.ServletRequest
6+
import jakarta.servlet.ServletResponse
7+
import org.springframework.beans.factory.annotation.Value
8+
import org.springframework.context.annotation.Profile
9+
import org.springframework.core.annotation.Order
10+
import org.springframework.stereotype.Component
11+
import org.springframework.web.filter.GenericFilterBean
12+
13+
/**
14+
* Adding some custom NAV-specific attributes to standard Spring Sleuth/Micrometer
15+
*/
16+
@Component
17+
@Profile("!local")
18+
@Order(-20)
19+
class CustomTraceFilter(
20+
private val tracer: Tracer,
21+
@Value("\${navCallIdName}") private val navCallIdName: String,
22+
) : GenericFilterBean() {
23+
24+
override fun doFilter(
25+
request: ServletRequest?, response: ServletResponse,
26+
chain: FilterChain
27+
) {
28+
//Create if not exists
29+
tracer.createBaggage(navCallIdName, tracer.currentTraceContext().context()!!.traceId())
30+
31+
//also add this, since some services require that version/spelling
32+
tracer.createBaggage("Nav-Call-Id", tracer.currentTraceContext().context()!!.traceId())
33+
34+
chain.doFilter(request, response)
35+
}
36+
}

src/main/kotlin/no/nav/klage/document/config/OpenApiConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package no.nav.klage.document.config
22

33
import no.nav.klage.document.api.DocumentController
4-
import org.springdoc.core.GroupedOpenApi
4+
import org.springdoc.core.models.GroupedOpenApi
55
import org.springframework.context.annotation.Bean
66
import org.springframework.context.annotation.Configuration
77

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,59 @@
11
package no.nav.klage.document.config
22

33
import no.nav.klage.document.exceptions.MissingAccessException
4-
import no.nav.klage.document.util.getLogger
5-
import org.springframework.http.ResponseEntity
4+
import no.nav.klage.document.util.getSecureLogger
5+
import org.springframework.http.HttpStatus
6+
import org.springframework.http.ProblemDetail
67
import org.springframework.orm.jpa.JpaObjectRetrievalFailureException
7-
import org.springframework.web.bind.annotation.ControllerAdvice
88
import org.springframework.web.bind.annotation.ExceptionHandler
9+
import org.springframework.web.bind.annotation.RestControllerAdvice
910
import org.springframework.web.context.request.NativeWebRequest
10-
import org.zalando.problem.Problem
11-
import org.zalando.problem.Status
12-
import org.zalando.problem.spring.web.advice.AdviceTrait
13-
import org.zalando.problem.spring.web.advice.ProblemHandling
11+
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
1412

15-
@ControllerAdvice
16-
class ProblemHandlingControllerAdvice : OurOwnExceptionAdviceTrait, ProblemHandling
17-
18-
interface OurOwnExceptionAdviceTrait : AdviceTrait {
13+
@RestControllerAdvice
14+
class ProblemHandlingControllerAdvice : ResponseEntityExceptionHandler() {
1915

2016
companion object {
21-
@Suppress("JAVA_CLASS_ON_COMPANION")
22-
private val logger = getLogger(javaClass.enclosingClass)
17+
private val secureLogger = getSecureLogger()
2318
}
2419

2520
@ExceptionHandler
2621
fun handleEntityNotFound(
2722
ex: JpaObjectRetrievalFailureException,
2823
request: NativeWebRequest
29-
): ResponseEntity<Problem> =
30-
create(Status.NOT_FOUND, ex, request)
24+
): ProblemDetail =
25+
create(HttpStatus.NOT_FOUND, ex)
3126

3227
@ExceptionHandler
3328
fun handleMissingAccess(
3429
ex: MissingAccessException,
3530
request: NativeWebRequest
36-
): ResponseEntity<Problem> =
37-
create(Status.FORBIDDEN, ex, request)
31+
): ProblemDetail =
32+
create(HttpStatus.FORBIDDEN, ex)
33+
34+
private fun create(httpStatus: HttpStatus, ex: Exception): ProblemDetail {
35+
val errorMessage = ex.message ?: "No error message available"
36+
37+
logError(
38+
httpStatus = httpStatus,
39+
errorMessage = errorMessage,
40+
exception = ex
41+
)
42+
43+
return ProblemDetail.forStatusAndDetail(httpStatus, errorMessage).apply {
44+
title = errorMessage
45+
}
46+
}
47+
48+
private fun logError(httpStatus: HttpStatus, errorMessage: String, exception: Exception) {
49+
when {
50+
httpStatus.is5xxServerError -> {
51+
secureLogger.error("Exception thrown to client: ${httpStatus.reasonPhrase}, $errorMessage", exception)
52+
}
53+
54+
else -> {
55+
secureLogger.warn("Exception thrown to client: ${httpStatus.reasonPhrase}, $errorMessage", exception)
56+
}
57+
}
58+
}
3859
}

src/main/kotlin/no/nav/klage/document/config/SecurityConfiguration.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package no.nav.klage.document.config
33
import no.nav.security.token.support.spring.api.EnableJwtTokenValidation
44
import org.springframework.context.annotation.Configuration
55

6-
@EnableJwtTokenValidation(ignore = ["org.springdoc"])
6+
@EnableJwtTokenValidation(ignore = ["org.springdoc", "org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController"])
77
@Configuration
88
internal class SecurityConfiguration {
99

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package no.nav.klage.document.config
2+
3+
import org.springframework.context.annotation.Configuration
4+
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer
5+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
6+
7+
8+
@Configuration
9+
class WebConfiguration : WebMvcConfigurer {
10+
override fun configurePathMatch(configurer: PathMatchConfigurer) {
11+
configurer.setUseTrailingSlashMatch(true)
12+
}
13+
}

src/main/kotlin/no/nav/klage/document/domain/Comment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package no.nav.klage.document.domain
22

3+
import jakarta.persistence.*
34
import org.hibernate.annotations.BatchSize
45
import org.hibernate.annotations.Fetch
56
import org.hibernate.annotations.FetchMode
67
import java.time.LocalDateTime
78
import java.util.*
8-
import javax.persistence.*
99

1010
@Entity
1111
@Table(name = "comment", schema = "klage")

src/main/kotlin/no/nav/klage/document/domain/Document.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package no.nav.klage.document.domain
22

3+
import jakarta.persistence.Column
4+
import jakarta.persistence.Entity
5+
import jakarta.persistence.Id
6+
import jakarta.persistence.Table
37
import java.time.LocalDateTime
48
import java.util.*
5-
import javax.persistence.Column
6-
import javax.persistence.Entity
7-
import javax.persistence.Id
8-
import javax.persistence.Table
99

1010
@Entity
1111
@Table(name = "document", schema = "klage")

0 commit comments

Comments
 (0)