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 30 additions and 8 deletions
Showing only changes of commit d359ae1693 - Show all commits

View File

@ -0,0 +1,8 @@
package net.hostsharing.hsadminng.config;
import jakarta.servlet.http.HttpServletRequest;
public interface Authenticator {
String authenticate(final HttpServletRequest httpRequest);
}

View File

@ -16,7 +16,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
@Service
@NoArgsConstructor
@AllArgsConstructor
public class CasAuthenticator {
public class CasAuthenticator implements Authenticator {
@Value("${hsadminng.cas.server-url}")
private String casServerUrl;
@ -28,11 +28,6 @@ public class CasAuthenticator {
@SneakyThrows
public String authenticate(final HttpServletRequest httpRequest) {
// FIXME: create FakeCasAuthenticator
if (casServerUrl.equals("fake")) {
return httpRequest.getHeader("current-subject");
}
final var ticket = httpRequest.getHeader("Authorization");
final var url = casServerUrl + "/p3/serviceValidate" +
"?service=" + serviceUrl +

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.test;
import net.hostsharing.hsadminng.config.Authenticator;
import net.hostsharing.hsadminng.config.CasAuthenticator;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
@ -19,7 +20,7 @@ public class DisableSecurityConfig {
}
@Bean
public CasAuthenticator casServiceTicketValidator() {
return new CasAuthenticator("fake", null);
public Authenticator casServiceTicketValidator() {
return new FakeAuthenticator();
}
}

View File

@ -0,0 +1,18 @@
package net.hostsharing.hsadminng.test;
import lombok.SneakyThrows;
import net.hostsharing.hsadminng.config.Authenticator;
import net.hostsharing.hsadminng.config.CasAuthenticator;
import org.springframework.stereotype.Service;
import jakarta.servlet.http.HttpServletRequest;
@Service
public class FakeAuthenticator implements Authenticator {
@Override
@SneakyThrows
public String authenticate(final HttpServletRequest httpRequest) {
return httpRequest.getHeader("current-subject");
}
}