use of org.springframework.security.web.csrf.CsrfToken in project pigatron-web by pigatron-industries.
the class AdminSecurityControllerAdvice method getMetadata.
@ModelAttribute("metadata")
public Map<String, String> getMetadata(HttpServletRequest request) {
Map<String, String> metadata = new HashMap<>();
CsrfToken token = (CsrfToken) request.getAttribute("_csrf");
if (token != null) {
metadata.put("_csrf", token.getToken());
metadata.put("_csrf_header", token.getHeaderName());
}
return metadata;
}
use of org.springframework.security.web.csrf.CsrfToken in project spring-security by spring-projects.
the class SecurityMockMvcRequestBuildersFormLoginTests method defaults.
@Test
public void defaults() {
MockHttpServletRequest request = formLogin().buildRequest(this.servletContext);
CsrfToken token = (CsrfToken) request.getAttribute(CsrfRequestPostProcessor.TestCsrfTokenRepository.TOKEN_ATTR_NAME);
assertThat(request.getParameter("username")).isEqualTo("user");
assertThat(request.getParameter("password")).isEqualTo("password");
assertThat(request.getMethod()).isEqualTo("POST");
assertThat(request.getParameter(token.getParameterName())).isEqualTo(token.getToken());
assertThat(request.getRequestURI()).isEqualTo("/login");
assertThat(request.getParameter("_csrf")).isNotNull();
}
use of org.springframework.security.web.csrf.CsrfToken in project spring-security by spring-projects.
the class SecurityMockMvcRequestBuildersFormLoginTests method customWithUriVars.
@Test
public void customWithUriVars() {
MockHttpServletRequest request = formLogin().loginProcessingUrl("/uri-login/{var1}/{var2}", "val1", "val2").user("username", "admin").password("password", "secret").buildRequest(this.servletContext);
CsrfToken token = (CsrfToken) request.getAttribute(CsrfRequestPostProcessor.TestCsrfTokenRepository.TOKEN_ATTR_NAME);
assertThat(request.getParameter("username")).isEqualTo("admin");
assertThat(request.getParameter("password")).isEqualTo("secret");
assertThat(request.getMethod()).isEqualTo("POST");
assertThat(request.getParameter(token.getParameterName())).isEqualTo(token.getToken());
assertThat(request.getRequestURI()).isEqualTo("/uri-login/val1/val2");
}
use of org.springframework.security.web.csrf.CsrfToken in project spring-security by spring-projects.
the class SecurityMockMvcRequestBuildersFormLoginTests method custom.
@Test
public void custom() {
MockHttpServletRequest request = formLogin("/login").user("username", "admin").password("password", "secret").buildRequest(this.servletContext);
CsrfToken token = (CsrfToken) request.getAttribute(CsrfRequestPostProcessor.TestCsrfTokenRepository.TOKEN_ATTR_NAME);
assertThat(request.getParameter("username")).isEqualTo("admin");
assertThat(request.getParameter("password")).isEqualTo("secret");
assertThat(request.getMethod()).isEqualTo("POST");
assertThat(request.getParameter(token.getParameterName())).isEqualTo(token.getToken());
assertThat(request.getRequestURI()).isEqualTo("/login");
}
use of org.springframework.security.web.csrf.CsrfToken in project spring-security by spring-projects.
the class SecurityMockMvcRequestBuildersFormLogoutTests method customWithUriVars.
@Test
public void customWithUriVars() {
MockHttpServletRequest request = logout().logoutUrl("/uri-logout/{var1}/{var2}", "val1", "val2").buildRequest(this.servletContext);
CsrfToken token = (CsrfToken) request.getAttribute(CsrfRequestPostProcessor.TestCsrfTokenRepository.TOKEN_ATTR_NAME);
assertThat(request.getMethod()).isEqualTo("POST");
assertThat(request.getParameter(token.getParameterName())).isEqualTo(token.getToken());
assertThat(request.getRequestURI()).isEqualTo("/uri-logout/val1/val2");
}
Aggregations