Skip to content

Commit 580cb7b

Browse files
authored
Merge pull request #33 from navikt/ktor-3
Tilpasser ktor 3. Fjerner logikk for gamle innloggingsnivå.
2 parents 68e36f8 + 641d938 commit 580cb7b

File tree

22 files changed

+30
-136
lines changed

22 files changed

+30
-136
lines changed

azure-validation/src/main/kotlin/no/nav/tms/token/support/azure/validation/AzurePrincipal.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ package no.nav.tms.token.support.azure.validation
33
import com.auth0.jwt.interfaces.DecodedJWT
44
import io.ktor.server.auth.*
55

6-
data class AzurePrincipal(val decodedJWT: DecodedJWT) : Principal
6+
data class AzurePrincipal(val decodedJWT: DecodedJWT)

buildSrc/src/main/kotlin/dependencies.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ object Caffeine : DependencyGroup {
1818
}
1919

2020
object JacksonDatatype: DependencyGroup {
21-
override val version get() = "2.17.0"
21+
override val version get() = "2.18.0"
2222

2323
val datatypeJsr310 get() = dependency("jackson-datatype-jsr310", groupId = "com.fasterxml.jackson.datatype")
2424
val moduleKotlin get() = dependency("jackson-module-kotlin", groupId = "com.fasterxml.jackson.module")
@@ -30,15 +30,15 @@ object Kotlin {
3030

3131
object Kotest : DependencyGroup {
3232
override val groupId = "io.kotest"
33-
override val version = "5.8.1"
33+
override val version = "5.9.1"
3434

3535
val runnerJunit = dependency("kotest-runner-junit5")
3636
val assertionsCore = dependency("kotest-assertions-core")
3737
val extensions = dependency("kotest-extensions")
3838
}
3939

4040
object Ktor : DependencyGroup {
41-
override val version = "2.3.10"
41+
override val version = "3.0.1"
4242
override val groupId = "io.ktor"
4343

4444
val serverAuth = dependency("ktor-server-auth")
@@ -59,28 +59,28 @@ object Ktor : DependencyGroup {
5959

6060
object KotlinLogging : DependencyGroup {
6161
override val groupId = "io.github.oshai"
62-
override val version = "6.0.4"
62+
override val version = "7.0.0"
6363

6464
val logging = dependency("kotlin-logging")
6565
}
6666

6767

6868
object Logback : DependencyGroup {
69-
override val version = "1.4.14"
69+
override val version = "1.5.12"
7070
override val groupId = "ch.qos.logback"
7171

7272
val classic = dependency("logback-classic")
7373
}
7474

7575
object Mockk : DependencyGroup {
76-
override val version = "1.13.10"
76+
override val version = "1.13.13"
7777
override val groupId = "io.mockk"
7878

7979
val mockk = dependency("mockk")
8080
}
8181

8282
object Nimbusds : DependencyGroup {
83-
override val version = "9.37.3"
83+
override val version = "9.42"
8484
override val groupId = "com.nimbusds"
8585

8686
val joseJwt = dependency("nimbus-jose-jwt")

idporten-sidecar-mock/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fun Application.setup() {
2929
installIdPortenAuthMock {
3030
setAsDefault = false
3131
alwaysAuthenticated = true
32-
staticLevelOfAssurance = LEVEL_4
32+
staticLevelOfAssurance = HIGH
3333
staticUserPid = '123'
3434
}
3535
}

idporten-sidecar-mock/src/main/kotlin/no/nav/tms/token/support/idporten/sidecar/mock/config.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ fun AuthenticationConfig.idPortenMock(configure: IdPortenMockedAuthenticatorConf
1212
}
1313

1414
enum class LevelOfAssurance(val claim: String) {
15-
LEVEL_3("Level3"),
16-
LEVEL_4("Level4"),
1715
SUBSTANTIAL("idporten-loa-substantial"),
1816
HIGH("idporten-loa-high")
1917
}

idporten-sidecar/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Her er det en rekke variabler:
2323
2424
- `authenticatorName`: Bestemmer navnet på autentikatoren. Default `IdPortenAuthenticator.name`
2525
- `setAsDefault`: (Optional) Setter denne autentikatoren som default. Default 'false'
26-
- `loginLevel`: Deprecated - Bruk `levelOfAssurance` i stedet.
2726
- `levelOfAssurance` (Optional) Setter minimum level-of-assurance for endepunkt. Default 'HIGH'
2827
- `enableDefaultProxy`: (Optional) Bestemmer hvorvidt system-default proxy skal brukes ved kall mot andre tjenester. Nødvendig for on-prem apper med webproxy. Default 'false'.
2928

idporten-sidecar/src/main/kotlin/no/nav/tms/token/support/idporten/sidecar/IdPortenLogin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class IdPortenLogin {
2222

2323
val config = IdPortenLoginConfig().also(configure)
2424

25-
val hello = pipeline.environment.rootPath
25+
val hello = pipeline.rootPath
2626

2727
pipeline.routing {
2828
idPortenLoginApi(

idporten-sidecar/src/main/kotlin/no/nav/tms/token/support/idporten/sidecar/IdPortenTokenPrincipal.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package no.nav.tms.token.support.idporten.sidecar
33
import com.auth0.jwt.interfaces.DecodedJWT
44
import io.ktor.server.auth.*
55

6-
data class IdPortenTokenPrincipal(
7-
val accessToken: DecodedJWT
8-
) : Principal {
9-
fun ident(identClaim: String = "pid"): String = accessToken.getClaim(identClaim).asString()
6+
data class IdPortenTokenPrincipal(val accessToken: DecodedJWT) {
7+
fun ident(identClaim: String = "pid"): String = accessToken.getClaim(identClaim).asString()
108
}

idporten-sidecar/src/main/kotlin/no/nav/tms/token/support/idporten/sidecar/config.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ class IdportenAuthenticationConfig {
1818

1919
var setAsDefault: Boolean = false
2020

21-
@Deprecated("Numbered login levels are deprecated as of Q4 2023. Set levelOfAssurance instead")
22-
var loginLevel: LoginLevel? = null
2321
var levelOfAssurance: LevelOfAssurance = HIGH
2422

2523
var enableDefaultProxy: Boolean = false
@@ -30,10 +28,6 @@ enum class LevelOfAssurance {
3028
HIGH // Equivalent to old Level4
3129
}
3230

33-
enum class LoginLevel {
34-
LEVEL_3, LEVEL_4
35-
}
36-
3731
// Name of token authenticator. See README for example of use
3832
object IdPortenAuthenticator {
3933
const val name = "idporten_access_token"

idporten-sidecar/src/main/kotlin/no/nav/tms/token/support/idporten/sidecar/install/IdPortenInstaller.kt

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ import io.github.oshai.kotlinlogging.KotlinLogging
44
import io.ktor.server.auth.*
55
import no.nav.tms.token.support.idporten.sidecar.IdportenAuthenticationConfig
66
import no.nav.tms.token.support.idporten.sidecar.LevelOfAssurance
7-
import no.nav.tms.token.support.idporten.sidecar.LoginLevel
87

98
internal object IdPortenInstaller {
10-
private val log = KotlinLogging.logger { }
119

1210
// Register authenticator for id-porten tokens
1311
// This can apply to any number of endpoints.
@@ -16,7 +14,7 @@ internal object IdPortenInstaller {
1614
) {
1715
val tokenVerifier = initializeTokenVerifier(
1816
enableDefaultProxy = config.enableDefaultProxy,
19-
minLevelOfAssurance = getMinLoa(config.levelOfAssurance, config.loginLevel)
17+
minLevelOfAssurance = getMinLoa(config.levelOfAssurance)
2018
)
2119

2220
registerIdPortenValidationProvider(
@@ -25,21 +23,12 @@ internal object IdPortenInstaller {
2523
)
2624
}
2725

28-
private fun getMinLoa(loa: LevelOfAssurance, loginLevel: LoginLevel?): IdPortenLevelOfAssurance {
29-
return if (loginLevel != null) {
30-
log.warn { "loginLevel will be deprecated as of Q4 2023. Use levelOfAssurance setting instead." }
31-
when (loginLevel) {
32-
LoginLevel.LEVEL_3 -> IdPortenLevelOfAssurance.Substantial
33-
LoginLevel.LEVEL_4 -> IdPortenLevelOfAssurance.High
34-
}
35-
} else {
36-
when (loa) {
37-
LevelOfAssurance.SUBSTANTIAL -> IdPortenLevelOfAssurance.Substantial
38-
LevelOfAssurance.HIGH -> IdPortenLevelOfAssurance.High
39-
}
40-
}
26+
private fun getMinLoa(loa: LevelOfAssurance) = when (loa) {
27+
LevelOfAssurance.SUBSTANTIAL -> IdPortenLevelOfAssurance.Substantial
28+
LevelOfAssurance.HIGH -> IdPortenLevelOfAssurance.High
4129
}
4230

31+
4332
private fun getAuthenticatorName(config: IdportenAuthenticationConfig): String? {
4433
return if (config.setAsDefault) {
4534
null

idporten-sidecar/src/main/kotlin/no/nav/tms/token/support/idporten/sidecar/install/IdPortenLevelOfAssurance.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package no.nav.tms.token.support.idporten.sidecar.install
22

33
internal enum class IdPortenLevelOfAssurance(val acr: String, val relativeValue: Int) {
4-
Level3("Level3", 2),
5-
Level4("Level4", 3),
64
Low("idporten-loa-low", 1),
75
Substantial("idporten-loa-substantial", 2),
86
High("idporten-loa-high", 3);

idporten-sidecar/src/main/kotlin/no/nav/tms/token/support/idporten/sidecar/install/loginApi.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ internal data class LoginStatus(
112112
companion object {
113113
fun unauthenticated() = LoginStatus(false, null, null)
114114
fun authenticated(levelOfAssuranceInternal: IdPortenLevelOfAssurance) = when (levelOfAssuranceInternal) {
115-
IdPortenLevelOfAssurance.Level3, IdPortenLevelOfAssurance.Substantial -> LoginStatus(true, 3, IdPortenLevelOfAssurance.Substantial.name)
116-
IdPortenLevelOfAssurance.Level4, IdPortenLevelOfAssurance.High -> LoginStatus(true, 4, IdPortenLevelOfAssurance.High.name)
115+
IdPortenLevelOfAssurance.Substantial -> LoginStatus(true, 3, IdPortenLevelOfAssurance.Substantial.name)
116+
IdPortenLevelOfAssurance.High -> LoginStatus(true, 4, IdPortenLevelOfAssurance.High.name)
117117
else -> throw IllegalStateException()
118118
}
119119
}

idporten-sidecar/src/main/kotlin/no/nav/tms/token/support/idporten/sidecar/user/IdportenUser.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import java.time.temporal.ChronoUnit
77

88
data class IdportenUser (
99
val ident: String,
10-
@Deprecated("Use levelOfAssurance instead.") val loginLevel: Int,
1110
val levelOfAssurance: LevelOfAssurance,
1211
val tokenExpirationTime: Instant,
1312
val jwt: DecodedJWT

idporten-sidecar/src/main/kotlin/no/nav/tms/token/support/idporten/sidecar/user/IdportenUserFactory.kt

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,20 @@ object IdportenUserFactory {
3434

3535

3636
val acrLoA = extractLevelOfAssurance(accessToken)
37-
val loginLevel = mapLoginLevel(acrLoA)
3837
val levelOfAssurance = mapLevelOfAssurance(acrLoA)
3938

4039
val expirationTime =
4140
getTokenExpirationLocalDateTime(
4241
accessToken
4342
)
4443

45-
return IdportenUser(ident, loginLevel, levelOfAssurance, expirationTime, accessToken)
46-
}
47-
48-
private fun mapLoginLevel(levelOfAssurance: IdPortenLevelOfAssurance): Int {
49-
50-
return when (levelOfAssurance) {
51-
Level3, Substantial -> 3
52-
Level4, High -> 4
53-
Low -> throw RuntimeException("Level of assurance 'low' er ikke støttet.")
54-
}
44+
return IdportenUser(ident, levelOfAssurance, expirationTime, accessToken)
5545
}
5646

5747
private fun mapLevelOfAssurance(levelOfAssurance: IdPortenLevelOfAssurance): LevelOfAssurance {
5848
return when (levelOfAssurance) {
59-
Level3, Substantial -> SUBSTANTIAL
60-
Level4, High -> HIGH
49+
Substantial -> SUBSTANTIAL
50+
High -> HIGH
6151
Low -> throw RuntimeException("Level of assurance 'low' er ikke støttet.")
6252
}
6353
}

idporten-sidecar/src/test/kotlin/no/nav/tms/token/support/idporten/sidecar/IdPortenPluginTest.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@ package no.nav.tms.token.support.idporten.sidecar
22

33
import com.auth0.jwt.interfaces.Claim
44
import com.auth0.jwt.interfaces.DecodedJWT
5-
import com.fasterxml.jackson.databind.node.NullNode
65
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
7-
import io.kotest.matchers.nulls.shouldBeNull
86
import io.kotest.matchers.shouldBe
97
import io.ktor.client.*
108
import io.ktor.client.request.*
119
import io.ktor.client.statement.*
1210
import io.ktor.http.*
1311
import io.ktor.server.application.*
1412
import io.ktor.server.testing.*
15-
import io.ktor.util.*
13+
import io.ktor.utils.io.*
1614
import io.mockk.*
1715
import no.nav.tms.token.support.idporten.sidecar.install.HttpClientBuilder
1816
import no.nav.tms.token.support.idporten.sidecar.install.IdPortenLevelOfAssurance
@@ -101,7 +99,6 @@ class IdPortenPluginTest {
10199
.let(objectMapper::readTree)
102100
.let {
103101
it["authenticated"]?.asBoolean() shouldBe true
104-
it["level"]?.asInt() shouldBe 4
105102
it["levelOfAssurance"]?.asText() shouldBe IdPortenLevelOfAssurance.High.name
106103
}
107104
}

tokenx-validation-mock/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fun Application.setup() {
3030
tokenXMock {
3131
setAsDefault = false
3232
alwaysAuthenticated = true
33-
staticLevelOfAssurance = LEVEL_4
33+
staticLevelOfAssurance = HIGH
3434
staticUserPid = '123'
3535
}
3636
}

tokenx-validation-mock/src/main/kotlin/no/nav/tms/token/support/tokenx/validation/mock/config.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ fun AuthenticationConfig.tokenXMock(configure: TokenXMockedAuthenticatorConfig.(
1212
}
1313

1414
enum class LevelOfAssurance(val claim: String) {
15-
LEVEL_3("Level3"),
16-
LEVEL_4("Level4"),
1715
SUBSTANTIAL("idporten-loa-substantial"),
1816
HIGH("idporten-loa-high")
1917
}

tokenx-validation-mock/src/test/kotlin/no/nav/tms/token/support/tokenx/validation/mock/TokenXAuthTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ internal class TokenXAuthTest {
4545
tokenXMock {
4646
alwaysAuthenticated = true
4747
staticUserPid = userPid
48-
staticLevelOfAssurance = LevelOfAssurance.LEVEL_4
48+
staticLevelOfAssurance = LevelOfAssurance.HIGH
4949
}
5050
}
5151
}

tokenx-validation/src/main/kotlin/no/nav/tms/token/support/tokenx/validation/TokenXPrincipal.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ package no.nav.tms.token.support.tokenx.validation
33
import com.auth0.jwt.interfaces.DecodedJWT
44
import io.ktor.server.auth.*
55

6-
data class TokenXPrincipal(val decodedJWT: DecodedJWT) : Principal {
6+
data class TokenXPrincipal(val decodedJWT: DecodedJWT) {
77
fun ident(identClaim: String = "pid"): String = decodedJWT.getClaim(identClaim).asString()
88
}

tokenx-validation/src/main/kotlin/no/nav/tms/token/support/tokenx/validation/install/IdPortenLevelOfAssurance.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package no.nav.tms.token.support.tokenx.validation.install
22

33
internal enum class IdPortenLevelOfAssurance(val acr: String, val relativeValue: Int) {
4-
Level3("Level3", 2),
5-
Level4("Level4", 3),
64
Low("idporten-loa-low", 1),
75
Substantial("idporten-loa-substantial", 2),
86
High("idporten-loa-high", 3);

tokenx-validation/src/main/kotlin/no/nav/tms/token/support/tokenx/validation/user/TokenXUser.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import java.time.temporal.ChronoUnit
77

88
data class TokenXUser (
99
val ident: String,
10-
@Deprecated("Use levelOfAssurance instead.") val loginLevel: Int,
1110
val levelOfAssurance: LevelOfAssurance,
1211
val tokenExpirationTime: Instant,
1312
val jwt: DecodedJWT

tokenx-validation/src/main/kotlin/no/nav/tms/token/support/tokenx/validation/user/TokenXUserFactory.kt

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,17 @@ object TokenXUserFactory {
2929

3030
val acrLoA = IdPortenLevelOfAssurance.fromAcr(token.getClaim("acr").asString())
3131

32-
val loginLevel = mapLoginLevel(acrLoA)
3332
val levelOfAssurance = mapLevelOfAssurance(acrLoA)
3433

35-
val expirationTime =
36-
getTokenExpirationLocalDateTime(
37-
token
38-
)
34+
val expirationTime = getTokenExpirationLocalDateTime(token)
3935

40-
return TokenXUser(ident, loginLevel, levelOfAssurance, expirationTime, token)
41-
}
42-
43-
private fun mapLoginLevel(levelOfAssurance: IdPortenLevelOfAssurance): Int {
44-
45-
return when (levelOfAssurance) {
46-
Level3, Substantial -> 3
47-
Level4, High -> 4
48-
Low -> throw RuntimeException("Level of assurance 'low' er ikke støttet.")
49-
}
36+
return TokenXUser(ident, levelOfAssurance, expirationTime, token)
5037
}
5138

5239
private fun mapLevelOfAssurance(levelOfAssurance: IdPortenLevelOfAssurance): LevelOfAssurance {
5340
return when (levelOfAssurance) {
54-
Level3, Substantial -> SUBSTANTIAL
55-
Level4, High -> HIGH
41+
Substantial -> SUBSTANTIAL
42+
High -> HIGH
5643
Low -> throw RuntimeException("Level of assurance 'low' er ikke støttet.")
5744
}
5845
}

0 commit comments

Comments
 (0)