fi most tests

This commit is contained in:
Michael Hoennig 2024-12-20 14:22:52 +01:00
parent 9ed2b79fe3
commit a41430eea9
4 changed files with 11 additions and 11 deletions

View File

@ -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}")

View File

@ -24,4 +24,11 @@ public class WebSecurityConfig {
)
.build();
}
@Bean
@Profile("!test")
public Authenticator casServiceTicketValidator() {
return new CasAuthenticator();
}
}

View File

@ -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();
}
}

View File

@ -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