saml-extension-federation Uses Docker Idp
Issue gh-127
This commit is contained in:
@@ -23,6 +23,9 @@ dependencies {
|
||||
implementation 'org.springframework.security:spring-security-saml2-service-provider'
|
||||
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
|
||||
|
||||
runtimeOnly files("$projectDir/../identity-provider/build/resources/main")
|
||||
|
||||
testImplementation project(':servlet:spring-boot:java:saml2:identity-provider')
|
||||
testImplementation 'org.htmlunit:htmlunit'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
testImplementation 'org.springframework.security:spring-security-test'
|
||||
|
||||
@@ -6,3 +6,6 @@ pluginManagement {
|
||||
maven { url "https://repo.spring.io/snapshot" }
|
||||
}
|
||||
}
|
||||
|
||||
include ":servlet:spring-boot:java:saml2:identity-provider"
|
||||
project(":servlet:spring-boot:java:saml2:identity-provider").projectDir = file("../identity-provider")
|
||||
@@ -21,33 +21,28 @@ import java.util.List;
|
||||
|
||||
import org.htmlunit.ElementNotFoundException;
|
||||
import org.htmlunit.WebClient;
|
||||
import org.htmlunit.html.HtmlButton;
|
||||
import org.htmlunit.html.HtmlElement;
|
||||
import org.htmlunit.html.HtmlForm;
|
||||
import org.htmlunit.html.HtmlInput;
|
||||
import org.htmlunit.html.HtmlPage;
|
||||
import org.htmlunit.html.HtmlPasswordInput;
|
||||
import org.htmlunit.html.HtmlSubmitInput;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.forwardedUrl;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@Disabled
|
||||
@SpringBootTest
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||
@AutoConfigureMockMvc
|
||||
public class SamlExtensionFederationApplicationITests {
|
||||
|
||||
@Autowired
|
||||
MockMvc mvc;
|
||||
@LocalServerPort
|
||||
int port;
|
||||
|
||||
@Autowired
|
||||
WebClient webClient;
|
||||
@@ -61,7 +56,7 @@ public class SamlExtensionFederationApplicationITests {
|
||||
void authenticationAttemptWhenValidThenShowsUserEmailAddress() throws Exception {
|
||||
performLogin();
|
||||
HtmlPage home = (HtmlPage) this.webClient.getCurrentWindow().getEnclosedPage();
|
||||
assertThat(home.asNormalizedText()).contains("You're email address is testuser2@spring.security.saml");
|
||||
assertThat(home.asNormalizedText()).contains("You're email address is user1@example.org");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,13 +72,6 @@ public class SamlExtensionFederationApplicationITests {
|
||||
assertThat(urls).contains("/login?logout");
|
||||
}
|
||||
|
||||
@Test
|
||||
void metadataWhenGetThenForwardToUrl() throws Exception {
|
||||
this.mvc.perform(get("/saml/metadata"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(forwardedUrl("/saml2/service-provider-metadata/one"));
|
||||
}
|
||||
|
||||
private void performLogin() throws Exception {
|
||||
HtmlPage login = this.webClient.getPage("/");
|
||||
login.getAnchors().get(0).click();
|
||||
@@ -91,9 +79,9 @@ public class SamlExtensionFederationApplicationITests {
|
||||
HtmlForm form = findForm(login);
|
||||
HtmlInput username = form.getInputByName("username");
|
||||
HtmlPasswordInput password = form.getInputByName("password");
|
||||
HtmlSubmitInput submit = login.getHtmlElementById("okta-signin-submit");
|
||||
username.type("testuser2@spring.security.saml");
|
||||
password.type("12345678");
|
||||
HtmlButton submit = (HtmlButton) form.getElementsByTagName("button").iterator().next();
|
||||
username.type("user1");
|
||||
password.type("user1pass");
|
||||
submit.click();
|
||||
this.webClient.waitForBackgroundJavaScript(10000);
|
||||
}
|
||||
@@ -101,7 +89,7 @@ public class SamlExtensionFederationApplicationITests {
|
||||
private HtmlForm findForm(HtmlPage login) {
|
||||
for (HtmlForm form : login.getForms()) {
|
||||
try {
|
||||
if (form.getId().equals("form19")) {
|
||||
if (form.getNameAttribute().equals("f")) {
|
||||
return form;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ public class SecurityConfiguration {
|
||||
.map((builder) -> builder.registrationId(UUID.randomUUID().toString())
|
||||
.entityId(registration.getEntityId())
|
||||
.assertionConsumerServiceLocation(registration.getAcs().getLocation())
|
||||
.singleLogoutServiceBinding(registration.getSinglelogout().getBinding())
|
||||
.singleLogoutServiceLocation(registration.getSinglelogout().getUrl())
|
||||
.singleLogoutServiceResponseLocation(registration.getSinglelogout().getResponseUrl())
|
||||
.signingX509Credentials((credentials) -> credentials.add(signing))
|
||||
|
||||
@@ -2,6 +2,11 @@ logging.level:
|
||||
org.springframework.security: TRACE
|
||||
|
||||
spring:
|
||||
docker:
|
||||
compose:
|
||||
file: classpath:docker/compose.yml
|
||||
readiness:
|
||||
wait: never
|
||||
security:
|
||||
filter:
|
||||
dispatcher-types: async, error, request, forward
|
||||
@@ -9,11 +14,11 @@ spring:
|
||||
relyingparty:
|
||||
registration:
|
||||
metadata:
|
||||
entity-id: "{baseUrl}/saml2/service-provider-metadata/one"
|
||||
entity-id: "{baseUrl}/saml/metadata"
|
||||
singlelogout:
|
||||
binding: POST
|
||||
binding: REDIRECT
|
||||
url: "{baseUrl}/saml/logout"
|
||||
responseUrl: "{baseUrl}/saml/SingleLogout"
|
||||
acs:
|
||||
location: "{baseUrl}/saml/SSO"
|
||||
assertingparty.metadata-uri: https://dev-05937739.okta.com/app/exk598vc9bHhwoTXM5d7/sso/saml/metadata
|
||||
assertingparty.metadata-uri: http://idp-one.7f000001.nip.io/simplesaml/saml2/idp/metadata.php
|
||||
|
||||
Reference in New Issue
Block a user