Search in sources :

Example 1 with CsrfToken

use of org.springframework.security.web.server.csrf.CsrfToken in project spring-security by spring-projects.

the class LoginPageGeneratingWebFilter method createBuffer.

private Mono<DataBuffer> createBuffer(ServerWebExchange exchange) {
    Mono<CsrfToken> token = exchange.getAttributeOrDefault(CsrfToken.class.getName(), Mono.empty());
    return token.map(LoginPageGeneratingWebFilter::csrfToken).defaultIfEmpty("").map((csrfTokenHtmlInput) -> {
        byte[] bytes = createPage(exchange, csrfTokenHtmlInput);
        DataBufferFactory bufferFactory = exchange.getResponse().bufferFactory();
        return bufferFactory.wrap(bytes);
    });
}
Also used : CsrfToken(org.springframework.security.web.server.csrf.CsrfToken) DataBufferFactory(org.springframework.core.io.buffer.DataBufferFactory)

Example 2 with CsrfToken

use of org.springframework.security.web.server.csrf.CsrfToken in project spring-security by spring-projects.

the class LogoutPageGeneratingWebFilter method createBuffer.

private Mono<DataBuffer> createBuffer(ServerWebExchange exchange) {
    Mono<CsrfToken> token = exchange.getAttributeOrDefault(CsrfToken.class.getName(), Mono.empty());
    return token.map(LogoutPageGeneratingWebFilter::csrfToken).defaultIfEmpty("").map((csrfTokenHtmlInput) -> {
        byte[] bytes = createPage(csrfTokenHtmlInput);
        DataBufferFactory bufferFactory = exchange.getResponse().bufferFactory();
        return bufferFactory.wrap(bytes);
    });
}
Also used : CsrfToken(org.springframework.security.web.server.csrf.CsrfToken) DataBufferFactory(org.springframework.core.io.buffer.DataBufferFactory)

Example 3 with CsrfToken

use of org.springframework.security.web.server.csrf.CsrfToken in project spring-security by spring-projects.

the class CsrfRequestDataValueProcessorTests method createGetExtraHiddenFieldsHasCsrfToken.

@Test
public void createGetExtraHiddenFieldsHasCsrfToken() {
    CsrfToken token = new DefaultCsrfToken("1", "a", "b");
    this.exchange.getAttributes().put(CsrfRequestDataValueProcessor.DEFAULT_CSRF_ATTR_NAME, token);
    Map<String, String> expected = new HashMap<>();
    expected.put(token.getParameterName(), token.getToken());
    CsrfRequestDataValueProcessor processor = new CsrfRequestDataValueProcessor();
    assertThat(this.processor.getExtraHiddenFields(this.exchange)).isEqualTo(expected);
}
Also used : HashMap(java.util.HashMap) DefaultCsrfToken(org.springframework.security.web.server.csrf.DefaultCsrfToken) DefaultCsrfToken(org.springframework.security.web.server.csrf.DefaultCsrfToken) CsrfToken(org.springframework.security.web.server.csrf.CsrfToken) Test(org.junit.jupiter.api.Test)

Aggregations

CsrfToken (org.springframework.security.web.server.csrf.CsrfToken)3 DataBufferFactory (org.springframework.core.io.buffer.DataBufferFactory)2 HashMap (java.util.HashMap)1 Test (org.junit.jupiter.api.Test)1 DefaultCsrfToken (org.springframework.security.web.server.csrf.DefaultCsrfToken)1