@Target(value={METHOD,TYPE}) @Retention(value=RUNTIME) @Inherited @Documented @WithSecurityContext(factory=org.springframework.security.test.context.support.WithUserDetailsSecurityContextFactory.class) public @interface WithUserDetails
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:
SecurityContext
created with be that of
SecurityContextHolder.createEmptyContext()
UsernamePasswordAuthenticationToken
that uses
the username of value()
.
WithMockUser
Modifier and Type | Optional Element and Description |
---|---|
TestExecutionEvent |
setupBefore
Determines when the
SecurityContext is setup. |
java.lang.String |
userDetailsServiceBeanName
The bean name for the
UserDetailsService to use. |
java.lang.String |
value
The username to look up in the
UserDetailsService |
public abstract java.lang.String value
UserDetailsService
public abstract java.lang.String userDetailsServiceBeanName
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.UserDetailsService
to use.@AliasFor(annotation=WithSecurityContext.class) public abstract TestExecutionEvent setupBefore
SecurityContext
is setup. The default is before
TestExecutionEvent.TEST_METHOD
which occurs during
TestExecutionListener.beforeTestMethod(TestContext)
TestExecutionEvent
to initialize before