mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-29 07:12:32 +00:00
Merge branch '6.1.x' into 6.2.x
Closes gh-14805
This commit is contained in:
commit
6f8cc920cd
@ -876,7 +876,7 @@ class SpaCsrfTokenRequestHandler : CsrfTokenRequestAttributeHandler() {
|
|||||||
delegate.handle(request, response, csrfToken)
|
delegate.handle(request, response, csrfToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun resolveCsrfTokenValue(request: HttpServletRequest, csrfToken: CsrfToken): String {
|
override fun resolveCsrfTokenValue(request: HttpServletRequest, csrfToken: CsrfToken): String? {
|
||||||
/*
|
/*
|
||||||
* If the request contains a request header, use CsrfTokenRequestAttributeHandler
|
* If the request contains a request header, use CsrfTokenRequestAttributeHandler
|
||||||
* to resolve the CsrfToken. This applies when a single-page application includes
|
* to resolve the CsrfToken. This applies when a single-page application includes
|
||||||
@ -1221,6 +1221,24 @@ public class CsrfTests {
|
|||||||
.andExpect(header().string(HttpHeaders.LOCATION, "/"));
|
.andExpect(header().string(HttpHeaders.LOCATION, "/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void loginWhenInvalidCsrfTokenThenForbidden() throws Exception {
|
||||||
|
this.mockMvc.perform(post("/login").with(csrf().useInvalidToken())
|
||||||
|
.accept(MediaType.TEXT_HTML)
|
||||||
|
.param("username", "user")
|
||||||
|
.param("password", "password"))
|
||||||
|
.andExpect(status().isForbidden());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void loginWhenMissingCsrfTokenThenForbidden() throws Exception {
|
||||||
|
this.mockMvc.perform(post("/login")
|
||||||
|
.accept(MediaType.TEXT_HTML)
|
||||||
|
.param("username", "user")
|
||||||
|
.param("password", "password"))
|
||||||
|
.andExpect(status().isForbidden());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithMockUser
|
@WithMockUser
|
||||||
public void logoutWhenValidCsrfTokenThenSuccess() throws Exception {
|
public void logoutWhenValidCsrfTokenThenSuccess() throws Exception {
|
||||||
@ -1264,6 +1282,24 @@ class CsrfTests {
|
|||||||
.andExpect(header().string(HttpHeaders.LOCATION, "/"))
|
.andExpect(header().string(HttpHeaders.LOCATION, "/"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun loginWhenInvalidCsrfTokenThenForbidden() {
|
||||||
|
mockMvc.perform(post("/login").with(csrf().useInvalidToken())
|
||||||
|
.accept(MediaType.TEXT_HTML)
|
||||||
|
.param("username", "user")
|
||||||
|
.param("password", "password"))
|
||||||
|
.andExpect(status().isForbidden)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun loginWhenMissingCsrfTokenThenForbidden() {
|
||||||
|
mockMvc.perform(post("/login")
|
||||||
|
.accept(MediaType.TEXT_HTML)
|
||||||
|
.param("username", "user")
|
||||||
|
.param("password", "password"))
|
||||||
|
.andExpect(status().isForbidden)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithMockUser
|
@WithMockUser
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user