From 6e21ad5dc6d9b79a8ac577d4247db2d5372dafa0 Mon Sep 17 00:00:00 2001 From: Cato Olsen Date: Mon, 16 Dec 2024 12:01:28 +0100 Subject: [PATCH] Renames subclasses of ClientCredential for consistency in relation to naming of configuration properties. --- .../profil/service/AzureAdTokenService.java | 6 ++-- .../exchange/azuread/AzureAdTokenService.java | 6 ++-- .../azuread/NavAzureAdTokenService.java | 8 ++--- .../exchange/AzureAdTokenExchange.java | 4 +-- .../domain/azuread/AzureClientCredential.java | 9 ++++++ .../azuread/AzureNavClientCredential.java | 12 +++++-- .../AzureNavProxyClientCredential.java | 17 ---------- .../azuread/ClientCredentialConfig.java | 32 +++++++++---------- .../exchange/AzureAdTokenService.java | 4 +-- .../exchange/AzureAdTokenService.java | 4 +-- 10 files changed, 51 insertions(+), 51 deletions(-) create mode 100644 libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/AzureClientCredential.java delete mode 100644 libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/AzureNavProxyClientCredential.java diff --git a/apps/profil-api/src/main/java/no/nav/registre/testnorge/profil/service/AzureAdTokenService.java b/apps/profil-api/src/main/java/no/nav/registre/testnorge/profil/service/AzureAdTokenService.java index 5333a97d46a..f262be55d05 100644 --- a/apps/profil-api/src/main/java/no/nav/registre/testnorge/profil/service/AzureAdTokenService.java +++ b/apps/profil-api/src/main/java/no/nav/registre/testnorge/profil/service/AzureAdTokenService.java @@ -1,7 +1,7 @@ package no.nav.registre.testnorge.profil.service; import lombok.extern.slf4j.Slf4j; -import no.nav.testnav.libs.securitycore.domain.azuread.AzureNavClientCredential; +import no.nav.testnav.libs.securitycore.domain.azuread.AzureClientCredential; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; @@ -22,13 +22,13 @@ @Service public class AzureAdTokenService { private final WebClient webClient; - private final AzureNavClientCredential clientCredential; + private final AzureClientCredential clientCredential; private final GetAuthenticatedToken getAuthenticatedToken; public AzureAdTokenService( @Value("${http.proxy:#{null}}") String proxyHost, @Value("${AAD_ISSUER_URI}") String issuerUrl, - AzureNavClientCredential clientCredential, + AzureClientCredential clientCredential, GetAuthenticatedToken getAuthenticatedToken ) { log.info("Init custom AzureAd token exchange."); diff --git a/libs/reactive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/exchange/azuread/AzureAdTokenService.java b/libs/reactive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/exchange/azuread/AzureAdTokenService.java index e65534dcfde..25375660305 100644 --- a/libs/reactive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/exchange/azuread/AzureAdTokenService.java +++ b/libs/reactive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/exchange/azuread/AzureAdTokenService.java @@ -9,7 +9,7 @@ import no.nav.testnav.libs.securitycore.domain.ResourceServerType; import no.nav.testnav.libs.securitycore.domain.ServerProperties; import no.nav.testnav.libs.securitycore.domain.Token; -import no.nav.testnav.libs.securitycore.domain.azuread.AzureNavClientCredential; +import no.nav.testnav.libs.securitycore.domain.azuread.AzureClientCredential; import no.nav.testnav.libs.securitycore.domain.azuread.ClientCredential; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -39,7 +39,7 @@ public class AzureAdTokenService implements TokenService { public AzureAdTokenService( @Value("${http.proxy:#{null}}") String proxyHost, @Value("${AAD_ISSUER_URI}") String issuerUrl, - AzureNavClientCredential azureNavClientCredential, + AzureClientCredential azureClientCredential, GetAuthenticatedToken getAuthenticatedToken ) { log.info("Init AzureAd token exchange."); @@ -63,7 +63,7 @@ public AzureAdTokenService( } this.webClient = builder.build(); this.getAuthenticatedToken = getAuthenticatedToken; - this.clientCredential = azureNavClientCredential; + this.clientCredential = azureClientCredential; } @Override diff --git a/libs/reactive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/exchange/azuread/NavAzureAdTokenService.java b/libs/reactive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/exchange/azuread/NavAzureAdTokenService.java index ae530208416..9a58bcd576d 100644 --- a/libs/reactive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/exchange/azuread/NavAzureAdTokenService.java +++ b/libs/reactive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/exchange/azuread/NavAzureAdTokenService.java @@ -1,7 +1,7 @@ package no.nav.testnav.libs.reactivesecurity.exchange.azuread; import lombok.extern.slf4j.Slf4j; -import no.nav.testnav.libs.securitycore.domain.azuread.AzureNavProxyClientCredential; +import no.nav.testnav.libs.securitycore.domain.azuread.AzureNavClientCredential; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; @@ -29,13 +29,13 @@ public class NavAzureAdTokenService implements ExchangeToken { public NavAzureAdTokenService( @Value("${http.proxy:#{null}}") String proxyHost, - AzureNavProxyClientCredential azureNavProxyClientCredential + AzureNavClientCredential azureNavClientCredential ) { - this.clientCredential = azureNavProxyClientCredential; + this.clientCredential = azureNavClientCredential; log.info("Init AzureAd Nav token service."); WebClient.Builder builder = WebClient .builder() - .baseUrl(azureNavProxyClientCredential.getTokenEndpoint()) + .baseUrl(azureNavClientCredential.getTokenEndpoint()) .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE); if (proxyHost != null) { diff --git a/libs/reactive-session-security/src/main/java/no/nav/testnav/libs/reactivesessionsecurity/exchange/AzureAdTokenExchange.java b/libs/reactive-session-security/src/main/java/no/nav/testnav/libs/reactivesessionsecurity/exchange/AzureAdTokenExchange.java index 7441dd04795..e3d73c62bd4 100644 --- a/libs/reactive-session-security/src/main/java/no/nav/testnav/libs/reactivesessionsecurity/exchange/AzureAdTokenExchange.java +++ b/libs/reactive-session-security/src/main/java/no/nav/testnav/libs/reactivesessionsecurity/exchange/AzureAdTokenExchange.java @@ -5,7 +5,7 @@ import no.nav.testnav.libs.securitycore.command.azuread.OnBehalfOfExchangeCommand; import no.nav.testnav.libs.securitycore.domain.AccessToken; import no.nav.testnav.libs.securitycore.domain.ServerProperties; -import no.nav.testnav.libs.securitycore.domain.azuread.AzureNavClientCredential; +import no.nav.testnav.libs.securitycore.domain.azuread.AzureClientCredential; import no.nav.testnav.libs.securitycore.domain.azuread.ClientCredential; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; @@ -25,7 +25,7 @@ public class AzureAdTokenExchange implements ExchangeToken { public AzureAdTokenExchange( @Value("${AAD_ISSUER_URI}") String issuerUrl, TokenResolver tokenResolver, - AzureNavClientCredential clientCredential) { + AzureClientCredential clientCredential) { this.webClient = WebClient .builder() diff --git a/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/AzureClientCredential.java b/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/AzureClientCredential.java new file mode 100644 index 00000000000..b21ef22212b --- /dev/null +++ b/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/AzureClientCredential.java @@ -0,0 +1,9 @@ +package no.nav.testnav.libs.securitycore.domain.azuread; + +public class AzureClientCredential extends ClientCredential { + + AzureClientCredential(String clientId, String clientSecret) { + super(clientId, clientSecret); + } + +} \ No newline at end of file diff --git a/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/AzureNavClientCredential.java b/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/AzureNavClientCredential.java index b6f1f00f38d..249d3c5615d 100644 --- a/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/AzureNavClientCredential.java +++ b/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/AzureNavClientCredential.java @@ -1,9 +1,17 @@ package no.nav.testnav.libs.securitycore.domain.azuread; +import lombok.EqualsAndHashCode; +import lombok.Getter; + +@Getter +@EqualsAndHashCode(callSuper = false) public class AzureNavClientCredential extends ClientCredential { - AzureNavClientCredential(String clientId, String clientSecret) { + private final String tokenEndpoint; + + AzureNavClientCredential(String tokenEndpoint, String clientId, String clientSecret) { super(clientId, clientSecret); + this.tokenEndpoint = tokenEndpoint; } -} \ No newline at end of file +} diff --git a/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/AzureNavProxyClientCredential.java b/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/AzureNavProxyClientCredential.java deleted file mode 100644 index a954209f916..00000000000 --- a/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/AzureNavProxyClientCredential.java +++ /dev/null @@ -1,17 +0,0 @@ -package no.nav.testnav.libs.securitycore.domain.azuread; - -import lombok.EqualsAndHashCode; -import lombok.Getter; - -@Getter -@EqualsAndHashCode(callSuper = false) -public class AzureNavProxyClientCredential extends ClientCredential { - - private final String tokenEndpoint; - - AzureNavProxyClientCredential(String tokenEndpoint, String clientId, String clientSecret) { - super(clientId, clientSecret); - this.tokenEndpoint = tokenEndpoint; - } - -} diff --git a/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/ClientCredentialConfig.java b/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/ClientCredentialConfig.java index 47b6c3be78e..5ba8852f8dc 100644 --- a/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/ClientCredentialConfig.java +++ b/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/ClientCredentialConfig.java @@ -34,20 +34,20 @@ public class ClientCredentialConfig { @Value("${AZURE_NAV_APP_CLIENT_SECRET:#{null}}") private String azureNavClientSecret; - @Bean("azureNavClientCredential") + @Bean("azureClientCredential") @Profile("!test") - @ConditionalOnMissingBean(AzureNavClientCredential.class) - public AzureNavClientCredential azureNavClientCredential() { + @ConditionalOnMissingBean(AzureClientCredential.class) + public AzureClientCredential azureNavClientCredential() { Assert.hasLength(azureClientId, AZURE_MISSING); Assert.hasLength(azureClientSecret, AZURE_MISSING); - return new AzureNavClientCredential(azureClientId, azureClientSecret); + return new AzureClientCredential(azureClientId, azureClientSecret); } - @Bean("azureNavClientCredential") + @Bean("azureClientCredential") @Profile("test") - @ConditionalOnMissingBean(AzureNavClientCredential.class) - public AzureNavClientCredential azureNavClientCredentialTest() { - return new AzureNavClientCredential(TEST_CLIENT_ID, TEST_CLIENT_SECRET); + @ConditionalOnMissingBean(AzureClientCredential.class) + public AzureClientCredential azureNavClientCredentialTest() { + return new AzureClientCredential(TEST_CLIENT_ID, TEST_CLIENT_SECRET); } @Bean("azureTrygdeetatenClientCredential") @@ -69,23 +69,23 @@ public AzureTrygdeetatenClientCredential azureTrygdeetatenClientCredentialTest() return new AzureTrygdeetatenClientCredential(TEST_TOKEN_ENDPOINT, TEST_CLIENT_ID, TEST_CLIENT_SECRET); } - @Bean("azureNavProxyClientCredential") + @Bean("azureNavClientCredential") @Profile("!test") - @ConditionalOnMissingBean(AzureNavProxyClientCredential.class) + @ConditionalOnMissingBean(AzureNavClientCredential.class) @ConditionalOnProperty("AZURE_NAV_OPENID_CONFIG_TOKEN_ENDPOINT") - public AzureNavProxyClientCredential azureNavProxyClientCredential( + public AzureNavClientCredential azureNavProxyClientCredential( @Value("AZURE_NAV_OPENID_CONFIG_TOKEN_ENDPOINT") String azureNavTokenEndpoint ) { Assert.hasLength(azureNavClientId, PROXY_MISSING); Assert.hasLength(azureNavClientSecret, PROXY_MISSING); - return new AzureNavProxyClientCredential(azureNavTokenEndpoint, azureNavClientId, azureNavClientSecret); + return new AzureNavClientCredential(azureNavTokenEndpoint, azureNavClientId, azureNavClientSecret); } - @Bean("azureNavProxyClientCredential") + @Bean("azureNavClientCredential") @Profile("test") - @ConditionalOnMissingBean(AzureNavProxyClientCredential.class) - public AzureNavProxyClientCredential azureNavProxyClientCredentialTest() { - return new AzureNavProxyClientCredential(TEST_TOKEN_ENDPOINT, TEST_CLIENT_ID, TEST_CLIENT_SECRET); + @ConditionalOnMissingBean(AzureNavClientCredential.class) + public AzureNavClientCredential azureNavProxyClientCredentialTest() { + return new AzureNavClientCredential(TEST_TOKEN_ENDPOINT, TEST_CLIENT_ID, TEST_CLIENT_SECRET); } } diff --git a/libs/servlet-insecure-security/src/main/java/no/nav/testnav/libs/standalone/servletsecurity/exchange/AzureAdTokenService.java b/libs/servlet-insecure-security/src/main/java/no/nav/testnav/libs/standalone/servletsecurity/exchange/AzureAdTokenService.java index 00696ba6667..ed6e1851df4 100644 --- a/libs/servlet-insecure-security/src/main/java/no/nav/testnav/libs/standalone/servletsecurity/exchange/AzureAdTokenService.java +++ b/libs/servlet-insecure-security/src/main/java/no/nav/testnav/libs/standalone/servletsecurity/exchange/AzureAdTokenService.java @@ -4,7 +4,7 @@ import no.nav.testnav.libs.securitycore.command.azuread.ClientCredentialExchangeCommand; import no.nav.testnav.libs.securitycore.domain.AccessToken; import no.nav.testnav.libs.securitycore.domain.ServerProperties; -import no.nav.testnav.libs.securitycore.domain.azuread.AzureNavClientCredential; +import no.nav.testnav.libs.securitycore.domain.azuread.AzureClientCredential; import no.nav.testnav.libs.securitycore.domain.azuread.ClientCredential; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; @@ -28,7 +28,7 @@ public class AzureAdTokenService implements ExchangeToken { public AzureAdTokenService( @Value("${http.proxy:#{null}}") String proxyHost, @Value("${AAD_ISSUER_URI}") String issuerUrl, - AzureNavClientCredential clientCredential + AzureClientCredential clientCredential ) { log.info("Init AzureAd token exchange."); WebClient.Builder builder = WebClient diff --git a/libs/servlet-security/src/main/java/no/nav/testnav/libs/servletsecurity/exchange/AzureAdTokenService.java b/libs/servlet-security/src/main/java/no/nav/testnav/libs/servletsecurity/exchange/AzureAdTokenService.java index f6323dcb5fc..27b304895b0 100644 --- a/libs/servlet-security/src/main/java/no/nav/testnav/libs/servletsecurity/exchange/AzureAdTokenService.java +++ b/libs/servlet-security/src/main/java/no/nav/testnav/libs/servletsecurity/exchange/AzureAdTokenService.java @@ -7,7 +7,7 @@ import no.nav.testnav.libs.securitycore.domain.ResourceServerType; import no.nav.testnav.libs.securitycore.domain.ServerProperties; import no.nav.testnav.libs.securitycore.domain.Token; -import no.nav.testnav.libs.securitycore.domain.azuread.AzureNavClientCredential; +import no.nav.testnav.libs.securitycore.domain.azuread.AzureClientCredential; import no.nav.testnav.libs.securitycore.domain.azuread.ClientCredential; import no.nav.testnav.libs.servletsecurity.action.GetAuthenticatedToken; import org.springframework.beans.factory.annotation.Value; @@ -34,7 +34,7 @@ public class AzureAdTokenService implements TokenService { public AzureAdTokenService( @Value("${http.proxy:#{null}}") String proxyHost, @Value("${AAD_ISSUER_URI}") String issuerUrl, - AzureNavClientCredential clientCredential, + AzureClientCredential clientCredential, GetAuthenticatedToken getAuthenticatedToken ) { log.info("Init AzureAd token exchange.");