add CAS authentication #138

Merged
hsh-michaelhoennig merged 24 commits from feature/add-cas-authentication into master 2024-12-23 12:49:46 +01:00
4 changed files with 11 additions and 11 deletions
Showing only changes of commit a41430eea9 - Show all commits

View File

@ -1,23 +1,15 @@
package net.hostsharing.hsadminng.config; package net.hostsharing.hsadminng.config;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary;
import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
@Primary
@Service
@NoArgsConstructor
@AllArgsConstructor
public class CasAuthenticator implements Authenticator { public class CasAuthenticator implements Authenticator {
@Value("${hsadminng.cas.server-url}") @Value("${hsadminng.cas.server-url}")

View File

@ -24,4 +24,11 @@ public class WebSecurityConfig {
) )
.build(); .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 net.hostsharing.hsadminng.config.Authenticator;
import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean; 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.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
@ -11,6 +12,7 @@ import org.springframework.security.web.SecurityFilterChain;
public class DisableSecurityConfig { public class DisableSecurityConfig {
@Bean @Bean
@Profile("test")
public SecurityFilterChain securityFilterChain(final HttpSecurity http) throws Exception { public SecurityFilterChain securityFilterChain(final HttpSecurity http) throws Exception {
http http
.authorizeHttpRequests(auth -> auth.anyRequest().permitAll()) .authorizeHttpRequests(auth -> auth.anyRequest().permitAll())
@ -19,7 +21,8 @@ public class DisableSecurityConfig {
} }
@Bean @Bean
public Authenticator casServiceTicketValidator() { @Profile("test")
public Authenticator fakeAuthenticator() {
return new FakeAuthenticator(); return new FakeAuthenticator();
} }
} }

View File

@ -2,11 +2,9 @@ package net.hostsharing.hsadminng.test;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import net.hostsharing.hsadminng.config.Authenticator; import net.hostsharing.hsadminng.config.Authenticator;
import org.springframework.stereotype.Service;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
@Service
public class FakeAuthenticator implements Authenticator { public class FakeAuthenticator implements Authenticator {
@Override @Override