diff --git a/libs/servlet-insecure-security/src/main/java/no/nav/testnav/libs/standalone/servletsecurity/config/InsecureJwtServerToServerConfiguration.java b/libs/servlet-insecure-security/src/main/java/no/nav/testnav/libs/standalone/servletsecurity/config/InsecureJwtServerToServerConfiguration.java index 7f12945ced7..633135c22cf 100644 --- a/libs/servlet-insecure-security/src/main/java/no/nav/testnav/libs/standalone/servletsecurity/config/InsecureJwtServerToServerConfiguration.java +++ b/libs/servlet-insecure-security/src/main/java/no/nav/testnav/libs/standalone/servletsecurity/config/InsecureJwtServerToServerConfiguration.java @@ -7,9 +7,7 @@ import no.nav.testnav.libs.standalone.servletsecurity.properties.ResourceServerProperties; import no.nav.testnav.libs.standalone.servletsecurity.properties.TokenXResourceServerProperties; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.*; import org.springframework.security.oauth2.jwt.JwtDecoder; import java.util.List; @@ -24,8 +22,17 @@ public class InsecureJwtServerToServerConfiguration { @Bean + @Profile("!test") @ConditionalOnMissingBean - public JwtDecoder jwtDecoder(List properties) { + JwtDecoder jwtDecoder(List properties) { return new MultipleIssuersJwtDecoder(properties); } + + @Bean + @Profile("test") + @ConditionalOnMissingBean + JwtDecoder jwtDecoderForTesting() { + return token -> null; + } + } \ No newline at end of file diff --git a/libs/servlet-security/src/main/java/no/nav/testnav/libs/servletsecurity/config/SecureOAuth2ServerToServerConfiguration.java b/libs/servlet-security/src/main/java/no/nav/testnav/libs/servletsecurity/config/SecureOAuth2ServerToServerConfiguration.java index 9a4933da79d..815ecd2be7e 100644 --- a/libs/servlet-security/src/main/java/no/nav/testnav/libs/servletsecurity/config/SecureOAuth2ServerToServerConfiguration.java +++ b/libs/servlet-security/src/main/java/no/nav/testnav/libs/servletsecurity/config/SecureOAuth2ServerToServerConfiguration.java @@ -1,11 +1,7 @@ package no.nav.testnav.libs.servletsecurity.config; import no.nav.testnav.libs.securitycore.domain.tokenx.TokenXProperties; -import no.nav.testnav.libs.servletsecurity.action.GetAuthenticatedId; -import no.nav.testnav.libs.servletsecurity.action.GetAuthenticatedResourceServerType; -import no.nav.testnav.libs.servletsecurity.action.GetAuthenticatedToken; -import no.nav.testnav.libs.servletsecurity.action.GetUserInfo; -import no.nav.testnav.libs.servletsecurity.action.GetUserJwt; +import no.nav.testnav.libs.servletsecurity.action.*; import no.nav.testnav.libs.servletsecurity.decoder.MultipleIssuersJwtDecoder; import no.nav.testnav.libs.servletsecurity.exchange.AzureAdTokenService; import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange; @@ -14,9 +10,7 @@ import no.nav.testnav.libs.servletsecurity.properties.ResourceServerProperties; import no.nav.testnav.libs.servletsecurity.properties.TokenXResourceServerProperties; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.*; import org.springframework.security.oauth2.jwt.JwtDecoder; import java.util.List; @@ -39,9 +33,17 @@ public class SecureOAuth2ServerToServerConfiguration { // TODO: There's also one in no.nav.testnav.libs.standalone.servletsecurity.config.SecureOAuth2ServerToServerConfiguration. testnav-ident-pool (and possibly others) includes both libraries. This should be fixed. @Bean + @Profile("!test") @ConditionalOnMissingBean - public JwtDecoder jwtDecoder(List properties) { + JwtDecoder jwtDecoder(List properties) { return new MultipleIssuersJwtDecoder(properties); } + @Bean + @Profile("test") + @ConditionalOnMissingBean + JwtDecoder jwtDecoderForTesting() { + return token -> null; + } + } \ No newline at end of file