Class GoogleOAuthClientAuthenticationStrategyDelegate
java.lang.Object
com.broadleafcommerce.auth.user.web.authentication.session.AbstractAuthenticationStrategyDelegate<org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken>
com.broadleafcommerce.auth.client.web.authentication.session.AbstractOAuthClientAuthenticationStrategyDelegate
com.broadleafcommerce.auth.client.web.authentication.session.GoogleOAuthClientAuthenticationStrategyDelegate
- All Implemented Interfaces:
AuthenticationStrategyDelegate
public class GoogleOAuthClientAuthenticationStrategyDelegate
extends AbstractOAuthClientAuthenticationStrategyDelegate
Maps
OAuth2AuthenticationToken
from Google to OAuth2UserDetails
. This
implementation overrides the default behavior of #buildUserRegistration to check that email
addresses have been verified before using them for registration.- Author:
- Cade Rea (cade-rea)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Attributes key to retrieve user's email address.static final String
Attribute key to retrieve the email verified claim.static final String
Attribute key to retrieve the user's first namestatic final String
Attributes key to retrieve user's full name as a single stringstatic final String
Attribute to retrieve the user's surnamestatic final String
For debugging purposes. -
Constructor Summary
ConstructorsConstructorDescriptionGoogleOAuthClientAuthenticationStrategyDelegate
(OAuth2UserDetailsService oAuth2UserDetailsService, UserRegistrationService<User> registrationService, AuthRegistrationProperties registrationProperties, AuthorizedClientService<AuthorizedClient> clientService, ClientIdentityProviderProperties clientProperties, com.broadleafcommerce.common.extension.TypeFactory typeFactory, PasswordGenerator passwordGenerator) -
Method Summary
Modifier and TypeMethodDescriptionprotected String
buildUsername
(@NonNull org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken authentication) Build a username from the authentication token.buildUserRegistration
(org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken authentication, String clientId, String username) Build aUserRegistration
from the authentication token.protected String
getEmail
(@NonNull org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken authentication) Get the user's email address from the authentication token.protected String
getName
(@NonNull org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken authentication) Get the user's name from the authentication token.protected String
Gets the registration type / client registration id that this delegate handlesprotected String
boolean
boolean
protected boolean
isEmailVerified
(org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken authentication) Methods inherited from class com.broadleafcommerce.auth.client.web.authentication.session.AbstractOAuthClientAuthenticationStrategyDelegate
canHandle, getClientId
Methods inherited from class com.broadleafcommerce.auth.user.web.authentication.session.AbstractAuthenticationStrategyDelegate
createAdminUser, generateRandomPassword, getAuthorizedClient, getClientProperties, getClientService, getExternalAdminUserHandler, getOAuth2UserDetails, getOAuth2UserDetailsService, getPasswordGenerator, getRegistrationProperties, getRegistrationService, getTypeFactory, getUsername, getUserType, handleAdminLogin, isAutoRegister, isAutoRegister, isThirdPartyAuth, registerNewUser, registerNewUser, setExternalAdminUserHandler
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.broadleafcommerce.auth.user.web.authentication.session.AuthenticationStrategyDelegate
canHandle, getOAuth2UserDetails
-
Field Details
-
EMAIL_ATTR_KEY
Attributes key to retrieve user's email address.- See Also:
-
FULL_NAME_ATTR_KEY
Attributes key to retrieve user's full name as a single string- See Also:
-
EMAIL_VERIFIED_ATTR_KEY
Attribute key to retrieve the email verified claim. This is a boolean- See Also:
-
FIRST_NAME_ATTR_KEY
Attribute key to retrieve the user's first name- See Also:
-
LAST_NAME_ATTR_KEY
Attribute to retrieve the user's surname- See Also:
-
REQUIRED_SCOPES
For debugging purposes. The scopes required to be able to retrieve the user's email address and name.- See Also:
-
-
Constructor Details
-
GoogleOAuthClientAuthenticationStrategyDelegate
public GoogleOAuthClientAuthenticationStrategyDelegate(OAuth2UserDetailsService oAuth2UserDetailsService, UserRegistrationService<User> registrationService, AuthRegistrationProperties registrationProperties, AuthorizedClientService<AuthorizedClient> clientService, ClientIdentityProviderProperties clientProperties, com.broadleafcommerce.common.extension.TypeFactory typeFactory, PasswordGenerator passwordGenerator)
-
-
Method Details
-
buildUserRegistration
public UserRegistration buildUserRegistration(org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken authentication, String clientId, String username) Description copied from class:AbstractAuthenticationStrategyDelegate
Build aUserRegistration
from the authentication token.- Overrides:
buildUserRegistration
in classAbstractAuthenticationStrategyDelegate<org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken>
- Parameters:
authentication
- The user'sAuthentication
.clientId
- The ID of the client authenticated withusername
- The username of the user- Returns:
- The
UserRegistration
for the user.
-
buildUsername
protected String buildUsername(@NonNull @NonNull org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken authentication) Description copied from class:AbstractAuthenticationStrategyDelegate
Build a username from the authentication token.- Overrides:
buildUsername
in classAbstractOAuthClientAuthenticationStrategyDelegate
- Parameters:
authentication
- The User's OAuth token issued by the third-party IDP.- Returns:
- A username derived from the authentication token.
-
getName
@Nullable protected String getName(@NonNull @NonNull org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken authentication) Description copied from class:AbstractAuthenticationStrategyDelegate
Get the user's name from the authentication token.- Overrides:
getName
in classAbstractOAuthClientAuthenticationStrategyDelegate
- Parameters:
authentication
- The User's OAuth token issued by the third-party IDP.- Returns:
- The user's name from the authentication token.
-
getEmail
protected String getEmail(@NonNull @NonNull org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken authentication) Description copied from class:AbstractAuthenticationStrategyDelegate
Get the user's email address from the authentication token.- Overrides:
getEmail
in classAbstractOAuthClientAuthenticationStrategyDelegate
- Parameters:
authentication
- The User's OAuth token issued by the third-party IDP.- Returns:
- The user's email address from the authentication token.
-
isEmailVerified
protected boolean isEmailVerified(org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken authentication) -
getOAuthRegistrationType
Description copied from class:AbstractOAuthClientAuthenticationStrategyDelegate
Gets the registration type / client registration id that this delegate handles- Specified by:
getOAuthRegistrationType
in classAbstractOAuthClientAuthenticationStrategyDelegate
- Returns:
- supported registration type
-
getRequiredScopes
-
isAdminClientHandler
public boolean isAdminClientHandler()- Returns:
- Does this authentication strategy delegate handle admin users? Default implementation returns true.
-
isCustomerClientHandler
public boolean isCustomerClientHandler()- Returns:
- Does this authentication strategy handle customer users? Default implementation returns true
-