Skip to content

Commit e54986c

Browse files
authored
Konvertert til Kotlin og JDK 21, i tillegg en masse tender love & care. (#812)
1 parent 5b3c889 commit e54986c

File tree

282 files changed

+4940
-8537
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

282 files changed

+4940
-8537
lines changed

.github/workflows/build-master.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ jobs:
1818
- name: Checkout latest code
1919
uses: actions/checkout@v4
2020

21-
- name: Set up JDK 17
21+
- name: Set up JDK 21
2222
uses: actions/setup-java@v4
2323
with:
24-
java-version: 17
24+
java-version: 21
2525
distribution: temurin
2626
- name: Setup build cache
2727
uses: actions/cache@v3

.github/workflows/codeql-analysis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ jobs:
2727
- name: Checkout repository
2828
uses: actions/checkout@v4
2929

30-
- name: Setter opp Java 17
30+
- name: Setter opp Java 21
3131
uses: actions/setup-java@v4
3232
with:
33-
java-version: 17
33+
java-version: 21
3434
distribution: temurin
3535
cache: maven
3636

@@ -50,4 +50,4 @@ jobs:
5050
- name: Perform CodeQL Analysis
5151
uses: github/codeql-action/analyze@v3
5252
with:
53-
category: "/language:${{matrix.language}}"
53+
category: "/language:${{matrix.language}}"

.github/workflows/publish-release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212
- name: Checkout latest code
1313
uses: actions/checkout@v4
1414

15-
- name: Set up JDK 17
15+
- name: Set up JDK 21
1616
uses: actions/setup-java@v4
1717
with:
18-
java-version: 17
18+
java-version: 21
1919
distribution: temurin
2020
cache: maven
2121

@@ -51,4 +51,4 @@ jobs:
5151
# run: |
5252
# git config user.email "actions@github.com"
5353
# git config user.name "GitHub Actions release"
54-
# ./mvnw --settings .github/settings.xml -Pgithub --batch-mode -Dmaven.main.skip=true -Dmaven.test.skip=true deploy
54+
# ./mvnw --settings .github/settings.xml -Pgithub --batch-mode -Dmaven.main.skip=true -Dmaven.test.skip=true deploy

.github/workflows/test-pull-requests.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
with:
1212
fetch-depth: 0
1313

14-
- name: Set up JDK 17
14+
- name: Set up JDK 21
1515
uses: actions/setup-java@v4
1616
with:
17-
java-version: 17
17+
java-version: 21
1818
distribution: temurin
1919

2020
- name: Setup build cache
@@ -30,5 +30,4 @@ jobs:
3030
GITHUB_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
3131
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
3232
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33-
run: mvn -B test
34-
33+
run: mvn -B test

.java-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
17
1+
21.0.1

pom.xml

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
<module>token-validation-spring-test</module>
3434
<module>token-validation-jaxrs</module>
3535
<module>token-validation-spring-demo</module>
36-
<module>token-validation-ktor</module>
3736
<module>token-validation-ktor-v2</module>
3837
<module>token-validation-ktor-demo</module>
3938
<module>token-client-spring</module>
@@ -42,6 +41,7 @@
4241
<module>token-client-core</module>
4342
</modules>
4443
<properties>
44+
<kotlin.version>1.9.22</kotlin.version>
4545
<kotlin-coroutines.version>1.6.2</kotlin-coroutines.version>
4646
<doclint>none</doclint>
4747
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
@@ -55,63 +55,26 @@
5555
<spring-boot.version>3.2.1</spring-boot.version>
5656
<oauth2-oidc-sdk.version>11.9</oauth2-oidc-sdk.version>
5757
<validation-api.version>2.0.1.Final</validation-api.version>
58-
<rest-assured.version>5.4.0</rest-assured.version>
5958
<mockwebserver.version>4.12.0</mockwebserver.version>
6059
<caffeine.version>3.1.8</caffeine.version>
6160
<okhttp3.version>4.12.0</okhttp3.version>
62-
<ktor.version>1.6.8</ktor.version>
61+
<ktor.version>2.3.6</ktor.version>
6362
<kotlin.code.style>official</kotlin.code.style>
6463
<kotlin.version>1.9.22</kotlin.version>
6564
<mock-oauth2-server.version>2.1.0</mock-oauth2-server.version>
6665
<nimbus.jose.jwt.version>9.37.3</nimbus.jose.jwt.version>
6766
<kotest.version>5.8.0</kotest.version>
6867
<kotlin.compiler.jvmTarget>17</kotlin.compiler.jvmTarget>
6968
</properties>
70-
7169
<scm>
7270
<url>https://github.com/navikt/token-support</url>
7371
<connection>scm:git:git@github.com:navikt/token-support.git</connection>
7472
<developerConnection>scm:git:git@github.com:navikt/token-support.git</developerConnection>
7573
<tag>HEAD</tag>
7674
</scm>
7775
<build>
78-
<plugins>
79-
<plugin>
80-
<groupId>org.apache.maven.plugins</groupId>
81-
<artifactId>maven-surefire-plugin</artifactId>
82-
<version>3.2.3</version>
83-
</plugin>
84-
<plugin>
85-
<groupId>org.jacoco</groupId>
86-
<artifactId>jacoco-maven-plugin</artifactId>
87-
<version>0.8.11</version>
88-
<executions>
89-
<execution>
90-
<goals>
91-
<goal>prepare-agent</goal>
92-
</goals>
93-
</execution>
94-
<execution>
95-
<id>report</id>
96-
<goals>
97-
<goal>report</goal>
98-
</goals>
99-
</execution>
100-
</executions>
101-
</plugin>
102-
</plugins>
10376
<pluginManagement>
10477
<plugins>
105-
<plugin>
106-
<groupId>org.apache.maven.plugins</groupId>
107-
<artifactId>maven-compiler-plugin</artifactId>
108-
<version>3.12.1</version>
109-
<configuration>
110-
<compilerArgs>
111-
<arg>-parameters</arg>
112-
</compilerArgs>
113-
</configuration>
114-
</plugin>
11578
<plugin>
11679
<groupId>org.jetbrains.kotlin</groupId>
11780
<artifactId>kotlin-maven-plugin</artifactId>
@@ -262,6 +225,13 @@
262225
</profiles>
263226
<dependencyManagement>
264227
<dependencies>
228+
<dependency>
229+
<groupId>org.jetbrains.kotlin</groupId>
230+
<artifactId>kotlin-bom</artifactId>
231+
<version>${kotlin.version}</version>
232+
<type>pom</type>
233+
<scope>import</scope>
234+
</dependency>
265235
<dependency>
266236
<groupId>org.springframework.boot</groupId>
267237
<artifactId>spring-boot-dependencies</artifactId>
@@ -432,6 +402,12 @@
432402
<artifactId>mockito-core</artifactId>
433403
<scope>test</scope>
434404
</dependency>
405+
<dependency>
406+
<groupId>org.mockito.kotlin</groupId>
407+
<artifactId>mockito-kotlin</artifactId>
408+
<version>5.2.1</version>
409+
<scope>test</scope>
410+
</dependency>
435411
<dependency>
436412
<groupId>org.mockito</groupId>
437413
<artifactId>mockito-junit-jupiter</artifactId>
@@ -442,4 +418,4 @@
442418
<artifactId>nimbus-jose-jwt</artifactId>
443419
</dependency>
444420
</dependencies>
445-
</project>
421+
</project>

token-client-core/src/main/kotlin/no/nav/security/token/support/client/core/ClientAuthenticationProperties.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package no.nav.security.token.support.client.core;
1+
package no.nav.security.token.support.client.core
22

33
import com.nimbusds.jose.jwk.RSAKey
44
import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod
@@ -43,5 +43,5 @@ class ClientAuthenticationProperties @JvmOverloads constructor(val clientId: Str
4343
class ClientAuthenticationPropertiesBuilder @JvmOverloads constructor(private val clientId: String, private val clientAuthMethod: ClientAuthenticationMethod, private var clientSecret: String? = null, private var clientJwk: String? = null) {
4444
fun clientSecret(clientSecret: String)= this.also { it.clientSecret = clientSecret }
4545
fun clientJwk(clientJwk: String)= this.also { it.clientJwk = clientJwk }
46-
fun build() = ClientAuthenticationProperties(clientId, clientAuthMethod, clientSecret, clientJwk);
46+
fun build() = ClientAuthenticationProperties(clientId, clientAuthMethod, clientSecret, clientJwk)
4747
}

token-client-core/src/main/kotlin/no/nav/security/token/support/client/core/ClientProperties.kt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
package no.nav.security.token.support.client.core;
1+
package no.nav.security.token.support.client.core
22

3-
import com.nimbusds.jose.util.DefaultResourceRetriever;
3+
import com.nimbusds.jose.util.DefaultResourceRetriever
44
import com.nimbusds.oauth2.sdk.GrantType
5+
import com.nimbusds.oauth2.sdk.GrantType.CLIENT_CREDENTIALS
6+
import com.nimbusds.oauth2.sdk.GrantType.JWT_BEARER
7+
import com.nimbusds.oauth2.sdk.GrantType.TOKEN_EXCHANGE
58
import com.nimbusds.oauth2.sdk.ParseException
69
import com.nimbusds.oauth2.sdk.`as`.AuthorizationServerMetadata
710
import java.io.IOException
811
import java.net.URI
12+
913
class ClientProperties @JvmOverloads constructor(var tokenEndpointUrl: URI? = null,
1014
private val wellKnownUrl: URI? = null,
1115
val grantType: GrantType,
@@ -16,8 +20,8 @@ class ClientProperties @JvmOverloads constructor(var tokenEndpointUrl: URI? = nu
1620

1721

1822
init {
23+
tokenEndpointUrl = tokenEndpointUrl ?: endpointUrlFromMetadata(requireNotNull(wellKnownUrl))
1924
require(grantType in GRANT_TYPES) { "Unsupported grantType $grantType, must be one of $GRANT_TYPES" }
20-
tokenEndpointUrl = tokenEndpointUrl ?: endpointUrlFromMetadata(wellKnownUrl)
2125
}
2226

2327

@@ -30,34 +34,38 @@ class ClientProperties @JvmOverloads constructor(var tokenEndpointUrl: URI? = nu
3034
.tokenExchange(tokenExchange)
3135

3236
companion object {
33-
private val GRANT_TYPES = listOf(GrantType.JWT_BEARER, GrantType.CLIENT_CREDENTIALS, GrantType.TOKEN_EXCHANGE)
37+
private val GRANT_TYPES = listOf(JWT_BEARER, CLIENT_CREDENTIALS, TOKEN_EXCHANGE)
3438

3539
@JvmStatic
3640
fun builder(grantType: GrantType, authentication: ClientAuthenticationProperties) = ClientPropertiesBuilder(grantType, authentication)
3741

3842
private fun endpointUrlFromMetadata(wellKnown: URI?) =
3943
runCatching {
4044
wellKnown?.let { AuthorizationServerMetadata.parse(DefaultResourceRetriever().retrieveResource(wellKnown.toURL()).content).tokenEndpointURI }
41-
?: throw OAuth2ClientException("Well knowcn url cannot be null, please check your configuration")
45+
?: throw OAuth2ClientException("Well-known url cannot be null, please check your configuration")
4246
}.getOrElse {
4347
when(it) {
4448
is ParseException-> throw OAuth2ClientException("Unable to parse response from $wellKnown", it)
45-
is IOException -> throw OAuth2ClientException("Unable to read from $wellKnown", it)
49+
is IOException -> throw OAuth2ClientException("Unable to read from $wellKnown", it)
4650
is OAuth2ClientException -> throw it
4751
else -> throw OAuth2ClientException("Unexpected error reading from $wellKnown", it)
4852
}
4953
}
5054
}
5155

52-
class ClientPropertiesBuilder @JvmOverloads constructor(private val grantType: GrantType, val authentication: ClientAuthenticationProperties,
56+
class ClientPropertiesBuilder @JvmOverloads constructor(private val grantType: GrantType,
57+
val authentication: ClientAuthenticationProperties,
5358
private var tokenEndpointUrl: URI? = null,
5459
private var wellKnownUrl: URI? = null,
5560
private var scope: List<String> = emptyList(),
5661
private var resourceUrl: URI? = null,
5762
private var tokenExchange: TokenExchangeProperties? = null) {
5863

64+
fun tokenEndpointUrl(endpointURI: String?) = endpointURI?.let { tokenEndpointUrl(URI.create(it)) } ?: this
5965
fun tokenEndpointUrl(endpointURI: URI?) = this.also { it.tokenEndpointUrl = endpointURI }
66+
fun wellKnownUrl(wellKnownURI: String?) = wellKnownURI?.let { wellKnownUrl(URI.create(it)) } ?: this
6067
fun wellKnownUrl(wellKnownURI: URI?) = this.also { it.wellKnownUrl = wellKnownURI }
68+
fun scopes(vararg scopes: String) = scope(scopes.toList())
6169
fun scope(scope: List<String>) = this.also { it.scope = scope}
6270
fun resourceUrl(resourceUrl: URI?) = this.also { it.resourceUrl = resourceUrl }
6371
fun tokenExchange(tokenExchange: TokenExchangeProperties?) = this.also { it.tokenExchange = tokenExchange }
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package no.nav.security.token.support.client.core
22

33
import com.nimbusds.oauth2.sdk.GrantType
4+
import kotlin.DeprecationLevel.WARNING
45

5-
@Deprecated("Use GrantType from nimbus instead", ReplaceWith("GrantType"), DeprecationLevel.WARNING)
6-
data class OAuth2GrantType(@JvmField val value : String) {
7-
fun value() = value
8-
6+
@Deprecated("Use GrantType from nimbus instead", ReplaceWith("GrantType"), WARNING)
7+
data class OAuth2GrantType(val value : String) {
98
companion object {
109
@JvmField
11-
@Deprecated("Use GrantType.JWT_BEARER from nimbus instead")
12-
val JWT_BEARER = OAuth2GrantType(GrantType.JWT_BEARER.value)
10+
@Deprecated("Use com.nimbusds.oauth2.sdk.GrantType instead", ReplaceWith("GrantType.JWT_BEARER"), WARNING)
11+
val JWT_BEARER = GrantType(GrantType.JWT_BEARER.value)
1312
@JvmField
14-
@Deprecated("Use GrantType.CLIENT_CREDENTIALS from nimbus instead")
15-
val CLIENT_CREDENTIALS = OAuth2GrantType(GrantType.CLIENT_CREDENTIALS.value)
13+
@Deprecated("Use com.nimbusds.oauth2.sdk.GrantType instead", ReplaceWith("GrantType.CLIENT_CREDENTIALS"), WARNING)
14+
val CLIENT_CREDENTIALS = GrantType(GrantType.CLIENT_CREDENTIALS.value)
1615
@JvmField
17-
@Deprecated("Use GrantType.TOKEN_EXCHANGE from nimbus instead")
18-
val TOKEN_EXCHANGE = OAuth2GrantType(GrantType.TOKEN_EXCHANGE.value)
16+
@Deprecated("Use com.nimbusds.oauth2.sdk.GrantType instead", ReplaceWith("GrantType.TOKEN_EXCHANGE"), WARNING)
17+
val TOKEN_EXCHANGE = GrantType(GrantType.TOKEN_EXCHANGE.value)
1918
}
2019
}

token-client-core/src/main/kotlin/no/nav/security/token/support/client/core/auth/ClientAssertion.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
11
package no.nav.security.token.support.client.core.auth
22

3-
import com.nimbusds.jose.JOSEObjectType.*
4-
import com.nimbusds.jose.JWSAlgorithm.*
3+
import com.nimbusds.jose.JOSEObjectType.JWT
4+
import com.nimbusds.jose.JWSAlgorithm.RS256
55
import com.nimbusds.jose.JWSHeader
66
import com.nimbusds.jose.crypto.RSASSASigner
77
import com.nimbusds.jose.jwk.RSAKey
8+
import com.nimbusds.jwt.JWTClaimNames.JWT_ID
89
import com.nimbusds.jwt.JWTClaimsSet
910
import com.nimbusds.jwt.JWTClaimsSet.Builder
1011
import com.nimbusds.jwt.SignedJWT
11-
import com.nimbusds.oauth2.sdk.auth.JWTAuthentication.*
12+
import com.nimbusds.oauth2.sdk.auth.JWTAuthentication.CLIENT_ASSERTION_TYPE
1213
import java.net.URI
13-
import java.time.Instant.*
14+
import java.time.Instant.now
1415
import java.util.Date
1516
import java.util.UUID
17+
import kotlin.DeprecationLevel.WARNING
1618
import no.nav.security.token.support.client.core.ClientAuthenticationProperties
1719

18-
class ClientAssertion(private val tokenEndpointUrl : URI, private val clientId : String, private val rsaKey : RSAKey, private val expiryInSeconds : Int) {
19-
constructor(tokenEndpointUrl: URI, auth : ClientAuthenticationProperties) : this(tokenEndpointUrl, auth.clientId, auth.clientRsaKey!!, EXPIRY_IN_SECONDS)
20+
class ClientAssertion(private val tokenEndpointUrl : URI?, private val clientId : String, private val rsaKey : RSAKey, private val expiryInSeconds : Int) {
21+
constructor(tokenEndpointUrl: URI?, auth : ClientAuthenticationProperties) : this(tokenEndpointUrl, auth.clientId, auth.clientRsaKey!!, EXPIRY_IN_SECONDS)
2022

2123
fun assertion() =
2224
now().run {
2325
createSignedJWT(rsaKey, Builder()
24-
.audience(tokenEndpointUrl.toString())
26+
.audience("$tokenEndpointUrl")
2527
.expirationTime(Date.from(plusSeconds(expiryInSeconds.toLong())))
2628
.issuer(clientId)
2729
.subject(clientId)
28-
.claim("jti", UUID.randomUUID().toString())
30+
.claim(JWT_ID, "${UUID.randomUUID()}")
2931
.notBeforeTime(Date.from(this))
3032
.issueTime(Date.from(this))
3133
.build()).serialize()
3234
}
3335

36+
@Deprecated("Use com.nimbusds.oauth2.sdk.auth.JWTAuthentication instead", ReplaceWith("JWTAuthentication.CLIENT_ASSERTION_TYPE"), WARNING)
3437
fun assertionType() = CLIENT_ASSERTION_TYPE
3538

3639
private fun createSignedJWT(rsaJwk : RSAKey, claimsSet : JWTClaimsSet) =
37-
3840
runCatching {
3941
SignedJWT(JWSHeader.Builder(RS256)
4042
.keyID(rsaJwk.keyID)
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package no.nav.security.token.support.client.core.context
22

3-
import java.util.Optional
4-
53
fun interface JwtBearerTokenResolver {
6-
fun token() : Optional<String>
4+
5+
fun token() : String?
76
}

token-client-core/src/main/kotlin/no/nav/security/token/support/client/core/http/OAuth2HttpClient.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ package no.nav.security.token.support.client.core.http
33
import no.nav.security.token.support.client.core.oauth2.OAuth2AccessTokenResponse
44

55
interface OAuth2HttpClient {
6-
7-
fun post(oAuth2HttpRequest : OAuth2HttpRequest) : OAuth2AccessTokenResponse?
6+
fun post(request : OAuth2HttpRequest) : OAuth2AccessTokenResponse?
87
}

token-client-core/src/main/kotlin/no/nav/security/token/support/client/core/http/OAuth2HttpHeaders.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class OAuth2HttpHeaders (val headers : Map<String, List<String>>) {
1515

1616
override fun hashCode() = Objects.hash(headers)
1717

18-
override fun toString() = javaClass.getSimpleName() + " [headers=" + headers + "]"
18+
override fun toString() = "${javaClass.getSimpleName()} [headers=$headers]"
1919

2020
class Builder(private val headers : TreeMap<String, MutableList<String>> = TreeMap(CASE_INSENSITIVE_ORDER)) {
2121

0 commit comments

Comments
 (0)