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.DigestRequestPostProcessor |
static class |
SecurityMockMvcRequestPostProcessors.UserRequestPostProcessor
Creates a
UsernamePasswordAuthenticationToken and sets the
principal to be a User and associates it to the
MockHttpServletRequest. |
| Modifier and Type | Method and Description |
|---|---|
static RequestPostProcessor |
authentication(Authentication authentication)
Establish a
SecurityContext that uses the specified Authentication for the
Authentication.getPrincipal() and a custom UserDetails. |
static SecurityMockMvcRequestPostProcessors.CsrfRequestPostProcessor |
csrf()
Creates a
RequestPostProcessor that will automatically populate a
valid CsrfToken in the request. |
static SecurityMockMvcRequestPostProcessors.DigestRequestPostProcessor |
digest()
Creates a DigestRequestPostProcessor that enables easily adding digest based authentication to a request.
|
static SecurityMockMvcRequestPostProcessors.DigestRequestPostProcessor |
digest(String username)
Creates a DigestRequestPostProcessor that enables easily adding digest based authentication to a request.
|
static RequestPostProcessor |
httpBasic(String username,
String password)
Convenience mechanism for setting the Authorization header to use HTTP
Basic with the given username and password.
|
static RequestPostProcessor |
securityContext(SecurityContext securityContext)
Establish the specified
SecurityContext to be used. |
static RequestPostProcessor |
testSecurityContext()
Creates a
RequestPostProcessor that can be used to ensure that
the resulting request is ran with the user in the
TestSecurityContextHolder. |
static SecurityMockMvcRequestPostProcessors.UserRequestPostProcessor |
user(String username)
Establish a
SecurityContext that has a
UsernamePasswordAuthenticationToken for the
Authentication.getPrincipal() and a User for the
UsernamePasswordAuthenticationToken.getPrincipal(). |
static RequestPostProcessor |
user(UserDetails user)
Establish a
SecurityContext that has a
UsernamePasswordAuthenticationToken for the
Authentication.getPrincipal() and a custom UserDetails
for the UsernamePasswordAuthenticationToken.getPrincipal(). |
static RequestPostProcessor |
x509(String resourceName)
Finds an X509Cetificate using a resoureName and populates it on the request.
|
static RequestPostProcessor |
x509(X509Certificate... certificates)
Populates the provided X509Certificate instances on the request.
|
public static SecurityMockMvcRequestPostProcessors.DigestRequestPostProcessor digest()
public static SecurityMockMvcRequestPostProcessors.DigestRequestPostProcessor digest(String username)
username - the username to usepublic static RequestPostProcessor x509(X509Certificate... certificates)
certificates - the X509Certificate instances to pouplateRequestPostProcessor to use.public static RequestPostProcessor x509(String resourceName) throws IOException, CertificateException
resourceName - the name of the X509Certificate resourceRequestPostProcessor to use.IOExceptionCertificateExceptionpublic 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