Annotation Interface WithUserDetails


@Target({METHOD,TYPE}) @Retention(RUNTIME) @Inherited @Documented @WithSecurityContext(factory=org.springframework.security.test.context.support.WithUserDetailsSecurityContextFactory.class) public @interface WithUserDetails
When used with WithSecurityContextTestExecutionListener this annotation can be added to a test method to emulate running with a UserDetails returned from the UserDetailsService. 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().
Since:
4.0
See Also:
  • Element Details

    • value

      String value
      The username to look up in the UserDetailsService
      Returns:
      Default:
      "user"
    • userDetailsServiceBeanName

      String userDetailsServiceBeanName
      The bean name for the UserDetailsService to use. If this is not provided, then the lookup is done by type and expects only a single UserDetailsService bean to be exposed.
      Returns:
      the bean name for the UserDetailsService to use.
      Since:
      4.1
      Default:
      ""
    • setupBefore

      @AliasFor(annotation=WithSecurityContext.class) TestExecutionEvent setupBefore
      Determines when the SecurityContext is setup. The default is before TestExecutionEvent.TEST_METHOD which occurs during TestExecutionListener.beforeTestMethod(TestContext)
      Returns:
      the TestExecutionEvent to initialize before
      Since:
      5.1
      Default:
      TEST_METHOD