-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanup/AAD_ISSUER_URI-replacement (#3734)
Startet fjerning av AAD_ISSUER_URI i adresse-service, som nå bruker en felles NaisEnvironmentApplicationContextInitializer for å emulere NAIS ved lokal kjøring og i tester.
- Loading branch information
Showing
22 changed files
with
96 additions
and
69 deletions.
There are no files selected for viewing
9 changes: 6 additions & 3 deletions
9
...ce/src/main/java/no/nav/testnav/apps/adresseservice/AdresseServiceApplicationStarter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
package no.nav.testnav.apps.adresseservice; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import no.nav.testnav.libs.servletcore.config.NaisEnvironmentApplicationContextInitializer; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
|
||
@SpringBootApplication | ||
public class AdresseServiceApplicationStarter { | ||
|
||
public static void main(String[] args) { | ||
|
||
SpringApplication.run(AdresseServiceApplicationStarter.class, args); | ||
new SpringApplicationBuilder(AdresseServiceApplicationStarter.class) | ||
.initializers(new NaisEnvironmentApplicationContextInitializer()) | ||
.run(args); | ||
} | ||
|
||
} |
2 changes: 0 additions & 2 deletions
2
apps/adresse-service/src/main/resources/application-local.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...esse-service/src/test/java/no/nav/testnav/apps/adresseservice/ApplicationContextTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +0,0 @@ | ||
TOKEN_X_ISSUER: dummy | ||
|
||
spring: | ||
cloud: | ||
gcp: | ||
secretmanager: | ||
enabled: false | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
.../no/nav/testnav/libs/servletcore/config/NaisEnvironmentApplicationContextInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package no.nav.testnav.libs.servletcore.config; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.ApplicationContextInitializer; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.lang.NonNull; | ||
|
||
import java.util.Map; | ||
import java.util.stream.Stream; | ||
|
||
@Slf4j | ||
public class NaisEnvironmentApplicationContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { | ||
|
||
private static final String DUMMY = "dummy"; | ||
|
||
@Override | ||
public void initialize(@NonNull ConfigurableApplicationContext context) { | ||
|
||
var environment = context.getEnvironment(); | ||
Stream | ||
.of(environment.getActiveProfiles()) | ||
.forEach(profile -> { | ||
switch (profile) { | ||
case "local" -> configureForLocalProfile(environment.getSystemProperties()); | ||
case "test" -> configureForTestProfile(environment.getSystemProperties()); | ||
default -> { /* Do nothing. */ } | ||
} | ||
}); | ||
|
||
} | ||
|
||
private static void configureForLocalProfile(Map<String, Object> properties) { | ||
|
||
log.info("Configuring environment for local profile using Secret Manager"); | ||
|
||
// Emulating NAIS provided environment variables. | ||
properties.putIfAbsent("AZURE_APP_CLIENT_ID", "${sm\\://azure-app-client-id}"); | ||
properties.putIfAbsent("AZURE_APP_CLIENT_SECRET", "${sm\\://azure-app-client-secret}"); | ||
properties.putIfAbsent("AZURE_OPENID_CONFIG_ISSUER", "${sm\\://azure-openid-config-issuer}"); | ||
properties.putIfAbsent("AZURE_OPENID_CONFIG_TOKEN_ENDPOINT", "${sm\\://azure-openid-config-token-endpoint}"); | ||
properties.putIfAbsent("TOKEN_X_ISSUER", "${sm\\://token-x-issuer}"); | ||
properties.putIfAbsent("TOKEN_X_JWKS_URI", "${sm\\://token-x-jwks-uri}"); | ||
|
||
} | ||
|
||
private static void configureForTestProfile(Map<String, Object> properties) { | ||
|
||
log.info("Configuring environment for test profile using dummy values"); | ||
|
||
// Disabling Secret Manager (not available when running builds on GitHub). | ||
properties.putIfAbsent("spring.cloud.gcp.secretmanager.enabled", "false"); | ||
|
||
// Setting dummy placeholders. | ||
properties.putIfAbsent("AZURE_OPENID_CONFIG_ISSUER", DUMMY); | ||
properties.putIfAbsent("AZURE_OPENID_CONFIG_TOKEN_ENDPOINT", DUMMY); | ||
properties.putIfAbsent("TOKEN_X_ISSUER", DUMMY); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.