diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 60bd987..e556f61 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -29,6 +29,7 @@ jobs: with: readertoken: false buildcommand: './gradlew check' + javaversion: 21 codeql: uses: navikt/sif-gha-workflows/.github/workflows/gradle-codeql.yml@main @@ -42,6 +43,7 @@ jobs: readertoken: false package-command: './gradlew clean build -x test' branch: main + javaversion: 21 build: uses: navikt/sif-gha-workflows/.github/workflows/gradle-build.yml@main @@ -54,6 +56,7 @@ jobs: team: dusseldorf readertoken: false buildcommand: '--configuration-cache build -x test' + javaversion: 21 trivy: needs: [ build ] diff --git a/build.gradle.kts b/build.gradle.kts index 974247b..50f59dc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,18 +1,18 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - kotlin("jvm") version "1.9.22" - kotlin("plugin.spring") version "1.9.22" - kotlin("plugin.jpa") version "1.9.22" - id("org.springframework.boot") version "3.2.2" + kotlin("jvm") version "1.9.23" + kotlin("plugin.spring") version "1.9.23" + kotlin("plugin.jpa") version "1.9.23" + id("org.springframework.boot") version "3.2.4" id("io.spring.dependency-management") version "1.1.4" - id("org.sonarqube") version "4.4.1.3373" + id("org.sonarqube") version "5.0.0.4638" jacoco } group = "no.nav" version = "0.0.1-SNAPSHOT" -java.sourceCompatibility = JavaVersion.VERSION_17 +java.sourceCompatibility = JavaVersion.VERSION_21 @@ -22,20 +22,20 @@ configurations { } } -val logstashLogbackEncoderVersion by extra("7.2") -val tokenSupportVersion by extra("3.2.0") +val logstashLogbackEncoderVersion by extra("7.4") +val tokenSupportVersion by extra("4.1.4") val springCloudVersion by extra("2022.0.0-RC2") -val retryVersion by extra("2.0.2") -val postgresqlVersion by extra("42.5.1") -val awailitilityKotlinVersion by extra("4.2.0") -val assertkJvmVersion by extra("0.25") -val springMockkVersion by extra("3.1.2") -val mockkVersion by extra("1.13.2") +val retryVersion by extra("2.0.5") +val postgresqlVersion by extra("42.7.2") +val awailitilityKotlinVersion by extra("4.2.1") +val assertkJvmVersion by extra("0.28.0") +val springMockkVersion by extra("4.0.2") +val mockkVersion by extra("1.13.10") val guavaVersion by extra("31.1-jre") -val okHttp3Version by extra("4.10.0") -val orgJsonVersion by extra("20231013") -val springdocVersion by extra("2.3.0") -val testcontainersVersion by extra("1.17.6") +val okHttp3Version by extra("4.12.0") +val orgJsonVersion by extra("20240303") +val springdocVersion by extra("2.5.0") +val testcontainersVersion by extra("1.19.7") ext["testcontainersVersion"] = testcontainersVersion @@ -140,7 +140,7 @@ tasks { withType { kotlinOptions { freeCompilerArgs = listOf("-Xjsr305=strict") - jvmTarget = "17" + jvmTarget = "21" } } @@ -149,7 +149,7 @@ tasks { } withType { - gradleVersion = "8.2.1" + gradleVersion = "8.5" } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9f4197d..1af9e09 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/kotlin/no/nav/cache/cache/CacheService.kt b/src/main/kotlin/no/nav/cache/cache/CacheService.kt index eb42dd0..53925ad 100644 --- a/src/main/kotlin/no/nav/cache/cache/CacheService.kt +++ b/src/main/kotlin/no/nav/cache/cache/CacheService.kt @@ -33,7 +33,7 @@ class CacheService( @Transactional("transactionManager") fun lagre(cacheRequestDTO: CacheRequestDTO): CacheResponseDTO { - val fnr = tokenValidationContextHolder.personIdentifikator() + val fnr = getFnrFraToken() if (repo.existsById(genererNøkkel(cacheRequestDTO.nøkkelPrefiks, fnr))) throw CacheConflictException(cacheRequestDTO.nøkkelPrefiks) @@ -45,7 +45,7 @@ class CacheService( } fun oppdater(cacheEntryDTO: CacheRequestDTO): CacheResponseDTO { - val fnr = tokenValidationContextHolder.personIdentifikator() + val fnr = getFnrFraToken() val cacheEntryDAO = repo.findByNøkkel(genererNøkkel(cacheEntryDTO.nøkkelPrefiks, fnr)) ?: throw CacheNotFoundException( cacheEntryDTO.nøkkelPrefiks @@ -56,7 +56,7 @@ class CacheService( @Throws(CacheNotFoundException::class) fun hent(nøkkelPrefiks: String): CacheResponseDTO { - val fnr = tokenValidationContextHolder.personIdentifikator() + val fnr = getFnrFraToken() return repo.findByNøkkel(genererNøkkel(nøkkelPrefiks, fnr))?.somCacheResponseDTO(fnr) ?: throw CacheNotFoundException(nøkkelPrefiks) } @@ -64,7 +64,7 @@ class CacheService( @Transactional("transactionManager") @Throws(FailedCacheDeletionException::class) fun slett(nøkkelPrefiks: String) { - val fnr = tokenValidationContextHolder.personIdentifikator() + val fnr = getFnrFraToken() val cacheEntryDAO = repo.findByNøkkel(genererNøkkel(nøkkelPrefiks, fnr)) ?: throw CacheNotFoundException(nøkkelPrefiks) @@ -116,6 +116,9 @@ class CacheService( endret = endret ) } + + private fun getFnrFraToken(): String = + tokenValidationContextHolder.personIdentifikator() ?: throw IllegalStateException("Token mangler fnr") } class CacheNotFoundException(nøkkelPrefiks: String) : diff --git a/src/main/kotlin/no/nav/cache/util/TokenUtils.kt b/src/main/kotlin/no/nav/cache/util/TokenUtils.kt index e4a43ca..f622f75 100644 --- a/src/main/kotlin/no/nav/cache/util/TokenUtils.kt +++ b/src/main/kotlin/no/nav/cache/util/TokenUtils.kt @@ -5,10 +5,15 @@ import no.nav.security.token.support.spring.SpringTokenValidationContextHolder object TokenUtils { fun SpringTokenValidationContextHolder.personIdentifikator() = - tokenValidationContext.firstValidToken.get().personIdentifikator() + getTokenValidationContext() + .firstValidToken?.personIdentifikator() fun JwtToken.personIdentifikator(): String = - jwtTokenClaims["pid"] as String? - ?: jwtTokenClaims["sub"] as String? - ?: throw IllegalStateException("Token claims inneholder verken pid eller sub.") + if (jwtTokenClaims.allClaims.containsKey("pid")) { + jwtTokenClaims.getStringClaim("pid") + } else if (jwtTokenClaims.allClaims.containsKey("sub")) { + jwtTokenClaims.getStringClaim("sub") + } else { + throw IllegalStateException("Token claims inneholder verken pid eller sub.") + } }