Update samples to use Spring Security 6
Issue gh-46
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
plugins {
|
||||
id "java"
|
||||
id "nebula.integtest" version "8.2.0"
|
||||
id "org.gretty" version "3.0.6"
|
||||
id "org.gretty" version "4.0.0"
|
||||
id "war"
|
||||
}
|
||||
|
||||
@@ -14,14 +14,14 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
||||
implementation platform("org.springframework.security:spring-security-bom:5.5.0-SNAPSHOT")
|
||||
implementation platform("org.springframework:spring-framework-bom:6.0.0-SNAPSHOT")
|
||||
implementation platform("org.springframework.security:spring-security-bom:6.0.0-SNAPSHOT")
|
||||
implementation platform("org.junit:junit-bom:5.7.0")
|
||||
|
||||
implementation "org.springframework.security:spring-security-config"
|
||||
implementation "org.springframework.security:spring-security-web"
|
||||
implementation "org.springframework:spring-webmvc"
|
||||
implementation "org.thymeleaf:thymeleaf-spring5:3.0.11.RELEASE"
|
||||
implementation "org.thymeleaf:thymeleaf-spring6:3.1.0.M1"
|
||||
|
||||
testImplementation "org.assertj:assertj-core:3.18.0"
|
||||
testImplementation "org.springframework:spring-test"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
gretty {
|
||||
servletContainer = "tomcat9"
|
||||
servletContainer = "tomcat10"
|
||||
contextPath = "/"
|
||||
fileLogEnabled = false
|
||||
integrationTestTask = 'integrationTest'
|
||||
@@ -38,4 +38,4 @@ project.tasks.matching { it.name == "integrationTest" }.all {
|
||||
integrationTest.systemProperty 'app.httpBaseURI', httpBaseUrl
|
||||
integrationTest.systemProperty 'app.httpsBaseURI', httpsBaseUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package example;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import jakarta.servlet.Filter;
|
||||
|
||||
import org.springframework.web.filter.HiddenHttpMethodFilter;
|
||||
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
package example;
|
||||
|
||||
import org.thymeleaf.spring5.ISpringTemplateEngine;
|
||||
import org.thymeleaf.spring5.SpringTemplateEngine;
|
||||
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
|
||||
import org.thymeleaf.spring5.view.ThymeleafViewResolver;
|
||||
import org.thymeleaf.spring6.ISpringTemplateEngine;
|
||||
import org.thymeleaf.spring6.SpringTemplateEngine;
|
||||
import org.thymeleaf.spring6.templateresolver.SpringResourceTemplateResolver;
|
||||
import org.thymeleaf.spring6.view.ThymeleafViewResolver;
|
||||
import org.thymeleaf.templatemode.TemplateMode;
|
||||
import org.thymeleaf.templateresolver.ITemplateResolver;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id "java"
|
||||
id "nebula.integtest" version "8.2.0"
|
||||
// id "nebula.integtest" version "8.2.0"
|
||||
id "org.gretty" version "3.0.6"
|
||||
id "war"
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
plugins {
|
||||
id "java"
|
||||
id "nebula.integtest" version "8.2.0"
|
||||
id "org.gretty" version "3.0.6"
|
||||
id "org.gretty" version "4.0.0"
|
||||
id "war"
|
||||
}
|
||||
|
||||
@@ -14,14 +14,14 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation platform("org.springframework:spring-framework-bom:5.3.0")
|
||||
implementation platform("org.springframework.security:spring-security-bom:5.5.0-SNAPSHOT")
|
||||
implementation platform("org.springframework:spring-framework-bom:6.0.0-SNAPSHOT")
|
||||
implementation platform("org.springframework.security:spring-security-bom:6.0.0-SNAPSHOT")
|
||||
implementation platform("org.junit:junit-bom:5.7.0")
|
||||
|
||||
implementation "org.springframework.security:spring-security-config"
|
||||
implementation "org.springframework.security:spring-security-web"
|
||||
implementation "org.springframework:spring-webmvc"
|
||||
implementation "org.thymeleaf:thymeleaf-spring5:3.0.11.RELEASE"
|
||||
implementation "org.thymeleaf:thymeleaf-spring6:3.1.0.M1"
|
||||
|
||||
testImplementation "org.assertj:assertj-core:3.18.0"
|
||||
testImplementation "org.springframework:spring-test"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
gretty {
|
||||
servletContainer = "tomcat9"
|
||||
servletContainer = "tomcat10"
|
||||
contextPath = "/"
|
||||
fileLogEnabled = false
|
||||
integrationTestTask = 'integrationTest'
|
||||
@@ -38,4 +38,4 @@ project.tasks.matching { it.name == "integrationTest" }.all {
|
||||
integrationTest.systemProperty 'app.httpBaseURI', httpBaseUrl
|
||||
integrationTest.systemProperty 'app.httpsBaseURI', httpsBaseUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,8 +51,10 @@ public class LoginPage {
|
||||
|
||||
private WebDriver webDriver;
|
||||
|
||||
@FindBy(id = "username")
|
||||
private WebElement username;
|
||||
|
||||
@FindBy(id = "password")
|
||||
private WebElement password;
|
||||
|
||||
@FindBy(css = "button[type=submit]")
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package example;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import jakarta.servlet.Filter;
|
||||
|
||||
import org.springframework.web.filter.HiddenHttpMethodFilter;
|
||||
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
package example;
|
||||
|
||||
import org.thymeleaf.spring5.ISpringTemplateEngine;
|
||||
import org.thymeleaf.spring5.SpringTemplateEngine;
|
||||
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
|
||||
import org.thymeleaf.spring5.view.ThymeleafViewResolver;
|
||||
import org.thymeleaf.spring6.ISpringTemplateEngine;
|
||||
import org.thymeleaf.spring6.SpringTemplateEngine;
|
||||
import org.thymeleaf.spring6.templateresolver.SpringResourceTemplateResolver;
|
||||
import org.thymeleaf.spring6.view.ThymeleafViewResolver;
|
||||
import org.thymeleaf.templatemode.TemplateMode;
|
||||
import org.thymeleaf.templateresolver.ITemplateResolver;
|
||||
|
||||
|
||||
@@ -51,8 +51,10 @@ public class LoginPage {
|
||||
|
||||
private WebDriver webDriver;
|
||||
|
||||
@FindBy(id = "username")
|
||||
private WebElement username;
|
||||
|
||||
@FindBy(id = "password")
|
||||
private WebElement password;
|
||||
|
||||
@FindBy(css = "button[type=submit]")
|
||||
|
||||
@@ -36,21 +36,19 @@ dependencies {
|
||||
implementation "org.opensaml:opensaml-saml-api:4.1.1"
|
||||
implementation "org.opensaml:opensaml-saml-impl:4.1.1"
|
||||
}
|
||||
implementation platform("org.springframework:spring-framework-bom:5.3.11")
|
||||
implementation platform("org.springframework.security:spring-security-bom:5.6.0-SNAPSHOT")
|
||||
implementation platform("org.springframework:spring-framework-bom:6.0.0-SNAPSHOT")
|
||||
implementation platform("org.springframework.security:spring-security-bom:6.0.0-SNAPSHOT")
|
||||
implementation platform("org.junit:junit-bom:5.7.0")
|
||||
|
||||
implementation "org.springframework.security:spring-security-config"
|
||||
implementation "org.springframework.security:spring-security-web"
|
||||
implementation "org.springframework:spring-webmvc"
|
||||
implementation "org.springframework.security:spring-security-saml2-service-provider"
|
||||
implementation "javax.servlet.jsp.jstl:javax.servlet.jsp.jstl-api:1.2.2"
|
||||
implementation "org.apache.taglibs:taglibs-standard-jstlel:1.2.5"
|
||||
implementation "org.thymeleaf:thymeleaf-spring5:3.0.11.RELEASE"
|
||||
implementation "org.thymeleaf.extras:thymeleaf-extras-springsecurity5:3.0.4.RELEASE"
|
||||
implementation "org.thymeleaf:thymeleaf-spring6:3.1.0.M1"
|
||||
implementation "org.thymeleaf.extras:thymeleaf-extras-springsecurity6:3.1.0.M1"
|
||||
|
||||
providedCompile "javax.servlet:javax.servlet-api:4.0.1"
|
||||
providedCompile "javax.servlet.jsp:javax.servlet.jsp-api:2.3.3"
|
||||
providedCompile "jakarta.servlet:jakarta.servlet-api:5.0.0"
|
||||
providedCompile "org.glassfish.web:jakarta.servlet.jsp.jstl:2.0.0"
|
||||
|
||||
testImplementation "org.assertj:assertj-core:3.18.0"
|
||||
testImplementation "org.springframework:spring-test"
|
||||
@@ -58,6 +56,7 @@ dependencies {
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-api")
|
||||
testImplementation "org.seleniumhq.selenium:htmlunit-driver:2.44.0"
|
||||
testImplementation 'org.hamcrest:hamcrest:2.2'
|
||||
testImplementation 'org.awaitility:awaitility:4.2.0'
|
||||
|
||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
|
||||
}
|
||||
|
||||
@@ -16,15 +16,16 @@
|
||||
|
||||
package example;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.gargoylesoftware.htmlunit.ElementNotFoundException;
|
||||
import com.gargoylesoftware.htmlunit.WebClient;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlElement;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlForm;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlInput;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -40,6 +41,9 @@ import org.springframework.test.web.servlet.htmlunit.MockMvcWebClientBuilder;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = ApplicationConfiguration.class)
|
||||
@WebAppConfiguration
|
||||
@@ -66,35 +70,47 @@ public class Saml2JavaConfigurationITests {
|
||||
|
||||
@Test
|
||||
void authenticationAttemptWhenValidThenShowsUserEmailAddress() throws Exception {
|
||||
HtmlPage relyingParty = performLogin();
|
||||
Assertions.assertThat(relyingParty.asText()).contains("You're email address is testuser@spring.security.saml");
|
||||
performLogin();
|
||||
HtmlPage home = (HtmlPage) this.webClient.getCurrentWindow().getEnclosedPage();
|
||||
assertThat(home.asText()).contains("You're email address is testuser@spring.security.saml");
|
||||
}
|
||||
|
||||
@Test
|
||||
void logoutWhenRelyingPartyInitiatedLogoutThenLoginPageWithLogoutParam() throws Exception {
|
||||
HtmlPage relyingParty = performLogin();
|
||||
HtmlElement rpLogoutButton = relyingParty.getHtmlElementById("rp_logout_button");
|
||||
performLogin();
|
||||
HtmlPage home = (HtmlPage) this.webClient.getCurrentWindow().getEnclosedPage();
|
||||
HtmlElement rpLogoutButton = home.getHtmlElementById("rp_logout_button");
|
||||
HtmlPage loginPage = rpLogoutButton.click();
|
||||
Assertions.assertThat(loginPage.getUrl().getFile()).isEqualTo("/login?logout");
|
||||
assertThat(loginPage.getUrl().getFile()).isEqualTo("/login?logout");
|
||||
}
|
||||
|
||||
@Test
|
||||
void logoutWhenAssertingPartyInitiatedLogoutThenLoginPageWithLogoutParam() throws Exception {
|
||||
HtmlPage relyingParty = performLogin();
|
||||
HtmlElement apLogoutButton = relyingParty.getHtmlElementById("ap_logout_button");
|
||||
HtmlPage loginPage = apLogoutButton.click();
|
||||
Assertions.assertThat(loginPage.getUrl().getFile()).isEqualTo("/login?logout");
|
||||
}
|
||||
|
||||
private HtmlPage performLogin() throws IOException {
|
||||
private void performLogin() throws Exception {
|
||||
HtmlPage login = this.webClient.getPage("/");
|
||||
HtmlForm form = login.getFormByName("f");
|
||||
this.webClient.waitForBackgroundJavaScript(10000);
|
||||
HtmlForm form = findForm(login);
|
||||
HtmlInput username = form.getInputByName("username");
|
||||
HtmlInput password = form.getInputByName("password");
|
||||
HtmlSubmitInput submit = login.getHtmlElementById("submit_button");
|
||||
username.setValueAttribute("user");
|
||||
password.setValueAttribute("password");
|
||||
return submit.click();
|
||||
HtmlPasswordInput password = form.getInputByName("password");
|
||||
HtmlSubmitInput submit = login.getHtmlElementById("okta-signin-submit");
|
||||
username.type("testuser@spring.security.saml");
|
||||
password.type("12345678");
|
||||
submit.click();
|
||||
this.webClient.waitForBackgroundJavaScript(10000);
|
||||
}
|
||||
|
||||
private HtmlForm findForm(HtmlPage login) {
|
||||
await().atMost(10, TimeUnit.SECONDS)
|
||||
.until(() -> login.getForms().stream().map(HtmlForm::getId).anyMatch("form19"::equals));
|
||||
for (HtmlForm form : login.getForms()) {
|
||||
try {
|
||||
if (form.getId().equals("form19")) {
|
||||
return form;
|
||||
}
|
||||
}
|
||||
catch (ElementNotFoundException ex) {
|
||||
// Continue
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("Could not resolve login form");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package example;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import jakarta.servlet.Filter;
|
||||
|
||||
import org.springframework.web.filter.HiddenHttpMethodFilter;
|
||||
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
package example;
|
||||
|
||||
import org.thymeleaf.extras.springsecurity5.dialect.SpringSecurityDialect;
|
||||
import org.thymeleaf.spring5.ISpringTemplateEngine;
|
||||
import org.thymeleaf.spring5.SpringTemplateEngine;
|
||||
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
|
||||
import org.thymeleaf.spring5.view.ThymeleafViewResolver;
|
||||
import org.thymeleaf.extras.springsecurity6.dialect.SpringSecurityDialect;
|
||||
import org.thymeleaf.spring6.ISpringTemplateEngine;
|
||||
import org.thymeleaf.spring6.SpringTemplateEngine;
|
||||
import org.thymeleaf.spring6.templateresolver.SpringResourceTemplateResolver;
|
||||
import org.thymeleaf.spring6.view.ThymeleafViewResolver;
|
||||
import org.thymeleaf.templatemode.TemplateMode;
|
||||
import org.thymeleaf.templateresolver.ITemplateResolver;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user