Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oppgrader java til 21 og oppgrader dependencies #123

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -54,6 +56,7 @@ jobs:
team: dusseldorf
readertoken: false
buildcommand: '--configuration-cache build -x test'
javaversion: 21

trivy:
needs: [ build ]
Expand Down
40 changes: 20 additions & 20 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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



Expand All @@ -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

Expand Down Expand Up @@ -140,7 +140,7 @@ tasks {
withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "17"
jvmTarget = "21"
}
}

Expand All @@ -149,7 +149,7 @@ tasks {
}

withType<Wrapper> {
gradleVersion = "8.2.1"
gradleVersion = "8.5"
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 7 additions & 4 deletions src/main/kotlin/no/nav/cache/cache/CacheService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -56,15 +56,15 @@ 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)
}

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

Expand Down Expand Up @@ -116,6 +116,9 @@ class CacheService(
endret = endret
)
}

private fun getFnrFraToken(): String =
tokenValidationContextHolder.personIdentifikator() ?: throw IllegalStateException("Token mangler fnr")
}

class CacheNotFoundException(nøkkelPrefiks: String) :
Expand Down
13 changes: 9 additions & 4 deletions src/main/kotlin/no/nav/cache/util/TokenUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
}
Loading