Annotation Interface WithMockOAuth2
@Retention(RUNTIME)
@Documented
@WithSecurityContext(factory=WithMockOAuth2SecurityContextFactory.class)
public @interface WithMockOAuth2
Simulates OAuth2 scopes to help with endpoint testing with Spring Security. This is designed to
mimic exactly what the
OAuth2ResourceWebSecurityConfiguration
does through its autoconfiguration, along with OAuth token expectations that come back from the
auth server, from the ScopeFilteringAccessTokenConverter.
If you are using MockMvc
this will not work if OAuth is configured to run stateless (the
default). In that case, you must instead inject the MockMvcOAuth2AuthenticationUtil
instead.
- Author:
- Phillip Verheyden (phillipuniverse)
- See Also:
-
Optional Element Summary
Optional Elements
-
Element Details
-
value
Alias forscopes()
.This attribute may not be used in conjunction with
scopes()
, but it may be used instead ofscopes()
.- See Also:
- Default:
- {}
-
scopes
The scopes that should be mocked on the authentication- Returns:
- scopes on the security context
- Default:
- {}
-
principal
String principalThe user principal.- Default:
- ""
-
authorities
String[] authoritiesAdditional security authorities assigned to the token- Returns:
- security roles for the token
- Default:
- {}
-
authDetails
AuthDetail[] authDetailsAdditional auth details assigned to the token beyond any default values. For example, setting a detail with the value, 'customer_id'@WithMockOAuth2(scopes = "USER", authorities = {"READ_CUSTOMER", "UPDATE_CUSTOMER"}, authDetails = { @AuthDetail(key = "customer_id", value = "1234") })
- Returns:
- Auth details to set
- Default:
- {}
-