Annotation Type WithMockUser
-
@Target({METHOD,TYPE}) @Retention(RUNTIME) @Inherited @Documented @WithSecurityContext(factory=org.springframework.security.test.context.support.WithMockUserSecurityContextFactory.class) public @interface WithMockUser
When used withWithSecurityContextTestExecutionListener
this annotation can be added to a test method to emulate running with a mocked user. 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 of eithervalue()
orusername()
,GrantedAuthority
that are specified byroles()
, and a password specified bypassword()
.
- Since:
- 4.0
- Author:
- Rob Winch
- See Also:
WithUserDetails
- The
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description String[]
authorities
The authorities to use.String
password
The password to be used.String[]
roles
The roles to use.String
username
The username to be used.String
value
Convenience mechanism for specifying the username.
-
-
-
Element Detail
-
value
String value
Convenience mechanism for specifying the username. The default is "user". Ifusername()
is specified it will be used instead ofvalue()
- Returns:
- Default:
- "user"
-
-
-
username
String username
The username to be used. Note thatvalue()
is a synonym forusername()
, but ifusername()
is specified it will take precedence.- Returns:
- 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:
- Default:
- {"USER"}
-
-
-
password
String password
The password to be used. The default is "password".- Returns:
- Default:
- "password"
-
-