Annotation Interface WithOAuth2Login
@Target({METHOD,TYPE})
@Retention(RUNTIME)
@Inherited
@Documented
@WithSecurityContext(factory=OAuth2AuthenticationTokenFactory.class)
public @interface WithOAuth2Login
Populates the test security context with an OAuth2AuthenticationToken instance with a
DefaultOAuth2User as principal.
Only the annotation properties are used to build the authentication Instance. Neither
OAuth2UserService nor GrantedAuthoritiesMapper are called.
@WithOAuth2Login({"BIDULE", "CHOSE"})
Advanced usage to set any claims, including private ones:
@WithOAuth2Login(
authorities = {"NICE"},
nameAttributeKey = StandardClaimNames.PREFERRED_USERNAME,
claims = @OpenIdClaims(
preferredUsername = "tonton-pirate",
email = "tonton@c4-soft.com",
otherClaims = @Claims(
stringClaims = { @StringClaim(name = "machin", value = "truc") })))
- Author:
- ch4mp@c4-soft.com
-
Element Details
-
value
- Default:
- {}
-
authorities
- Default:
- {}
-
claims
OpenIdClaims claims- Default:
- @com.c4_soft.springaddons.security.oauth2.test.annotations.OpenIdClaims
-
tokenString
String tokenString- Default:
- "machin.truc.chose"
-
authorizedClientRegistrationId
String authorizedClientRegistrationId- Default:
- "bidule"
-
nameAttributeKey
String nameAttributeKey- Returns:
- the key used to access the user's "name" from claims. This takes precedence over OpenIdClaims::usernameClaim if both are defined
- Default:
- "sub"
-
setupBefore
@AliasFor(annotation=org.springframework.security.test.context.support.WithSecurityContext.class) org.springframework.security.test.context.support.TestExecutionEvent setupBefore- Default:
- TEST_METHOD
-