diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/config/WebSecurityTestConfig.kt b/search-service/src/test/kotlin/com/egm/stellio/search/config/WebSecurityTestConfig.kt deleted file mode 100644 index 3049b3a95..000000000 --- a/search-service/src/test/kotlin/com/egm/stellio/search/config/WebSecurityTestConfig.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.egm.stellio.search.config - -import com.egm.stellio.shared.config.ApplicationProperties -import org.springframework.boot.test.context.TestConfiguration -import org.springframework.context.annotation.Bean -import org.springframework.security.oauth2.jwt.ReactiveJwtDecoder -import org.springframework.security.oauth2.jwt.ReactiveJwtDecoders - -@TestConfiguration -class WebSecurityTestConfig( - private val applicationProperties: ApplicationProperties -) { - - @Bean - fun jwtDecoder(): ReactiveJwtDecoder = - ReactiveJwtDecoders.fromOidcIssuerLocation(applicationProperties.tenants[0].issuer) -} diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/web/AnonymousUserHandlerTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/web/AnonymousUserHandlerTests.kt index 12df2bd12..d80f2b957 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/web/AnonymousUserHandlerTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/web/AnonymousUserHandlerTests.kt @@ -2,7 +2,6 @@ package com.egm.stellio.search.web import com.egm.stellio.search.authorization.AuthorizationService import com.egm.stellio.search.config.SearchProperties -import com.egm.stellio.search.config.WebSecurityTestConfig import com.egm.stellio.search.service.EntityEventService import com.egm.stellio.search.service.EntityPayloadService import com.egm.stellio.search.service.QueryService @@ -14,7 +13,6 @@ import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest -import org.springframework.context.annotation.Import import org.springframework.http.HttpHeaders import org.springframework.security.test.context.support.WithAnonymousUser import org.springframework.test.context.ActiveProfiles @@ -24,7 +22,6 @@ import org.springframework.test.web.reactive.server.WebTestClient @WebFluxTest(EntityHandler::class) @EnableConfigurationProperties(ApplicationProperties::class, SearchProperties::class) @Suppress("unused") -@Import(WebSecurityTestConfig::class) class AnonymousUserHandlerTests { @Autowired diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/web/AttributeHandlerTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/web/AttributeHandlerTests.kt index 1688f67bd..8cf090d52 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/web/AttributeHandlerTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/web/AttributeHandlerTests.kt @@ -3,7 +3,6 @@ package com.egm.stellio.search.web import arrow.core.left import arrow.core.right import com.egm.stellio.search.config.SearchProperties -import com.egm.stellio.search.config.WebSecurityTestConfig import com.egm.stellio.search.model.AttributeDetails import com.egm.stellio.search.model.AttributeList import com.egm.stellio.search.model.AttributeType @@ -21,7 +20,6 @@ import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest -import org.springframework.context.annotation.Import import org.springframework.http.HttpHeaders import org.springframework.http.MediaType import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.csrf @@ -32,7 +30,6 @@ import org.springframework.test.web.reactive.server.WebTestClient @ActiveProfiles("test") @WebFluxTest(AttributeHandler::class) @EnableConfigurationProperties(ApplicationProperties::class, SearchProperties::class) -@Import(WebSecurityTestConfig::class) class AttributeHandlerTests { @Autowired diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityAccessControlHandlerTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityAccessControlHandlerTests.kt index 5446332c3..1845d72d7 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityAccessControlHandlerTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityAccessControlHandlerTests.kt @@ -7,7 +7,6 @@ import com.egm.stellio.search.authorization.EntityAccessRights import com.egm.stellio.search.authorization.EntityAccessRightsService import com.egm.stellio.search.authorization.User import com.egm.stellio.search.config.SearchProperties -import com.egm.stellio.search.config.WebSecurityTestConfig import com.egm.stellio.search.service.EntityPayloadService import com.egm.stellio.shared.config.ApplicationProperties import com.egm.stellio.shared.model.* @@ -37,7 +36,6 @@ import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest -import org.springframework.context.annotation.Import import org.springframework.http.HttpHeaders import org.springframework.http.HttpStatus import org.springframework.http.MediaType @@ -51,7 +49,6 @@ import java.time.Duration @ActiveProfiles("test") @WebFluxTest(EntityAccessControlHandler::class) @EnableConfigurationProperties(ApplicationProperties::class, SearchProperties::class) -@Import(WebSecurityTestConfig::class) class EntityAccessControlHandlerTests { @Autowired diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityHandlerTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityHandlerTests.kt index 79fbb2f09..9a5c4de9e 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityHandlerTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityHandlerTests.kt @@ -4,7 +4,6 @@ import arrow.core.left import arrow.core.right import com.egm.stellio.search.authorization.AuthorizationService import com.egm.stellio.search.config.SearchProperties -import com.egm.stellio.search.config.WebSecurityTestConfig import com.egm.stellio.search.model.* import com.egm.stellio.search.service.EntityEventService import com.egm.stellio.search.service.EntityPayloadService @@ -34,7 +33,6 @@ import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest -import org.springframework.context.annotation.Import import org.springframework.core.io.ClassPathResource import org.springframework.http.HttpHeaders import org.springframework.http.HttpMethod @@ -51,7 +49,6 @@ import java.time.* @ActiveProfiles("test") @WebFluxTest(EntityHandler::class) @EnableConfigurationProperties(ApplicationProperties::class, SearchProperties::class) -@Import(WebSecurityTestConfig::class) class EntityHandlerTests { @Autowired diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityOperationHandlerTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityOperationHandlerTests.kt index 01492e202..b6287aae2 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityOperationHandlerTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityOperationHandlerTests.kt @@ -4,7 +4,6 @@ import arrow.core.left import arrow.core.right import com.egm.stellio.search.authorization.AuthorizationService import com.egm.stellio.search.config.SearchProperties -import com.egm.stellio.search.config.WebSecurityTestConfig import com.egm.stellio.search.model.EMPTY_UPDATE_RESULT import com.egm.stellio.search.model.EntityPayload import com.egm.stellio.search.model.UpdateResult @@ -31,7 +30,6 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest -import org.springframework.context.annotation.Import import org.springframework.core.io.ClassPathResource import org.springframework.http.HttpStatus import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.csrf @@ -44,7 +42,6 @@ import java.net.URI @ActiveProfiles("test") @WebFluxTest(EntityOperationHandler::class) @EnableConfigurationProperties(ApplicationProperties::class, SearchProperties::class) -@Import(WebSecurityTestConfig::class) class EntityOperationHandlerTests { @Autowired diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityTypeHandlerTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityTypeHandlerTests.kt index a898ebb44..4f8425445 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityTypeHandlerTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityTypeHandlerTests.kt @@ -3,7 +3,6 @@ package com.egm.stellio.search.web import arrow.core.left import arrow.core.right import com.egm.stellio.search.config.SearchProperties -import com.egm.stellio.search.config.WebSecurityTestConfig import com.egm.stellio.search.model.* import com.egm.stellio.search.model.AttributeType import com.egm.stellio.search.service.EntityTypeService @@ -19,7 +18,6 @@ import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest -import org.springframework.context.annotation.Import import org.springframework.http.HttpHeaders import org.springframework.http.MediaType import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.csrf @@ -30,7 +28,6 @@ import org.springframework.test.web.reactive.server.WebTestClient @ActiveProfiles("test") @WebFluxTest(EntityTypeHandler::class) @EnableConfigurationProperties(ApplicationProperties::class, SearchProperties::class) -@Import(WebSecurityTestConfig::class) class EntityTypeHandlerTests { @Autowired diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/web/TemporalEntityHandlerTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/web/TemporalEntityHandlerTests.kt index 0be654954..c669cc883 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/web/TemporalEntityHandlerTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/web/TemporalEntityHandlerTests.kt @@ -6,7 +6,6 @@ import arrow.core.left import arrow.core.right import com.egm.stellio.search.authorization.AuthorizationService import com.egm.stellio.search.config.SearchProperties -import com.egm.stellio.search.config.WebSecurityTestConfig import com.egm.stellio.search.model.SimplifiedAttributeInstanceResult import com.egm.stellio.search.model.TemporalEntityAttribute import com.egm.stellio.search.model.TemporalQuery @@ -28,7 +27,6 @@ import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest -import org.springframework.context.annotation.Import import org.springframework.core.io.ClassPathResource import org.springframework.http.HttpHeaders import org.springframework.http.HttpMethod @@ -46,7 +44,6 @@ import java.util.UUID @ActiveProfiles("test") @WebFluxTest(TemporalEntityHandler::class) @EnableConfigurationProperties(ApplicationProperties::class, SearchProperties::class) -@Import(WebSecurityTestConfig::class) class TemporalEntityHandlerTests { @Autowired diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/web/TemporalEntityOperationsHandlerTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/web/TemporalEntityOperationsHandlerTests.kt index 9b297bd01..8e7884ca6 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/web/TemporalEntityOperationsHandlerTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/web/TemporalEntityOperationsHandlerTests.kt @@ -3,7 +3,6 @@ package com.egm.stellio.search.web import arrow.core.Either import com.egm.stellio.search.authorization.AuthorizationService import com.egm.stellio.search.config.SearchProperties -import com.egm.stellio.search.config.WebSecurityTestConfig import com.egm.stellio.search.model.TemporalQuery import com.egm.stellio.search.service.QueryService import com.egm.stellio.shared.config.ApplicationProperties @@ -17,7 +16,6 @@ import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest -import org.springframework.context.annotation.Import import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.csrf import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.mockJwt import org.springframework.test.context.ActiveProfiles @@ -27,7 +25,6 @@ import java.time.ZonedDateTime @ActiveProfiles("test") @WebFluxTest(TemporalEntityOperationsHandler::class) @EnableConfigurationProperties(ApplicationProperties::class, SearchProperties::class) -@Import(WebSecurityTestConfig::class) class TemporalEntityOperationsHandlerTests { @Autowired diff --git a/shared/src/main/kotlin/com/egm/stellio/shared/config/TenantAuthenticationManagerResolver.kt b/shared/src/main/kotlin/com/egm/stellio/shared/config/TenantAuthenticationManagerResolver.kt index 5d6c2587e..1eff2591a 100644 --- a/shared/src/main/kotlin/com/egm/stellio/shared/config/TenantAuthenticationManagerResolver.kt +++ b/shared/src/main/kotlin/com/egm/stellio/shared/config/TenantAuthenticationManagerResolver.kt @@ -5,6 +5,7 @@ import com.egm.stellio.shared.web.DEFAULT_TENANT_NAME import com.egm.stellio.shared.web.NGSILD_TENANT_HEADER import org.springframework.beans.factory.InitializingBean import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty +import org.springframework.context.annotation.Profile import org.springframework.security.authentication.ReactiveAuthenticationManager import org.springframework.security.authentication.ReactiveAuthenticationManagerResolver import org.springframework.security.oauth2.jwt.ReactiveJwtDecoders @@ -14,6 +15,7 @@ import org.springframework.web.server.ServerWebExchange import reactor.core.publisher.Mono @Component +@Profile("!test") @ConditionalOnProperty("application.authentication.enabled") class TenantAuthenticationManagerResolver( private val applicationProperties: ApplicationProperties diff --git a/shared/src/main/kotlin/com/egm/stellio/shared/config/WebSecurityConfig.kt b/shared/src/main/kotlin/com/egm/stellio/shared/config/WebSecurityConfig.kt index 187ef5e8e..e17a98cf4 100644 --- a/shared/src/main/kotlin/com/egm/stellio/shared/config/WebSecurityConfig.kt +++ b/shared/src/main/kotlin/com/egm/stellio/shared/config/WebSecurityConfig.kt @@ -3,10 +3,12 @@ package com.egm.stellio.shared.config import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Profile import org.springframework.security.config.web.server.ServerHttpSecurity import org.springframework.security.web.server.SecurityWebFilterChain @Configuration +@Profile("!test") @ConditionalOnProperty("application.authentication.enabled") class WebSecurityConfig( private val tenantAuthenticationManagerResolver: TenantAuthenticationManagerResolver