Class SecurityMockMvcRequestPostProcessors.UserRequestPostProcessor
java.lang.Object
org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.UserRequestPostProcessor
- All Implemented Interfaces:
org.springframework.test.web.servlet.request.RequestPostProcessor
- Enclosing class:
- SecurityMockMvcRequestPostProcessors
public static final class SecurityMockMvcRequestPostProcessors.UserRequestPostProcessor
extends Object
implements org.springframework.test.web.servlet.request.RequestPostProcessor
Creates a
UsernamePasswordAuthenticationToken and sets the principal to be
a User and associates it to the MockHttpServletRequest.- Since:
- 4.0
-
Method Summary
Modifier and TypeMethodDescriptionauthorities(Collection<? extends org.springframework.security.core.GrantedAuthority> authorities) Populates the user'sGrantedAuthority's.authorities(org.springframework.security.core.GrantedAuthority... authorities) Populates the user'sGrantedAuthority's.Populates the user's password.org.springframework.mock.web.MockHttpServletRequestpostProcessRequest(org.springframework.mock.web.MockHttpServletRequest request) Specify the roles of the user to authenticate as.
-
Method Details
-
roles
Specify the roles of the user to authenticate as. This method is similar toauthorities(GrantedAuthority...), but just not as flexible.- Parameters:
roles- The roles to populate. Note that if the role does not start withROLE_PREFIXit will automatically be prepended. This means by defaultroles("ROLE_USER")androles("USER")are equivalent.- Returns:
- the UserRequestPostProcessor for further customizations
- See Also:
-
authorities(GrantedAuthority...)ROLE_PREFIX
-
authorities
public SecurityMockMvcRequestPostProcessors.UserRequestPostProcessor authorities(org.springframework.security.core.GrantedAuthority... authorities) Populates the user'sGrantedAuthority's. The default is ROLE_USER.- Parameters:
authorities-- Returns:
- the UserRequestPostProcessor for further customizations
- See Also:
-
authorities
public SecurityMockMvcRequestPostProcessors.UserRequestPostProcessor authorities(Collection<? extends org.springframework.security.core.GrantedAuthority> authorities) Populates the user'sGrantedAuthority's. The default is ROLE_USER.- Parameters:
authorities-- Returns:
- the UserRequestPostProcessor for further customizations
- See Also:
-
password
Populates the user's password. The default is "password"- Parameters:
password- the user's password- Returns:
- the UserRequestPostProcessor for further customizations
-
postProcessRequest
public org.springframework.mock.web.MockHttpServletRequest postProcessRequest(org.springframework.mock.web.MockHttpServletRequest request) - Specified by:
postProcessRequestin interfaceorg.springframework.test.web.servlet.request.RequestPostProcessor
-