Class OAuth2AuthorizationContext
- java.lang.Object
-
- org.springframework.security.oauth2.client.OAuth2AuthorizationContext
-
public final class OAuth2AuthorizationContext extends java.lang.Object
A context that holds authorization-specific state and is used by anOAuth2AuthorizedClientProvider
when attempting to authorize (or re-authorize) an OAuth 2.0 Client.- Since:
- 5.2
- See Also:
OAuth2AuthorizedClientProvider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
OAuth2AuthorizationContext.Builder
A builder forOAuth2AuthorizationContext
.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
PASSWORD_ATTRIBUTE_NAME
The name of theattribute
in the context associated to the value for the resource owner's password.static java.lang.String
REQUEST_SCOPE_ATTRIBUTE_NAME
The name of theattribute
in the context associated to the value for the "request scope(s)".static java.lang.String
USERNAME_ATTRIBUTE_NAME
The name of theattribute
in the context associated to the value for the resource owner's username.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
getAttribute(java.lang.String name)
Returns the value of an attribute associated to the context ornull
if not available.java.util.Map<java.lang.String,java.lang.Object>
getAttributes()
Returns the attributes associated to the context.OAuth2AuthorizedClient
getAuthorizedClient()
ClientRegistration
getClientRegistration()
Returns theclient registration
.Authentication
getPrincipal()
Returns thePrincipal
(to be) associated to the authorized client.static OAuth2AuthorizationContext.Builder
withAuthorizedClient(OAuth2AuthorizedClient authorizedClient)
Returns a newOAuth2AuthorizationContext.Builder
initialized with theOAuth2AuthorizedClient
.static OAuth2AuthorizationContext.Builder
withClientRegistration(ClientRegistration clientRegistration)
Returns a newOAuth2AuthorizationContext.Builder
initialized with theClientRegistration
.
-
-
-
Field Detail
-
REQUEST_SCOPE_ATTRIBUTE_NAME
public static final java.lang.String REQUEST_SCOPE_ATTRIBUTE_NAME
-
USERNAME_ATTRIBUTE_NAME
public static final java.lang.String USERNAME_ATTRIBUTE_NAME
The name of theattribute
in the context associated to the value for the resource owner's username.
-
PASSWORD_ATTRIBUTE_NAME
public static final java.lang.String PASSWORD_ATTRIBUTE_NAME
The name of theattribute
in the context associated to the value for the resource owner's password.
-
-
Method Detail
-
getClientRegistration
public ClientRegistration getClientRegistration()
Returns theclient registration
.- Returns:
- the
ClientRegistration
-
getAuthorizedClient
@Nullable public OAuth2AuthorizedClient getAuthorizedClient()
- Returns:
- the
OAuth2AuthorizedClient
ornull
if the client registration was supplied
-
getPrincipal
public Authentication getPrincipal()
Returns thePrincipal
(to be) associated to the authorized client.- Returns:
- the
Principal
(to be) associated to the authorized client
-
getAttributes
public java.util.Map<java.lang.String,java.lang.Object> getAttributes()
Returns the attributes associated to the context.- Returns:
- a
Map
of the attributes associated to the context
-
getAttribute
@Nullable public <T> T getAttribute(java.lang.String name)
Returns the value of an attribute associated to the context ornull
if not available.- Type Parameters:
T
- the type of the attribute- Parameters:
name
- the name of the attribute- Returns:
- the value of the attribute associated to the context
-
withClientRegistration
public static OAuth2AuthorizationContext.Builder withClientRegistration(ClientRegistration clientRegistration)
Returns a newOAuth2AuthorizationContext.Builder
initialized with theClientRegistration
.- Parameters:
clientRegistration
- theclient registration
- Returns:
- the
OAuth2AuthorizationContext.Builder
-
withAuthorizedClient
public static OAuth2AuthorizationContext.Builder withAuthorizedClient(OAuth2AuthorizedClient authorizedClient)
Returns a newOAuth2AuthorizationContext.Builder
initialized with theOAuth2AuthorizedClient
.- Parameters:
authorizedClient
- theauthorized client
- Returns:
- the
OAuth2AuthorizationContext.Builder
-
-