Search in sources :

Example 1 with DefaultCsrfToken

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

the class AbstractSecurityWebSocketMessageBrokerConfigurerDocTests method setup.

@BeforeEach
public void setup() {
    this.token = new DefaultCsrfToken("header", "param", "token");
    this.sessionAttr = "sessionAttr";
    this.messageUser = new TestingAuthenticationToken("user", "pass", "ROLE_USER");
}
Also used : DefaultCsrfToken(org.springframework.security.web.csrf.DefaultCsrfToken) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with DefaultCsrfToken

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

the class AbstractSecurityWebSocketMessageBrokerConfigurerTests method setup.

@BeforeEach
public void setup() {
    this.token = new DefaultCsrfToken("header", "param", "token");
    this.sessionAttr = "sessionAttr";
    this.messageUser = new TestingAuthenticationToken("user", "pass", "ROLE_USER");
}
Also used : DefaultCsrfToken(org.springframework.security.web.csrf.DefaultCsrfToken) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with DefaultCsrfToken

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

the class DefaultCsrfTokenMixinTests method defaultCsrfTokenDeserializeTest.

@Test
public void defaultCsrfTokenDeserializeTest() throws IOException {
    DefaultCsrfToken token = this.mapper.readValue(CSRF_JSON, DefaultCsrfToken.class);
    assertThat(token).isNotNull();
    assertThat(token.getHeaderName()).isEqualTo("csrf-header");
    assertThat(token.getParameterName()).isEqualTo("_csrf");
    assertThat(token.getToken()).isEqualTo("1");
}
Also used : DefaultCsrfToken(org.springframework.security.web.csrf.DefaultCsrfToken) Test(org.junit.jupiter.api.Test)

Example 4 with DefaultCsrfToken

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

the class CsrfInputTagTests method handleTokenReturnsHiddenInput.

@Test
public void handleTokenReturnsHiddenInput() {
    CsrfToken token = new DefaultCsrfToken("X-Csrf-Token", "_csrf", "abc123def456ghi789");
    String value = this.tag.handleToken(token);
    assertThat(value).as("The returned value should not be null.").isNotNull();
    assertThat(value).withFailMessage("The output is not correct.").isEqualTo("<input type=\"hidden\" name=\"_csrf\" value=\"abc123def456ghi789\" />");
}
Also used : DefaultCsrfToken(org.springframework.security.web.csrf.DefaultCsrfToken) CsrfToken(org.springframework.security.web.csrf.CsrfToken) DefaultCsrfToken(org.springframework.security.web.csrf.DefaultCsrfToken) Test(org.junit.jupiter.api.Test)

Example 5 with DefaultCsrfToken

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

the class CsrfMetaTagsTagTests method handleTokenRendersTags.

@Test
public void handleTokenRendersTags() {
    CsrfToken token = new DefaultCsrfToken("X-Csrf-Token", "_csrf", "abc123def456ghi789");
    String value = this.tag.handleToken(token);
    assertThat(value).as("The returned value should not be null.").isNotNull();
    assertThat(value).withFailMessage("The output is not correct.").isEqualTo("<meta name=\"_csrf_parameter\" content=\"_csrf\" />" + "<meta name=\"_csrf_header\" content=\"X-Csrf-Token\" />" + "<meta name=\"_csrf\" content=\"abc123def456ghi789\" />");
}
Also used : DefaultCsrfToken(org.springframework.security.web.csrf.DefaultCsrfToken) CsrfToken(org.springframework.security.web.csrf.CsrfToken) DefaultCsrfToken(org.springframework.security.web.csrf.DefaultCsrfToken) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultCsrfToken (org.springframework.security.web.csrf.DefaultCsrfToken)31 Test (org.junit.jupiter.api.Test)21 CsrfToken (org.springframework.security.web.csrf.CsrfToken)18 BeforeEach (org.junit.jupiter.api.BeforeEach)6 HttpSessionCsrfTokenRepository (org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository)6 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 CsrfTokenRepository (org.springframework.security.web.csrf.CsrfTokenRepository)5 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 MockHttpSession (org.springframework.mock.web.MockHttpSession)3 MvcResult (org.springframework.test.web.servlet.MvcResult)3 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 MockFilterChain (org.springframework.mock.web.MockFilterChain)2 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)2 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)2 Filter (jakarta.servlet.Filter)1 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)1 Date (java.util.Date)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1