public final class SecurityMockMvcRequestPostProcessors extends Object
MockMvc RequestPostProcessor implementations for
Spring Security.| Modifier and Type | Class and Description |
|---|---|
static class |
SecurityMockMvcRequestPostProcessors.CsrfRequestPostProcessor
Populates a valid
CsrfToken into the request. |
static class |
SecurityMockMvcRequestPostProcessors.UserRequestPostProcessor
Creates a
UsernamePasswordAuthenticationToken and sets the
principal to be a User and associates it to the
MockHttpServletRequest. |
public static SecurityMockMvcRequestPostProcessors.CsrfRequestPostProcessor csrf()
RequestPostProcessor that will automatically populate a
valid CsrfToken in the request.SecurityMockMvcRequestPostProcessors.CsrfRequestPostProcessor for further customizations.public static RequestPostProcessor testSecurityContext()
RequestPostProcessor that can be used to ensure that
the resulting request is ran with the user in the
TestSecurityContextHolder.RequestPostProcessor to suepublic static SecurityMockMvcRequestPostProcessors.UserRequestPostProcessor user(String username)
SecurityContext that has a
UsernamePasswordAuthenticationToken for the
Authentication.getPrincipal() and a User for the
UsernamePasswordAuthenticationToken.getPrincipal(). All details
are declarative and do not require that the user actually exists.username - the username to populateSecurityMockMvcRequestPostProcessors.UserRequestPostProcessor for additional customizationpublic static RequestPostProcessor user(UserDetails user)
SecurityContext that has a
UsernamePasswordAuthenticationToken for the
Authentication.getPrincipal() and a custom UserDetails
for the UsernamePasswordAuthenticationToken.getPrincipal(). All
details are declarative and do not require that the user actually exists.user - the UserDetails to populateRequestPostProcessor to usepublic static RequestPostProcessor authentication(Authentication authentication)
SecurityContext that uses the specified Authentication for the
Authentication.getPrincipal() and a custom UserDetails. All
details are declarative and do not require that the user actually exists.user - the UserDetails to populateRequestPostProcessor to usepublic static RequestPostProcessor securityContext(SecurityContext securityContext)
SecurityContext to be used.public static RequestPostProcessor httpBasic(String username, String password)
username - the username to include in the Authorization header.password - the password to include in the Authorization header.RequestPostProcessor to use