Skip to content

Commit

Permalink
E - Oppdaterer tokenSupportVersion til 4.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
dskarpas committed Jan 12, 2024
1 parent 480a3c8 commit d4fa974
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
springKafkaVersion = '3.1.1'
cxfVersion = '3.4.2'
jacksonModuleKotlinVersion = '2.16.1'
tokenSupportVersion = '3.2.0'
tokenSupportVersion = '4.0.5'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PDLConfiguration(
override fun callBack(): PdlToken {
val clientProperties = Optional.ofNullable(clientConfigurationProperties.registration["pdl-credentials"]).orElseThrow { RuntimeException("could not find oauth2 client config for pdl-credentials") }
val response = oAuth2AccessTokenService.getAccessToken(clientProperties)
val token = response.accessToken
val token = response?.accessToken!!
return PdlTokenImp(token)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import org.springframework.http.client.ClientHttpRequestInterceptor
import org.springframework.http.client.SimpleClientHttpRequestFactory
import org.springframework.web.client.DefaultResponseErrorHandler
import org.springframework.web.client.RestTemplate
import java.net.URLDecoder
import java.nio.charset.StandardCharsets


@Configuration
Expand Down Expand Up @@ -109,7 +111,7 @@ class RestTemplateConfig(
private fun onBehalfOfBearerTokenInterceptor(clientId: String): ClientHttpRequestInterceptor {
logger.info("init onBehalfOfBearerTokenInterceptor: $clientId")
return ClientHttpRequestInterceptor { request: HttpRequest, body: ByteArray?, execution: ClientHttpRequestExecution ->
val navidentTokenFromUI = getToken(tokenValidationContextHolder).tokenAsString
val navidentTokenFromUI = URLDecoder.decode(getToken(tokenValidationContextHolder)?.encodedToken, StandardCharsets.UTF_8)

logger.info("NAVIdent: ${getClaims(tokenValidationContextHolder).get("NAVident")?.toString()}")

Expand All @@ -136,7 +138,7 @@ class RestTemplateConfig(
): ClientHttpRequestInterceptor {
return ClientHttpRequestInterceptor { request: HttpRequest, body: ByteArray?, execution: ClientHttpRequestExecution ->
val response = oAuth2AccessTokenService.getAccessToken(clientProperties)
request.headers.setBearerAuth(response.accessToken)
request.headers.setBearerAuth(response?.accessToken!!)
/*
val tokenChunks = response.accessToken.split(".")
val tokenBody = tokenChunks[1]
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/no/nav/eessi/pensjon/config/TokenUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import java.util.*


fun getClaims(tokenValidationContextHolder: TokenValidationContextHolder): JwtTokenClaims {
val context = tokenValidationContextHolder.tokenValidationContext
val context = tokenValidationContextHolder.getTokenValidationContext()
if(context.issuers.isEmpty())
throw RuntimeException("No issuer found in context")

Expand All @@ -25,8 +25,8 @@ import java.util.*

}

fun getToken(tokenValidationContextHolder: TokenValidationContextHolder): JwtToken {
val context = tokenValidationContextHolder.tokenValidationContext
fun getToken(tokenValidationContextHolder: TokenValidationContextHolder): JwtToken? {
val context = tokenValidationContextHolder.getTokenValidationContext()
if(context.issuers.isEmpty())
throw RuntimeException("No issuer found in context")
val issuer = context.issuers.first()
Expand Down

0 comments on commit d4fa974

Please sign in to comment.