Search in sources :

Example 1 with HomePage

use of org.springframework.security.config.web.server.FormLoginTests.HomePage in project spring-security by spring-projects.

the class RequestCacheTests method requestCacheNoOp.

@Test
public void requestCacheNoOp() {
    // @formatter:off
    SecurityWebFilterChain securityWebFilter = this.http.authorizeExchange().anyExchange().authenticated().and().formLogin().and().requestCache().requestCache(NoOpServerRequestCache.getInstance()).and().build();
    WebTestClient webTestClient = WebTestClient.bindToController(new SecuredPageController(), new WebTestClientBuilder.Http200RestController()).webFilter(new WebFilterChainProxy(securityWebFilter)).build();
    WebDriver driver = WebTestClientHtmlUnitDriverBuilder.webTestClientSetup(webTestClient).build();
    // @formatter:on
    DefaultLoginPage loginPage = SecuredPage.to(driver, DefaultLoginPage.class).assertAt();
    // @formatter:off
    HomePage securedPage = loginPage.loginForm().username("user").password("password").submit(HomePage.class);
    // @formatter:on
    securedPage.assertAt();
}
Also used : WebTestClientBuilder(org.springframework.security.test.web.reactive.server.WebTestClientBuilder) WebDriver(org.openqa.selenium.WebDriver) HomePage(org.springframework.security.config.web.server.FormLoginTests.HomePage) WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) WebFilterChainProxy(org.springframework.security.web.server.WebFilterChainProxy) DefaultLoginPage(org.springframework.security.config.web.server.FormLoginTests.DefaultLoginPage) SecurityWebFilterChain(org.springframework.security.web.server.SecurityWebFilterChain) Test(org.junit.jupiter.api.Test)

Example 2 with HomePage

use of org.springframework.security.config.web.server.FormLoginTests.HomePage in project spring-security by spring-projects.

the class RequestCacheTests method requestWhenCustomRequestCacheInLambdaThenCustomCacheUsed.

@Test
public void requestWhenCustomRequestCacheInLambdaThenCustomCacheUsed() {
    // @formatter:off
    SecurityWebFilterChain securityWebFilter = this.http.authorizeExchange((exchange) -> exchange.anyExchange().authenticated()).formLogin(withDefaults()).requestCache((requestCache) -> requestCache.requestCache(NoOpServerRequestCache.getInstance())).build();
    WebTestClient webTestClient = WebTestClient.bindToController(new SecuredPageController(), new WebTestClientBuilder.Http200RestController()).webFilter(new WebFilterChainProxy(securityWebFilter)).build();
    WebDriver driver = WebTestClientHtmlUnitDriverBuilder.webTestClientSetup(webTestClient).build();
    // @formatter:on
    DefaultLoginPage loginPage = SecuredPage.to(driver, DefaultLoginPage.class).assertAt();
    // @formatter:off
    HomePage securedPage = loginPage.loginForm().username("user").password("password").submit(HomePage.class);
    // @formatter:on
    securedPage.assertAt();
}
Also used : ServerHttpSecurityConfigurationBuilder(org.springframework.security.config.annotation.web.reactive.ServerHttpSecurityConfigurationBuilder) WebDriver(org.openqa.selenium.WebDriver) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HomePage(org.springframework.security.config.web.server.FormLoginTests.HomePage) Controller(org.springframework.stereotype.Controller) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) WebFilterChainProxy(org.springframework.security.web.server.WebFilterChainProxy) ServerWebExchange(org.springframework.web.server.ServerWebExchange) Test(org.junit.jupiter.api.Test) WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) WebTestClientHtmlUnitDriverBuilder(org.springframework.security.htmlunit.server.WebTestClientHtmlUnitDriverBuilder) SecurityWebFilterChain(org.springframework.security.web.server.SecurityWebFilterChain) GetMapping(org.springframework.web.bind.annotation.GetMapping) Customizer.withDefaults(org.springframework.security.config.Customizer.withDefaults) WebTestClientBuilder(org.springframework.security.test.web.reactive.server.WebTestClientBuilder) NoOpServerRequestCache(org.springframework.security.web.server.savedrequest.NoOpServerRequestCache) PageFactory(org.openqa.selenium.support.PageFactory) DefaultLoginPage(org.springframework.security.config.web.server.FormLoginTests.DefaultLoginPage) WebTestClientBuilder(org.springframework.security.test.web.reactive.server.WebTestClientBuilder) WebDriver(org.openqa.selenium.WebDriver) HomePage(org.springframework.security.config.web.server.FormLoginTests.HomePage) WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) WebFilterChainProxy(org.springframework.security.web.server.WebFilterChainProxy) DefaultLoginPage(org.springframework.security.config.web.server.FormLoginTests.DefaultLoginPage) SecurityWebFilterChain(org.springframework.security.web.server.SecurityWebFilterChain) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 WebDriver (org.openqa.selenium.WebDriver)2 DefaultLoginPage (org.springframework.security.config.web.server.FormLoginTests.DefaultLoginPage)2 HomePage (org.springframework.security.config.web.server.FormLoginTests.HomePage)2 WebTestClientBuilder (org.springframework.security.test.web.reactive.server.WebTestClientBuilder)2 SecurityWebFilterChain (org.springframework.security.web.server.SecurityWebFilterChain)2 WebFilterChainProxy (org.springframework.security.web.server.WebFilterChainProxy)2 WebTestClient (org.springframework.test.web.reactive.server.WebTestClient)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 PageFactory (org.openqa.selenium.support.PageFactory)1 Customizer.withDefaults (org.springframework.security.config.Customizer.withDefaults)1 ServerHttpSecurityConfigurationBuilder (org.springframework.security.config.annotation.web.reactive.ServerHttpSecurityConfigurationBuilder)1 WebTestClientHtmlUnitDriverBuilder (org.springframework.security.htmlunit.server.WebTestClientHtmlUnitDriverBuilder)1 NoOpServerRequestCache (org.springframework.security.web.server.savedrequest.NoOpServerRequestCache)1 Controller (org.springframework.stereotype.Controller)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 ServerWebExchange (org.springframework.web.server.ServerWebExchange)1