Annotation Type WithUserDetails
-
@Target({METHOD,TYPE}) @Retention(RUNTIME) @Inherited @Documented @WithSecurityContext(factory=org.springframework.security.test.context.support.WithUserDetailsSecurityContextFactory.class) public @interface WithUserDetails
When used withWithSecurityContextTestExecutionListener
this annotation can be added to a test method to emulate running with aUserDetails
returned from theUserDetailsService
. In order to work withMockMvc
TheSecurityContext
that is used will have the following properties:- The
SecurityContext
created with be that ofSecurityContextHolder.createEmptyContext()
- It will be populated with an
UsernamePasswordAuthenticationToken
that uses the username ofvalue()
.
- Since:
- 4.0
- See Also:
WithMockUser
- The
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description TestExecutionEvent
setupBefore
Determines when theSecurityContext
is setup.java.lang.String
userDetailsServiceBeanName
The bean name for theUserDetailsService
to use.java.lang.String
value
The username to look up in theUserDetailsService
-
-
-
Element Detail
-
value
java.lang.String value
The username to look up in theUserDetailsService
- Returns:
- Default:
- "user"
-
-
-
userDetailsServiceBeanName
java.lang.String userDetailsServiceBeanName
The bean name for theUserDetailsService
to use. If this is not provided, then the lookup is done by type and expects only a singleUserDetailsService
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 theSecurityContext
is setup. The default is beforeTestExecutionEvent.TEST_METHOD
which occurs duringTestExecutionListener.beforeTestMethod(TestContext)
- Returns:
- the
TestExecutionEvent
to initialize before - Since:
- 5.1
- Default:
- org.springframework.security.test.context.support.TestExecutionEvent.TEST_METHOD
-
-