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 StringAttributes key to retrieve user's email address.static final StringAttribute key to retrieve the email verified claim.static final StringAttribute key to retrieve the user's first namestatic final StringAttributes key to retrieve user's full name as a single stringstatic final StringAttribute to retrieve the user's surnamestatic final StringFor 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 StringbuildUsername(@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 aUserRegistrationfrom the authentication token.protected StringgetEmail(@NonNull org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken authentication) Get the user's email address from the authentication token.protected StringgetName(@NonNull org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken authentication) Get the user's name from the authentication token.protected StringGets the registration type / client registration id that this delegate handlesprotected Stringbooleanbooleanprotected booleanisEmailVerified(org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken authentication) Methods inherited from class com.broadleafcommerce.auth.client.web.authentication.session.AbstractOAuthClientAuthenticationStrategyDelegate
canHandle, getClientIdMethods 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, setExternalAdminUserHandlerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:AbstractAuthenticationStrategyDelegateBuild aUserRegistrationfrom the authentication token.- Overrides:
buildUserRegistrationin 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
UserRegistrationfor the user.
-
buildUsername
protected String buildUsername(@NonNull @NonNull org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken authentication) Description copied from class:AbstractAuthenticationStrategyDelegateBuild a username from the authentication token.- Overrides:
buildUsernamein 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:AbstractAuthenticationStrategyDelegateGet the user's name from the authentication token.- Overrides:
getNamein 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:AbstractAuthenticationStrategyDelegateGet the user's email address from the authentication token.- Overrides:
getEmailin 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:AbstractOAuthClientAuthenticationStrategyDelegateGets the registration type / client registration id that this delegate handles- Specified by:
getOAuthRegistrationTypein 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
-