Class AbstractExternalAdminUserHandler<T extends org.springframework.security.core.Authentication>
java.lang.Object
com.broadleafcommerce.auth.security.service.AbstractExternalAdminUserHandler<T>
- All Implemented Interfaces:
ExternalAdminUserHandler<T>
- Direct Known Subclasses:
OAuthExternalAdminUserHandler
public abstract class AbstractExternalAdminUserHandler<T extends org.springframework.security.core.Authentication>
extends Object
implements ExternalAdminUserHandler<T>
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAbstractExternalAdminUserHandler(UserService<User> userService, ExternalRoleMappingService<ExternalRoleMapping> externalRoleMappingService, AuthorizationServerService<AuthorizationServer> authorizationServerService, PasswordGenerator passwordGenerator, ExternalAdminUserModificationEventProducer modificationEventProducer, AdminUserMessagingProperties adminUserMessagingProperties, com.broadleafcommerce.common.extension.TypeFactory typeFactory, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanassignTenantAndApplicationAccess(T authentication, User user, AuthorizedClient client, com.broadleafcommerce.data.tracking.core.type.OperationType operationType) Determine if an admin user has tenant and/or application access.protected booleanassignThirdPartyRoles(T authentication, User user, AuthorizedClient client) Assign roles to admin users.protected voidassignUserAccess(T authentication, User user, AuthorizedClient client) Set initial tenant and server values on the newUserand set tenant access, application access, and roles.createAdminUser(T authentication, String username, String email, String name, AuthorizedClient client) Responsible for initializing and creating an admin if automatic admin creation is enabled for third party IDP.protected StringCreate a random password for the User and encode it with the password encoder.getAdditionalExternalEventAttributes(User user, T authentication, AuthorizedClient client) Extension point for adding additional information to be included with the user modification event.protected AdminUserMessagingPropertiesgetApplicationRestrictions(T authentication) Return a set of application ID strings indicating which applications a user is restricted to purely based on what is specified in the third party authentication token.protected AuthorizationServerService<AuthorizationServer>protected Optional<ClientIdentityProviderProperties.ClientProperties.AutoRegisteredAdminUserProperties>getAutoRegisteredAdminUserProperties(String providerId, AuthorizedClient client) protected ClientIdentityProviderPropertiesprotected ExternalRoleMappingService<ExternalRoleMapping>protected abstract BooleangetHasAppAccess(T authentication) Return whether the user has application access purely based on what is specified in the third party authentication token.protected abstract BooleangetHasTenantAccess(T authentication) Return whether the user has tenant level access purely based on what is specified in the third party authentication token.getInternallySourcedApplicationRestrictionsInitialValue(T authentication, User user, AuthorizedClient client) This method is used to determine the initial value for a user's application assignments setting when external tenant/app access management is disabled and a user is being newly created.protected BooleangetInternallySourcedHasAppAccessInitialValue(T authentication, User user, AuthorizedClient client) This method is used to determine the initial value for a user's application access setting when external tenant/app access management is disabled and a user is being newly created.protected BooleangetInternallySourcedHasTenantAccessInitialValue(T authentication, User user, AuthorizedClient client) This method is used to determine the initial value for a user's tenant access setting when external tenant/app access management is disabled and a user is being newly created.protected org.springframework.security.crypto.password.PasswordEncoderprotected PasswordGeneratorgetProviderClientRegistrationId(T authentication, AuthorizedClient client) getThirdPartyAssignedRoles(T authentication, AuthorizedClient client) An extension point for resolving third party assigned roles.protected com.broadleafcommerce.common.extension.TypeFactoryprotected UserService<User>handleAdminUserUpdates(T authentication, User user, AuthorizedClient client) Update theUser'stenant access, application access, and roles from the authentication token provided by the third-party authentication provider.handleThirdPartyAdminLogin(T authentication, AuthorizedClient client, String username) Upon successful login of an existing admin user, handle any relevant updates and return the user if modifications occurred.protected voidsendExternalAdminUserUpdateEvent(User user, String operationType, Map<String, Object> additionalAttributes) voidsetClientIdentityProviderProperties(ClientIdentityProviderProperties clientIdentityProviderProperties)
-
Field Details
-
RANDOM
-
-
Constructor Details
-
AbstractExternalAdminUserHandler
public AbstractExternalAdminUserHandler(UserService<User> userService, ExternalRoleMappingService<ExternalRoleMapping> externalRoleMappingService, AuthorizationServerService<AuthorizationServer> authorizationServerService, PasswordGenerator passwordGenerator, ExternalAdminUserModificationEventProducer modificationEventProducer, AdminUserMessagingProperties adminUserMessagingProperties, com.broadleafcommerce.common.extension.TypeFactory typeFactory, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder)
-
-
Method Details
-
createAdminUser
public User createAdminUser(T authentication, String username, String email, String name, AuthorizedClient client) Description copied from interface:ExternalAdminUserHandlerResponsible for initializing and creating an admin if automatic admin creation is enabled for third party IDP. In addition, emits a user created event that is consumed by the Admin User service.- Specified by:
createAdminUserin interfaceExternalAdminUserHandler<T extends org.springframework.security.core.Authentication>- Parameters:
authentication- The authentication objectusername- The desired usernameemail- The user's emailname- The user's nameclient- The authorized client- Returns:
- The newly created admin
-
handleThirdPartyAdminLogin
public Optional<User> handleThirdPartyAdminLogin(T authentication, AuthorizedClient client, String username) Description copied from interface:ExternalAdminUserHandlerUpon successful login of an existing admin user, handle any relevant updates and return the user if modifications occurred.- Specified by:
handleThirdPartyAdminLoginin interfaceExternalAdminUserHandler<T extends org.springframework.security.core.Authentication>- Parameters:
authentication- The authenication objectclient- The authorized clientusername- The admin's username- Returns:
- The user, if updates were made, else empty.
-
assignUserAccess
Set initial tenant and server values on the newUserand set tenant access, application access, and roles.- Parameters:
authentication- The authentication token granted by the third-party authentication provider.user- TheUserrepresented by the given authentication tokenclient- TheAuthorizedClientthat the User is using to log in.
-
handleAdminUserUpdates
protected Optional<User> handleAdminUserUpdates(T authentication, User user, AuthorizedClient client) Update theUser'stenant access, application access, and roles from the authentication token provided by the third-party authentication provider.- Parameters:
authentication- The authentication token granted by the third-party authentication provider.user- TheUserrepresented by the given authentication tokenclient- TheAuthorizedClientthat the User is using to log in.- Returns:
- An Optional containing a refreshed
Userobject if the user was updated. Otherwise, an empty Optional if the user was not updated during this operation.
-
assignTenantAndApplicationAccess
protected boolean assignTenantAndApplicationAccess(T authentication, User user, AuthorizedClient client, com.broadleafcommerce.data.tracking.core.type.OperationType operationType) Determine if an admin user has tenant and/or application access. This method should determine and set whether the user has tenant or application access (or both). If the user is restricted to certain application, implementors of this method should handle that scenario as well.See:
User.setTenantAccess(boolean)
User.setApplicationAccess(boolean)
User.setApplicationIds(Set)- Parameters:
authentication- The authentication token granted by the third-party authentication provider.user- TheUserrepresented by the given authentication tokenclient- TheAuthorizedClientthat the User is using to log in.operationType- (since AuthenticationServices 2.3.0, RT 2.3.0) the operation type that this assignment logic is being performed for. For example, if the user is being created, this value will beOperationType.CREATE. If they are being updated, this value will beOperationType.UPDATE. This allows for different logic in the different scenarios of an initial user setup vs a user update.- Returns:
- True if the given
Userobject was changed during this operation. False if the given user was not changed.
-
assignThirdPartyRoles
Assign roles to admin users. This implementation defers togetThirdPartyAssignedRoles(Authentication, AuthorizedClient)to get the roles that should be granted to the admin. TheexternalRoleMappingServiceis used to map the role ids from the authentication to Broadleaf roles. Roles added this way are marked asUserRoleRef.isThirdPartyAssigned().- Parameters:
authentication- The authentication token granted by the third-party authentication provider.user- TheUserrepresented by the given authentication tokenclient- TheAuthorizedClientthat the User is using to log in.- Returns:
- True if the given
Userobject was changed during this operation. False if the given user was not changed.
-
getApplicationRestrictions
Return a set of application ID strings indicating which applications a user is restricted to purely based on what is specified in the third party authentication token.- Parameters:
authentication- The authentication object- Returns:
- A set of strings indicating which applications a user is restricted to purely based on what is specified in the third party authentication token.
- See Also:
-
getInternallySourcedApplicationRestrictionsInitialValue
protected Set<String> getInternallySourcedApplicationRestrictionsInitialValue(T authentication, User user, AuthorizedClient client) This method is used to determine the initial value for a user's application assignments setting when external tenant/app access management is disabled and a user is being newly created.- Parameters:
authentication- the third party authentication objectuser- the user being createdclient- theAuthorizedClientin Broadleaf the user is signing into- Returns:
- the initial value to use for
User.getApplicationIds()sourced from internal settings, oremptyif not defined
-
getHasTenantAccess
Return whether the user has tenant level access purely based on what is specified in the third party authentication token.- Parameters:
authentication- The authentication object- Returns:
- true if the user has tenant level access purely based on what is specified in the third party authentication token
- See Also:
-
getInternallySourcedHasTenantAccessInitialValue
@Nullable protected Boolean getInternallySourcedHasTenantAccessInitialValue(T authentication, User user, AuthorizedClient client) This method is used to determine the initial value for a user's tenant access setting when external tenant/app access management is disabled and a user is being newly created.- Parameters:
authentication- the third party authentication objectuser- the user being createdclient- theAuthorizedClientin Broadleaf the user is signing into- Returns:
- the initial value to use for
User.isTenantAccess()sourced from internal settings, ornullif not defined
-
getProviderClientRegistrationId
protected Optional<String> getProviderClientRegistrationId(T authentication, AuthorizedClient client) -
getAutoRegisteredAdminUserProperties
protected Optional<ClientIdentityProviderProperties.ClientProperties.AutoRegisteredAdminUserProperties> getAutoRegisteredAdminUserProperties(String providerId, AuthorizedClient client) -
getHasAppAccess
Return whether the user has application access purely based on what is specified in the third party authentication token.- Parameters:
authentication- The authentication object- Returns:
- true if the user has application access purely based on what is specified in the third party authentication token
- See Also:
-
getInternallySourcedHasAppAccessInitialValue
@Nullable protected Boolean getInternallySourcedHasAppAccessInitialValue(T authentication, User user, AuthorizedClient client) This method is used to determine the initial value for a user's application access setting when external tenant/app access management is disabled and a user is being newly created.- Parameters:
authentication- the third party authentication objectuser- the user being createdclient- theAuthorizedClientin Broadleaf the user is signing into- Returns:
- the initial value to use for
User.isApplicationAccess()sourced from internal settings, ornullif not defined
-
sendExternalAdminUserUpdateEvent
-
generateRandomPassword
Create a random password for the User and encode it with the password encoder.- Returns:
- a secure, random, encoded String
-
getThirdPartyAssignedRoles
protected abstract Set<String> getThirdPartyAssignedRoles(T authentication, AuthorizedClient client) An extension point for resolving third party assigned roles. These roles should then be mapped to BLC roles.- Parameters:
authentication- The authentication object- Returns:
- A set of strings representing third party roles.
-
getAdditionalExternalEventAttributes
@NonNull protected Map<String,Object> getAdditionalExternalEventAttributes(User user, T authentication, AuthorizedClient client) Extension point for adding additional information to be included with the user modification event. Default returns an empty map.
SeeExternalAdminUserModificationEvent.getAdditionalAttributes().- Returns:
- A map of any additional attributes to be sent with the user modification event.
-
getUserService
-
getExternalRoleMappingService
-
getAuthorizationServerService
-
getPasswordGenerator
-
getModificationEventProducer
-
getAdminUserMessagingProperties
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getPasswordEncoder
protected org.springframework.security.crypto.password.PasswordEncoder getPasswordEncoder() -
getClientIdentityProviderProperties
-
setClientIdentityProviderProperties
@Autowired public void setClientIdentityProviderProperties(ClientIdentityProviderProperties clientIdentityProviderProperties)
-