diff --git a/src/main/java/net/hostsharing/hsadminng/config/CasAuthenticator.java b/src/main/java/net/hostsharing/hsadminng/config/CasAuthenticator.java index a7918324..278b5470 100644 --- a/src/main/java/net/hostsharing/hsadminng/config/CasAuthenticator.java +++ b/src/main/java/net/hostsharing/hsadminng/config/CasAuthenticator.java @@ -1,23 +1,15 @@ package net.hostsharing.hsadminng.config; -import lombok.AllArgsConstructor; -import lombok.NoArgsConstructor; import lombok.SneakyThrows; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Primary; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import jakarta.servlet.http.HttpServletRequest; import javax.xml.parsers.DocumentBuilderFactory; -@Primary -@Service -@NoArgsConstructor -@AllArgsConstructor public class CasAuthenticator implements Authenticator { @Value("${hsadminng.cas.server-url}") diff --git a/src/main/java/net/hostsharing/hsadminng/config/WebSecurityConfig.java b/src/main/java/net/hostsharing/hsadminng/config/WebSecurityConfig.java index 6da383ab..6c91ce17 100644 --- a/src/main/java/net/hostsharing/hsadminng/config/WebSecurityConfig.java +++ b/src/main/java/net/hostsharing/hsadminng/config/WebSecurityConfig.java @@ -24,4 +24,11 @@ public class WebSecurityConfig { ) .build(); } + + @Bean + @Profile("!test") + public Authenticator casServiceTicketValidator() { + return new CasAuthenticator(); + } + } diff --git a/src/test/java/net/hostsharing/hsadminng/test/DisableSecurityConfig.java b/src/test/java/net/hostsharing/hsadminng/test/DisableSecurityConfig.java index 0fa84c8c..0021dbbe 100644 --- a/src/test/java/net/hostsharing/hsadminng/test/DisableSecurityConfig.java +++ b/src/test/java/net/hostsharing/hsadminng/test/DisableSecurityConfig.java @@ -3,6 +3,7 @@ package net.hostsharing.hsadminng.test; import net.hostsharing.hsadminng.config.Authenticator; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Profile; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.web.SecurityFilterChain; @@ -11,6 +12,7 @@ import org.springframework.security.web.SecurityFilterChain; public class DisableSecurityConfig { @Bean + @Profile("test") public SecurityFilterChain securityFilterChain(final HttpSecurity http) throws Exception { http .authorizeHttpRequests(auth -> auth.anyRequest().permitAll()) @@ -19,7 +21,8 @@ public class DisableSecurityConfig { } @Bean - public Authenticator casServiceTicketValidator() { + @Profile("test") + public Authenticator fakeAuthenticator() { return new FakeAuthenticator(); } } diff --git a/src/test/java/net/hostsharing/hsadminng/test/FakeAuthenticator.java b/src/test/java/net/hostsharing/hsadminng/test/FakeAuthenticator.java index f749c262..4e5e3132 100644 --- a/src/test/java/net/hostsharing/hsadminng/test/FakeAuthenticator.java +++ b/src/test/java/net/hostsharing/hsadminng/test/FakeAuthenticator.java @@ -2,11 +2,9 @@ package net.hostsharing.hsadminng.test; import lombok.SneakyThrows; import net.hostsharing.hsadminng.config.Authenticator; -import org.springframework.stereotype.Service; import jakarta.servlet.http.HttpServletRequest; -@Service public class FakeAuthenticator implements Authenticator { @Override