@Target(value={METHOD,TYPE}) @Retention(value=RUNTIME) @Inherited @Documented @WithSecurityContext(factory=org.springframework.security.test.context.support.WithMockUserSecurityContextFactory.class) public @interface WithMockUser
WithSecurityContextTestExecutionListener this annotation can be
added to a test method to emulate running with a mocked user. 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 either value() or username(),
GrantedAuthority that are specified by roles(), and a
password specified by password().
WithUserDetailspublic abstract String value
username() is specified it will be used instead of value()public abstract String username
value() is a synonym for username(), but if username() is specified it will take precedence.public abstract String[] roles
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.public abstract String password