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 Details

    • roles

      Specify the roles of the user to authenticate as. This method is similar to authorities(GrantedAuthority...), but just not as flexible.
      Parameters:
      roles - The roles to populate. Note that if the role does not start with ROLE_PREFIX it will automatically be prepended. This means by default roles("ROLE_USER") and roles("USER") are equivalent.
      Returns:
      the UserRequestPostProcessor for further customizations
      See Also:
    • authorities

      public SecurityMockMvcRequestPostProcessors.UserRequestPostProcessor authorities(org.springframework.security.core.GrantedAuthority... authorities)
      Populates the user's GrantedAuthority'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's GrantedAuthority'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:
      postProcessRequest in interface org.springframework.test.web.servlet.request.RequestPostProcessor