Skip to content

Commit

Permalink
mulig fix for azure security client for soko kontoregister
Browse files Browse the repository at this point in the history
  • Loading branch information
d142796 committed May 29, 2024
1 parent 50407ed commit f9d2dd8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package no.nav.arbeidsgiver.tiltakrefusjon
import no.nav.security.token.support.client.core.ClientProperties
import no.nav.security.token.support.client.core.oauth2.OAuth2AccessTokenService
import no.nav.security.token.support.client.spring.ClientConfigurationProperties
import no.nav.security.token.support.client.spring.oauth2.ClientConfigurationPropertiesMatcher
import no.nav.security.token.support.client.spring.oauth2.EnableOAuth2Client
import no.nav.security.token.support.client.spring.oauth2.OAuth2ClientRequestInterceptor
import org.springframework.boot.web.client.RestTemplateBuilder
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
Expand All @@ -12,6 +14,8 @@ import org.springframework.http.HttpRequest
import org.springframework.http.client.ClientHttpRequestExecution
import org.springframework.http.client.ClientHttpRequestInterceptor
import org.springframework.web.client.RestTemplate
import java.net.URI
import java.util.*

@EnableOAuth2Client(cacheEnabled = true)
@Configuration
Expand All @@ -34,9 +38,6 @@ class SecurityClientConfiguration(
@Bean
fun anonymProxyRestTemplate() = restTemplateForRegistration("aad-anonym")

@Bean
fun sokosRestTemplate() = restTemplateForRegistration("sokos-kontoregister")


private fun restTemplateForRegistration(registration: String): RestTemplate {
val clientProperties = clientConfigurationProperties.registration[registration]
Expand All @@ -46,6 +47,7 @@ class SecurityClientConfiguration(
.build()
}


private fun bearerTokenInterceptor(
clientProperties: ClientProperties,
oAuth2AccessTokenService: OAuth2AccessTokenService
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package no.nav.arbeidsgiver.tiltakrefusjon

import no.nav.security.token.support.client.core.ClientProperties
import no.nav.security.token.support.client.core.oauth2.OAuth2AccessTokenService
import no.nav.security.token.support.client.spring.ClientConfigurationProperties
import no.nav.security.token.support.client.spring.oauth2.ClientConfigurationPropertiesMatcher
import no.nav.security.token.support.client.spring.oauth2.EnableOAuth2Client
import no.nav.security.token.support.client.spring.oauth2.OAuth2ClientRequestInterceptor
import org.springframework.boot.web.client.RestTemplateBuilder
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Profile
import org.springframework.web.client.RestTemplate
import java.net.URI
import java.util.*

@EnableOAuth2Client(cacheEnabled = true)
@Configuration
@Profile("dev-gcp", "prod-gcp")
class SecurityClientConfigurationSokoKontoregister{

@Bean("sokosRestTemplate")
fun azureRestTemplate(
restTemplateBuilder: RestTemplateBuilder,
oAuth2ClientRequestInterceptor: OAuth2ClientRequestInterceptor?
): RestTemplate {
return restTemplateBuilder
.interceptors(oAuth2ClientRequestInterceptor)
.build()
}

@Bean
fun oAuth2ClientRequestInterceptor(
properties: ClientConfigurationProperties?,
service: OAuth2AccessTokenService?,
matcher: ClientConfigurationPropertiesMatcher?
): OAuth2ClientRequestInterceptor {
return OAuth2ClientRequestInterceptor(properties!!, service!!, matcher!!)
}

@Bean
fun clientConfigurationPropertiesMatcher(): ClientConfigurationPropertiesMatcher {
return object : ClientConfigurationPropertiesMatcher {
override fun findProperties(
properties: ClientConfigurationProperties,
s: String
): ClientProperties? {
return properties.registration["sokos-kontoregister"]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class LokalSecurityClientConfiguration(val restTemplateBuilder: RestTemplateBuil
@Bean
fun anonymProxyRestTemplate() = restTemplateBuilder.build()

@Bean
@Bean("sokosRestTemplate")
fun sokosRestTemplate() = restTemplateBuilder.build()
}

0 comments on commit f9d2dd8

Please sign in to comment.