Skip to content

Commit

Permalink
log stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
janolaveide committed Jan 27, 2025
1 parent 1c00141 commit 1ddbed4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.net.URI
import java.time.Instant.now
import java.util.*
import no.nav.security.token.support.client.core.ClientAuthenticationProperties
import kotlin.DeprecationLevel.WARNING
import kotlin.DeprecationLevel.ERROR

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 All @@ -32,7 +32,7 @@ class ClientAssertion(private val tokenEndpointUrl : URI, private val clientId :
.build()).serialize()
}

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

private fun createSignedJWT(rsaJwk : RSAKey, claimsSet : JWTClaimsSet) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package no.nav.security.token.support.client.spring.oauth2

import no.nav.security.token.support.client.core.oauth2.OAuth2AccessTokenService
import no.nav.security.token.support.client.spring.ClientConfigurationProperties
import org.slf4j.LoggerFactory
import org.springframework.http.HttpRequest
import org.springframework.http.client.ClientHttpRequestExecution
import org.springframework.http.client.ClientHttpRequestInterceptor
Expand All @@ -22,13 +23,21 @@ import org.springframework.http.client.ClientHttpResponse
class OAuth2ClientRequestInterceptor(private val properties: ClientConfigurationProperties,
private val service: OAuth2AccessTokenService,
private val matcher: ClientConfigurationPropertiesMatcher = object : ClientConfigurationPropertiesMatcher {}) : ClientHttpRequestInterceptor {

private val log = LoggerFactory.getLogger(OAuth2ClientRequestInterceptor::class.java)


override fun intercept(req: HttpRequest, body: ByteArray, execution: ClientHttpRequestExecution): ClientHttpResponse {
log.trace("Intercepting request to {}", req.uri)
matcher.findProperties(properties, req.uri)?.let {
service.getAccessToken(it).access_token?.let { token -> req.headers.setBearerAuth(token) }
log.trace("Found properties {} for uri {}", it, req.uri)
service.getAccessToken(it).access_token?.let {
token -> req.headers.setBearerAuth(token)
log.trace("Finished setting Authorization header with accesstoken OK")
}
}
return execution.execute(req, body)
}

override fun toString() = "${javaClass.simpleName} [properties=$properties, service=$service, matcher=$matcher]"

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ open class JwtTokenAnnotationHandler(private val tokenValidationContextHolder :
}

private fun handleRequiredIssuers(a: RequiredIssuers): Boolean {
val hasToken = a.value.any { sub ->
val jwtToken = getJwtToken(sub.issuer, tokenValidationContextHolder)
jwtToken.isPresent && handleProtectedWithClaimsAnnotation(sub, jwtToken.get())
val hasToken = a.value.any {
getJwtToken(it.issuer, tokenValidationContextHolder).run {
isPresent && handleProtectedWithClaimsAnnotation(it, get())
}
}
return when {
hasToken -> true
Expand Down
4 changes: 0 additions & 4 deletions token-validation-filter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ spring.autoconfigure.exclude: org.springframework.boot.autoconfigure.web.servlet
no.nav.security.jwt:
issuers: protected
issuer.protected:
discoveryurl: http://metadata
discovery-url: http://metadata
accepted_audience: aud-localhost
debug: false
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,7 @@ class ApplicationTest {
put("no.nav.security.jwt.issuers.0.issuer_name", acceptedIssuer)
put(
"no.nav.security.jwt.issuers.0.discoveryurl",
server.wellKnownUrl(ISSUER_ID).toString()
)//server.baseUrl() + "/.well-known/openid-configuration")
server.wellKnownUrl(ISSUER_ID).toString())
put("no.nav.security.jwt.issuers.0.accepted_audience", acceptedAudience)
}
}
Expand Down

0 comments on commit 1ddbed4

Please sign in to comment.