Annotation Type WithMockTenantUser


@Target({METHOD,TYPE}) @Retention(RUNTIME) @Inherited @Documented @WithSecurityContext(factory=WithMockTenantUserSecurityContextFactory.class) public @interface WithMockTenantUser
When used with WithSecurityContextTestExecutionListener this annotation can be added to a test method to emulate running with a SecurityPrincipal. In order to work with MockMvc The SecurityContext that is used will have the following properties:
  • The SecurityContext created with be that of SecurityContextHolder.createEmptyContext()
  • It will be populated with an UsernamePasswordAuthenticationToken that uses the username of value() and the tenant of tenant().
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The authorities to use.
    The roles to use.
    org.springframework.security.test.context.support.TestExecutionEvent
     
    The tenant identifier to be used.
    The username to be used.
    Convenience mechanism for specifying the username.
  • Element Details

    • tenant

      String tenant
      The tenant identifier to be used. The default is "public".
      Returns:
      the tenant identifier value.
      Default:
      "public"
    • value

      String value
      Convenience mechanism for specifying the username. The default is "user". If username() is specified it will be used instead of value().
      Returns:
      the username value.
      Default:
      "user"
    • username

      String username
      The username to be used. Note that value() is a synonym for username(), but if username() is specified it will take precedence.
      Returns:
      the username value.
      Default:
      ""
    • roles

      String[] roles

      The roles to use. The default is "USER". A GrantedAuthority will be created for each value within roles. Each value in roles will automatically be prefixed with "ROLE_". For example, the default will result in "ROLE_USER" being used.

      If authorities() is specified this property cannot be changed from the default.

      Returns:
      the array of roles.
      Default:
      {"USER"}
    • authorities

      String[] authorities

      The authorities to use. A GrantedAuthority will be created for each value.

      If this property is specified then roles() is not used. This differs from roles() in that it does not prefix the values passed in automatically.

      Returns:
      the array of authorities.
      Default:
      {}
    • setupBefore

      @AliasFor(annotation=org.springframework.security.test.context.support.WithSecurityContext.class) org.springframework.security.test.context.support.TestExecutionEvent setupBefore
      See Also:
      • WithSecurityContext.setupBefore()
      Default:
      TEST_METHOD