Class SecurityMockMvcRequestPostProcessors
java.lang.Object
org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors
Contains
MockMvc RequestPostProcessor implementations for Spring
Security.- Since:
- 4.0
- Author:
- Rob Winch
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classPopulates a validCsrfTokeninto the request.static classstatic final classCreates aUsernamePasswordAuthenticationTokenand sets the principal to be aUserand associates it to theMockHttpServletRequest. -
Method Summary
Modifier and TypeMethodDescriptionstatic org.springframework.test.web.servlet.request.RequestPostProcessorauthentication(org.springframework.security.core.Authentication authentication) Establish aSecurityContextthat uses the specifiedAuthenticationfor theAuthentication.getPrincipal()and a customUserDetails.csrf()Creates aRequestPostProcessorthat will automatically populate a validCsrfTokenin the request.digest()Creates a DigestRequestPostProcessor that enables easily adding digest based authentication to a request.Creates a DigestRequestPostProcessor that enables easily adding digest based authentication to a request.static org.springframework.test.web.servlet.request.RequestPostProcessorConvenience mechanism for setting the Authorization header to use HTTP Basic with the given username and password.static org.springframework.test.web.servlet.request.RequestPostProcessorsecurityContext(org.springframework.security.core.context.SecurityContext securityContext) Establish the specifiedSecurityContextto be used.static org.springframework.test.web.servlet.request.RequestPostProcessorCreates aRequestPostProcessorthat can be used to ensure that the resulting request is ran with the user in theTestSecurityContextHolder.Establish aSecurityContextthat has aUsernamePasswordAuthenticationTokenfor theAuthentication.getPrincipal()and aUserfor theUsernamePasswordAuthenticationToken.getPrincipal().static org.springframework.test.web.servlet.request.RequestPostProcessoruser(org.springframework.security.core.userdetails.UserDetails user) Establish aSecurityContextthat has aUsernamePasswordAuthenticationTokenfor theAuthentication.getPrincipal()and a customUserDetailsfor theUsernamePasswordAuthenticationToken.getPrincipal().static org.springframework.test.web.servlet.request.RequestPostProcessorFinds an X509Cetificate using a resoureName and populates it on the request.static org.springframework.test.web.servlet.request.RequestPostProcessorx509(X509Certificate... certificates) Populates the provided X509Certificate instances on the request.
-
Method Details
-
digest
Creates a DigestRequestPostProcessor that enables easily adding digest based authentication to a request.- Returns:
- the DigestRequestPostProcessor to use
-
digest
public static SecurityMockMvcRequestPostProcessors.DigestRequestPostProcessor digest(String username) Creates a DigestRequestPostProcessor that enables easily adding digest based authentication to a request.- Parameters:
username- the username to use- Returns:
- the DigestRequestPostProcessor to use
-
x509
public static org.springframework.test.web.servlet.request.RequestPostProcessor x509(X509Certificate... certificates) Populates the provided X509Certificate instances on the request.- Parameters:
certificates- the X509Certificate instances to pouplate- Returns:
- the
RequestPostProcessorto use.
-
x509
public static org.springframework.test.web.servlet.request.RequestPostProcessor x509(String resourceName) throws IOException, CertificateException Finds an X509Cetificate using a resoureName and populates it on the request.- Parameters:
resourceName- the name of the X509Certificate resource- Returns:
- the
RequestPostProcessorto use. - Throws:
IOExceptionCertificateException
-
csrf
Creates aRequestPostProcessorthat will automatically populate a validCsrfTokenin the request.- Returns:
- the
SecurityMockMvcRequestPostProcessors.CsrfRequestPostProcessorfor further customizations.
-
testSecurityContext
public static org.springframework.test.web.servlet.request.RequestPostProcessor testSecurityContext()Creates aRequestPostProcessorthat can be used to ensure that the resulting request is ran with the user in theTestSecurityContextHolder.- Returns:
- the
RequestPostProcessorto sue
-
user
Establish aSecurityContextthat has aUsernamePasswordAuthenticationTokenfor theAuthentication.getPrincipal()and aUserfor theUsernamePasswordAuthenticationToken.getPrincipal(). All details are declarative and do not require that the user actually exists.- Parameters:
username- the username to populate- Returns:
- the
SecurityMockMvcRequestPostProcessors.UserRequestPostProcessorfor additional customization
-
user
public static org.springframework.test.web.servlet.request.RequestPostProcessor user(org.springframework.security.core.userdetails.UserDetails user) Establish aSecurityContextthat has aUsernamePasswordAuthenticationTokenfor theAuthentication.getPrincipal()and a customUserDetailsfor theUsernamePasswordAuthenticationToken.getPrincipal(). All details are declarative and do not require that the user actually exists.- Parameters:
user- the UserDetails to populate- Returns:
- the
RequestPostProcessorto use
-
authentication
public static org.springframework.test.web.servlet.request.RequestPostProcessor authentication(org.springframework.security.core.Authentication authentication) Establish aSecurityContextthat uses the specifiedAuthenticationfor theAuthentication.getPrincipal()and a customUserDetails. All details are declarative and do not require that the user actually exists.- Parameters:
authentication- the Authentication to populate- Returns:
- the
RequestPostProcessorto use
-
securityContext
public static org.springframework.test.web.servlet.request.RequestPostProcessor securityContext(org.springframework.security.core.context.SecurityContext securityContext) Establish the specifiedSecurityContextto be used. -
httpBasic
public static org.springframework.test.web.servlet.request.RequestPostProcessor httpBasic(String username, String password) Convenience mechanism for setting the Authorization header to use HTTP Basic with the given username and password. This method will automatically perform the necessary Base64 encoding.- Parameters:
username- the username to include in the Authorization header.password- the password to include in the Authorization header.- Returns:
- the
RequestPostProcessorto use
-