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 44fbd661718..f3c0cbaeafd 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 @@ -6,9 +6,15 @@ @Configuration public class AzureNavClientCredential extends ClientCredential { + /* + TODO: A better solution, for another day: + 1. No longer import AzureNavClientCredential - generify this, or use factories. It cannot be a @Configuration for its own @Bean. + 2. Create two beans, one for @Profile("test"), one on @ConditionalOnMissingBean. + 3. Check if we really need subclasses for this, or if ClientCredential will suffice. + */ public AzureNavClientCredential( - @Value("${AZURE_APP_CLIENT_ID}") String clientId, - @Value("${AZURE_APP_CLIENT_SECRET}") String clientSecret + @Value("#{systemProperties['spring.profiles.active'] == 'test' ? 'test-client-id' : '${AZURE_APP_CLIENT_ID:#{null}}'}") String clientId, + @Value("#{systemProperties['spring.profiles.active'] == 'test' ? 'test-client-secret' : '${AZURE_APP_CLIENT_SECRET:#{null}}'}") String clientSecret ) { super(clientId, clientSecret); } diff --git a/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/ClientCredential.java b/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/ClientCredential.java index c1d621f8bbc..0482462dc53 100644 --- a/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/ClientCredential.java +++ b/libs/security-core/src/main/java/no/nav/testnav/libs/securitycore/domain/azuread/ClientCredential.java @@ -1,12 +1,24 @@ package no.nav.testnav.libs.securitycore.domain.azuread; -import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import org.springframework.util.Assert; -@Data +@EqualsAndHashCode +@Getter public class ClientCredential { + private final String clientId; private final String clientSecret; + public ClientCredential(String clientId, String clientSecret) { + Assert.notNull(clientId, "AZURE_NAV_APP_CLIENT_ID must be set"); + Assert.notNull(clientSecret, "AZURE_NAV_APP_CLIENT_SECRET must be set"); + + this.clientId = clientId; + this.clientSecret = clientSecret; + } + @Override public final String toString() { return "ClientCredential{" +