Skip to content

Commit

Permalink
- Overriding client credentials in Spring profile "test".
Browse files Browse the repository at this point in the history
- Client credentials are now manually asserted to be non-null.
  • Loading branch information
rfc3092 committed Dec 11, 2024
1 parent 018a432 commit 99f099d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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{" +
Expand Down

0 comments on commit 99f099d

Please sign in to comment.