Skip to content

Commit

Permalink
imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan-Olav Eide committed Mar 29, 2024
1 parent 233c286 commit 013fda8
Show file tree
Hide file tree
Showing 101 changed files with 335 additions and 419 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import com.nimbusds.oauth2.sdk.GrantType.CLIENT_CREDENTIALS
import com.nimbusds.oauth2.sdk.GrantType.JWT_BEARER
import com.nimbusds.oauth2.sdk.GrantType.TOKEN_EXCHANGE
import com.nimbusds.oauth2.sdk.ParseException
import com.nimbusds.oauth2.sdk.`as`.AuthorizationServerMetadata
import com.nimbusds.oauth2.sdk.`as`.AuthorizationServerMetadata.*
import com.nimbusds.oauth2.sdk.`as`.AuthorizationServerMetadata.parse
import java.io.IOException
import java.net.URI

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import com.nimbusds.jwt.SignedJWT
import com.nimbusds.oauth2.sdk.auth.JWTAuthentication.CLIENT_ASSERTION_TYPE
import java.net.URI
import java.time.Instant.now
import java.util.Date
import java.util.UUID
import kotlin.DeprecationLevel.WARNING
import java.util.*
import no.nav.security.token.support.client.core.ClientAuthenticationProperties
import kotlin.DeprecationLevel.WARNING

class ClientAssertion(private val tokenEndpointUrl : URI, private val clientId : String, private val rsaKey : RSAKey, private val expiryInSeconds : Int) {
constructor(tokenEndpointUrl: URI, auth : ClientAuthenticationProperties) : this(tokenEndpointUrl, auth.clientId, auth.clientRsaKey!!, EXPIRY_IN_SECONDS)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package no.nav.security.token.support.client.core.http

import java.lang.String.CASE_INSENSITIVE_ORDER
import java.util.Objects
import java.util.TreeMap
import java.util.*

class OAuth2HttpHeaders (val headers : Map<String, List<String>>) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package no.nav.security.token.support.client.core.oauth2

import com.nimbusds.oauth2.sdk.GrantType
import java.util.Objects
import java.util.*
import no.nav.security.token.support.client.core.ClientProperties

abstract class AbstractOAuth2GrantRequest(val grantType : GrantType, val clientProperties : ClientProperties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod.CLIENT_SECRET_BAS
import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod.CLIENT_SECRET_POST
import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod.PRIVATE_KEY_JWT
import com.nimbusds.oauth2.sdk.auth.JWTAuthentication
import java.lang.String.join
import java.nio.charset.StandardCharsets.UTF_8
import java.util.Base64.getEncoder
import no.nav.security.token.support.client.core.ClientProperties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import com.nimbusds.oauth2.sdk.GrantType.CLIENT_CREDENTIALS
import com.nimbusds.oauth2.sdk.GrantType.JWT_BEARER
import com.nimbusds.oauth2.sdk.GrantType.TOKEN_EXCHANGE
import java.util.function.Function
import org.slf4j.LoggerFactory
import no.nav.security.token.support.client.core.ClientProperties
import no.nav.security.token.support.client.core.OAuth2ClientException
import no.nav.security.token.support.client.core.context.JwtBearerTokenResolver
import org.slf4j.LoggerFactory

class OAuth2AccessTokenService @JvmOverloads constructor(private val tokenResolver : JwtBearerTokenResolver,
private val onBehalfOfTokenClient : OnBehalfOfTokenClient,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package no.nav.security.token.support.client.core.oauth2

import com.nimbusds.oauth2.sdk.GrantType.JWT_BEARER
import java.util.Objects
import java.util.*
import no.nav.security.token.support.client.core.ClientProperties

class OnBehalfOfGrantRequest(clientProperties : ClientProperties, val assertion : String) : AbstractOAuth2GrantRequest(JWT_BEARER, clientProperties) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package no.nav.security.token.support.client.core.oauth2

import com.nimbusds.oauth2.sdk.GrantType
import no.nav.security.token.support.client.core.ClientProperties.TokenExchangeProperties.Companion.SUBJECT_TOKEN_TYPE_VALUE
import no.nav.security.token.support.client.core.OAuth2ClientException
import no.nav.security.token.support.client.core.OAuth2ParameterNames
import no.nav.security.token.support.client.core.OAuth2ParameterNames.AUDIENCE
import no.nav.security.token.support.client.core.OAuth2ParameterNames.RESOURCE
import no.nav.security.token.support.client.core.OAuth2ParameterNames.SCOPE
import no.nav.security.token.support.client.core.OAuth2ParameterNames.SUBJECT_TOKEN
import no.nav.security.token.support.client.core.OAuth2ParameterNames.SUBJECT_TOKEN_TYPE
import no.nav.security.token.support.client.core.http.OAuth2HttpClient
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package no.nav.security.token.support.client.core.oauth2

import com.nimbusds.oauth2.sdk.GrantType.TOKEN_EXCHANGE
import java.util.Objects
import java.util.*
import no.nav.security.token.support.client.core.ClientProperties

class TokenExchangeGrantRequest(clientProperties : ClientProperties, val subjectToken : String) : AbstractOAuth2GrantRequest(TOKEN_EXCHANGE, clientProperties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod.CLIENT_SECRET_JWT
import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod.NONE
import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod.SELF_SIGNED_TLS_CLIENT_AUTH
import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod.TLS_CLIENT_AUTH
import no.nav.security.token.support.client.core.ClientAuthenticationProperties.Companion.builder
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import no.nav.security.token.support.client.core.ClientAuthenticationProperties.Companion.builder

internal class ClientAuthenticationPropertiesTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import com.nimbusds.oauth2.sdk.GrantType.CLIENT_CREDENTIALS
import com.nimbusds.oauth2.sdk.GrantType.JWT_BEARER
import com.nimbusds.oauth2.sdk.GrantType.TOKEN_EXCHANGE
import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod.CLIENT_SECRET_BASIC
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import no.nav.security.token.support.client.core.ClientProperties.ClientPropertiesBuilder
import no.nav.security.token.support.client.core.ClientProperties.TokenExchangeProperties
import no.nav.security.token.support.client.core.TestUtils.jsonResponse
import no.nav.security.token.support.client.core.TestUtils.withMockServer
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows

internal class ClientPropertiesTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ import java.net.URLEncoder
import java.nio.charset.StandardCharsets
import java.time.LocalDateTime.now
import java.time.ZoneId.systemDefault
import java.util.Base64
import java.util.Date
import java.util.Optional
import java.util.UUID
import java.util.*
import no.nav.security.token.support.client.core.ClientAuthenticationProperties.Companion.builder
import no.nav.security.token.support.client.core.ClientProperties.Companion.builder
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import okhttp3.mockwebserver.RecordedRequest
import org.assertj.core.api.Assertions.assertThat
import no.nav.security.token.support.client.core.ClientAuthenticationProperties.Companion.builder
import no.nav.security.token.support.client.core.ClientProperties.Companion.builder

object TestUtils {
@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package no.nav.security.token.support.client.core.auth

import com.nimbusds.jose.JOSEObjectType.*
import com.nimbusds.jose.JWSAlgorithm.*
import com.nimbusds.jose.JOSEObjectType.JWT
import com.nimbusds.jose.JWSAlgorithm.RS256
import com.nimbusds.jose.crypto.RSASSAVerifier
import com.nimbusds.jwt.SignedJWT
import com.nimbusds.oauth2.sdk.GrantType.CLIENT_CREDENTIALS
import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod.PRIVATE_KEY_JWT
import java.net.URI
import java.time.Instant
import java.util.Date
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import java.util.*
import no.nav.security.token.support.client.core.ClientAuthenticationProperties.Companion.builder
import no.nav.security.token.support.client.core.ClientProperties.Companion.builder
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

internal class ClientAssertionTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package no.nav.security.token.support.client.core.http

import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import no.nav.security.token.support.client.core.http.OAuth2HttpHeaders.Companion.builder
import no.nav.security.token.support.client.core.http.OAuth2HttpHeaders.Companion.of
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

internal class OAuth2HttpHeadersTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package no.nav.security.token.support.client.core.jwk
import com.nimbusds.jose.util.Base64URL.encode
import java.security.KeyStore
import java.security.MessageDigest.getInstance
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import no.nav.security.token.support.client.core.jwk.JwkFactory.fromJsonFile
import no.nav.security.token.support.client.core.jwk.JwkFactory.fromKeyStore
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

internal class JwkFactoryTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ package no.nav.security.token.support.client.core.oauth2
import com.nimbusds.oauth2.sdk.GrantType.CLIENT_CREDENTIALS
import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod
import java.net.URI
import okhttp3.mockwebserver.MockWebServer
import okhttp3.mockwebserver.RecordedRequest
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import no.nav.security.token.support.client.core.ClientAuthenticationProperties.Companion.builder
import no.nav.security.token.support.client.core.ClientProperties
import no.nav.security.token.support.client.core.ClientProperties.Companion.builder
Expand All @@ -20,6 +13,13 @@ import no.nav.security.token.support.client.core.TestUtils.decodeBasicAuth
import no.nav.security.token.support.client.core.TestUtils.encodeValue
import no.nav.security.token.support.client.core.TestUtils.jsonResponse
import no.nav.security.token.support.client.core.http.SimpleOAuth2HttpClient
import okhttp3.mockwebserver.MockWebServer
import okhttp3.mockwebserver.RecordedRequest
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows

internal class ClientCredentialsTokenClientTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import com.nimbusds.oauth2.sdk.GrantType.*
import java.time.Instant
import java.time.LocalDateTime.*
import java.time.ZoneId.*
import java.util.Arrays
import java.util.Date
import java.util.UUID
import java.util.*
import no.nav.security.token.support.client.core.ClientProperties.TokenExchangeProperties
import no.nav.security.token.support.client.core.OAuth2CacheFactory.accessTokenResponseCache
import no.nav.security.token.support.client.core.OAuth2ClientException
import no.nav.security.token.support.client.core.TestUtils.clientProperties
import no.nav.security.token.support.client.core.context.JwtBearerTokenResolver
import org.assertj.core.api.Assertions.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand All @@ -22,11 +25,6 @@ import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations.*
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.kotlin.whenever
import no.nav.security.token.support.client.core.ClientProperties.TokenExchangeProperties
import no.nav.security.token.support.client.core.OAuth2CacheFactory.accessTokenResponseCache
import no.nav.security.token.support.client.core.OAuth2ClientException
import no.nav.security.token.support.client.core.TestUtils.clientProperties
import no.nav.security.token.support.client.core.context.JwtBearerTokenResolver

@ExtendWith(MockitoExtension::class)
internal class OAuth2AccessTokenServiceTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ package no.nav.security.token.support.client.core.oauth2
import com.nimbusds.oauth2.sdk.GrantType.JWT_BEARER
import java.net.URLEncoder
import java.nio.charset.StandardCharsets.UTF_8
import okhttp3.mockwebserver.MockWebServer
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatExceptionOfType
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import no.nav.security.token.support.client.core.OAuth2ClientException
import no.nav.security.token.support.client.core.TestUtils.assertPostMethodAndJsonHeaders
import no.nav.security.token.support.client.core.TestUtils.clientProperties
import no.nav.security.token.support.client.core.TestUtils.jsonResponse
import no.nav.security.token.support.client.core.TestUtils.jwt
import no.nav.security.token.support.client.core.http.SimpleOAuth2HttpClient
import okhttp3.mockwebserver.MockWebServer
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows

internal class OnBehalfOfTokenClientTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ package no.nav.security.token.support.client.core.oauth2
import com.nimbusds.oauth2.sdk.GrantType.TOKEN_EXCHANGE
import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod
import java.net.URI
import okhttp3.mockwebserver.MockWebServer
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import no.nav.security.token.support.client.core.ClientAuthenticationProperties.Companion.builder
import no.nav.security.token.support.client.core.ClientProperties
import no.nav.security.token.support.client.core.ClientProperties.Companion.builder
Expand All @@ -24,6 +18,12 @@ import no.nav.security.token.support.client.core.TestUtils.encodeValue
import no.nav.security.token.support.client.core.TestUtils.jsonResponse
import no.nav.security.token.support.client.core.TestUtils.jwt
import no.nav.security.token.support.client.core.http.SimpleOAuth2HttpClient
import okhttp3.mockwebserver.MockWebServer
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows

internal class TokenExchangeClientTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,22 @@ import com.nimbusds.jwt.SignedJWT
import com.nimbusds.oauth2.sdk.GrantType.CLIENT_CREDENTIALS
import com.nimbusds.oauth2.sdk.GrantType.JWT_BEARER
import com.nimbusds.oauth2.sdk.GrantType.TOKEN_EXCHANGE
import io.ktor.client.HttpClient
import io.ktor.client.engine.cio.CIO
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.http.ContentType.Application.Json
import io.ktor.http.HttpStatusCode.Companion.OK
import io.ktor.serialization.jackson.JacksonConverter
import io.ktor.serialization.jackson.jackson
import io.ktor.server.application.Application
import io.ktor.server.application.call
import io.ktor.server.application.install
import io.ktor.server.auth.Authentication
import io.ktor.server.auth.authenticate
import io.ktor.server.auth.principal
import io.ktor.server.response.respond
import io.ktor.server.routing.get
import io.ktor.server.routing.routing
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation as ContentNegotiationClient
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation as ContentNegotiationServer
import io.ktor.serialization.jackson.*
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import no.nav.security.mock.oauth2.MockOAuth2Server
import no.nav.security.token.support.client.core.oauth2.OAuth2AccessTokenResponse
import no.nav.security.token.support.ktor.oauth.ClientConfig
import no.nav.security.token.support.v2.TokenValidationContextPrincipal
import no.nav.security.token.support.v2.tokenValidationSupport
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation as ContentNegotiationClient
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation as ContentNegotiationServer

fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package no.nav.security.token.support.ktor.oauth

import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod
import io.ktor.client.HttpClient
import io.ktor.server.config.ApplicationConfig
import io.ktor.client.*
import io.ktor.server.config.*
import no.nav.security.token.support.client.core.ClientAuthenticationProperties

class ClientConfig(applicationConfig: ApplicationConfig, httpClient: HttpClient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod.CLIENT_SECRET_BAS
import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod.CLIENT_SECRET_POST
import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod.PRIVATE_KEY_JWT
import com.nimbusds.oauth2.sdk.auth.JWTAuthentication.CLIENT_ASSERTION_TYPE
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.basicAuth
import io.ktor.client.request.forms.submitForm
import io.ktor.client.request.get
import io.ktor.client.request.header
import io.ktor.http.Parameters
import io.ktor.http.ParametersBuilder
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.request.*
import io.ktor.client.request.forms.*
import io.ktor.http.*
import java.net.URI
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ import com.nimbusds.jwt.JWTClaimNames.SUBJECT
import io.kotest.assertions.asClue
import io.kotest.assertions.assertSoftly
import io.kotest.matchers.shouldBe
import io.ktor.client.call.body
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.request.get
import io.ktor.client.request.header
import io.ktor.serialization.jackson.jackson
import io.ktor.server.config.MapApplicationConfig
import io.ktor.server.testing.testApplication
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import io.ktor.client.call.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.request.*
import io.ktor.serialization.jackson.*
import io.ktor.server.config.*
import io.ktor.server.testing.*
import no.nav.security.mock.oauth2.MockOAuth2Server
import no.nav.security.mock.oauth2.withMockOAuth2Server
import no.nav.security.token.support.client.core.jwk.JwkFactory
import no.nav.security.token.support.core.JwtTokenConstants.AUTHORIZATION_HEADER
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test

internal class ApplicationTest {

Expand Down
Loading

0 comments on commit 013fda8

Please sign in to comment.