Add LogoutPageGeneratingWebFilter
Fixes gh-4735
This commit is contained in:
+1
@@ -41,6 +41,7 @@ public enum SecurityWebFiltersOrder {
|
||||
*/
|
||||
REACTOR_CONTEXT,
|
||||
LOGIN_PAGE_GENERATING,
|
||||
LOGOUT_PAGE_GENERATING,
|
||||
/**
|
||||
* {@link org.springframework.security.web.server.context.SecurityContextServerWebExchangeWebFilter}
|
||||
*/
|
||||
|
||||
+2
@@ -61,6 +61,7 @@ import org.springframework.security.web.server.header.StrictTransportSecuritySer
|
||||
import org.springframework.security.web.server.header.XFrameOptionsServerHttpHeadersWriter;
|
||||
import org.springframework.security.web.server.header.XXssProtectionServerHttpHeadersWriter;
|
||||
import org.springframework.security.web.server.ui.LoginPageGeneratingWebFilter;
|
||||
import org.springframework.security.web.server.ui.LogoutPageGeneratingWebFilter;
|
||||
import org.springframework.security.web.server.util.matcher.MediaTypeServerWebExchangeMatcher;
|
||||
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher;
|
||||
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcherEntry;
|
||||
@@ -220,6 +221,7 @@ public class ServerHttpSecurity {
|
||||
}
|
||||
if(this.formLogin.serverAuthenticationEntryPoint == null) {
|
||||
this.webFilters.add(new OrderedWebFilter(new LoginPageGeneratingWebFilter(), SecurityWebFiltersOrder.LOGIN_PAGE_GENERATING.getOrder()));
|
||||
this.webFilters.add(new OrderedWebFilter(new LogoutPageGeneratingWebFilter(), SecurityWebFiltersOrder.LOGOUT_PAGE_GENERATING.getOrder()));
|
||||
}
|
||||
this.formLogin.configure(this);
|
||||
}
|
||||
|
||||
+30
-2
@@ -78,9 +78,11 @@ public class FormLoginTests {
|
||||
|
||||
homePage.assertAt();
|
||||
|
||||
driver.get("http://localhost/logout");
|
||||
loginPage = DefaultLogoutPage.to(driver)
|
||||
.assertAt()
|
||||
.logout();
|
||||
|
||||
DefaultLoginPage.create(driver)
|
||||
loginPage
|
||||
.assertAt()
|
||||
.assertLogout();
|
||||
}
|
||||
@@ -229,6 +231,32 @@ public class FormLoginTests {
|
||||
}
|
||||
}
|
||||
|
||||
public static class DefaultLogoutPage {
|
||||
|
||||
private WebDriver driver;
|
||||
@FindBy(css = "button[type=submit]")
|
||||
private WebElement submit;
|
||||
|
||||
public DefaultLogoutPage(WebDriver webDriver) {
|
||||
this.driver = webDriver;
|
||||
}
|
||||
|
||||
public DefaultLogoutPage assertAt() {
|
||||
assertThat(this.driver.getTitle()).isEqualTo("Confirm Log Out?");
|
||||
return this;
|
||||
}
|
||||
|
||||
public DefaultLoginPage logout() {
|
||||
this.submit.click();
|
||||
return DefaultLoginPage.create(this.driver);
|
||||
}
|
||||
|
||||
static DefaultLogoutPage to(WebDriver driver) {
|
||||
driver.get("http://localhost/logout");
|
||||
return PageFactory.initElements(driver, DefaultLogoutPage.class);
|
||||
}
|
||||
|
||||
}
|
||||
public static class HomePage {
|
||||
private WebDriver driver;
|
||||
|
||||
|
||||
+6
-3
@@ -26,6 +26,7 @@ import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.htmlunit.server.WebTestClientHtmlUnitDriverBuilder;
|
||||
import org.springframework.security.web.server.SecurityWebFilterChain;
|
||||
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatchers;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.security.test.web.reactive.server.WebTestClientBuilder;
|
||||
|
||||
@@ -70,9 +71,11 @@ public class LogoutBuilderTests {
|
||||
|
||||
homePage.assertAt();
|
||||
|
||||
driver.get("http://localhost/logout");
|
||||
loginPage = FormLoginTests.DefaultLogoutPage.to(driver)
|
||||
.assertAt()
|
||||
.logout();
|
||||
|
||||
FormLoginTests.DefaultLoginPage.create(driver)
|
||||
loginPage
|
||||
.assertAt()
|
||||
.assertLogout();
|
||||
}
|
||||
@@ -85,7 +88,7 @@ public class LogoutBuilderTests {
|
||||
.and()
|
||||
.formLogin().and()
|
||||
.logout()
|
||||
.logoutUrl("/custom-logout")
|
||||
.requiresLogout(ServerWebExchangeMatchers.pathMatchers("/custom-logout"))
|
||||
.and()
|
||||
.build();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user