diff --git a/src/main/java/net/hostsharing/hsadminng/config/Authenticator.java b/src/main/java/net/hostsharing/hsadminng/config/Authenticator.java new file mode 100644 index 00000000..13f4ada4 --- /dev/null +++ b/src/main/java/net/hostsharing/hsadminng/config/Authenticator.java @@ -0,0 +1,8 @@ +package net.hostsharing.hsadminng.config; + +import jakarta.servlet.http.HttpServletRequest; + +public interface Authenticator { + + String authenticate(final HttpServletRequest httpRequest); +} diff --git a/src/main/java/net/hostsharing/hsadminng/config/CasAuthenticator.java b/src/main/java/net/hostsharing/hsadminng/config/CasAuthenticator.java index 2d0302ee..a048a16c 100644 --- a/src/main/java/net/hostsharing/hsadminng/config/CasAuthenticator.java +++ b/src/main/java/net/hostsharing/hsadminng/config/CasAuthenticator.java @@ -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 + diff --git a/src/test/java/net/hostsharing/hsadminng/test/DisableSecurityConfig.java b/src/test/java/net/hostsharing/hsadminng/test/DisableSecurityConfig.java index 16918eef..978edbb8 100644 --- a/src/test/java/net/hostsharing/hsadminng/test/DisableSecurityConfig.java +++ b/src/test/java/net/hostsharing/hsadminng/test/DisableSecurityConfig.java @@ -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(); } } diff --git a/src/test/java/net/hostsharing/hsadminng/test/FakeAuthenticator.java b/src/test/java/net/hostsharing/hsadminng/test/FakeAuthenticator.java new file mode 100644 index 00000000..66dcd9a3 --- /dev/null +++ b/src/test/java/net/hostsharing/hsadminng/test/FakeAuthenticator.java @@ -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"); + } +}