Class DefaultAdminUserService<P extends AdminUser,D extends com.broadleafcommerce.data.tracking.core.mapping.BusinessTypeAware & com.broadleafcommerce.common.messaging.notification.domain.NotificationStateAware>
- All Implemented Interfaces:
AdminUserService<P>
- Author:
- Nathan Moore (nathanmoore)., Samarth Dhruva (samarthd).
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultAdminUserService(AdminUserRepository<D> repository, com.broadleafcommerce.common.messaging.notification.NotificationStateService notificationStateService, com.broadleafcommerce.common.messaging.notification.NotificationManager notificationManager, com.broadleafcommerce.common.messaging.notification.MessageSerializationHelper messageSerializationHelper, com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager mapper, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator, com.broadleafcommerce.common.messaging.PersistenceProducer persistenceProducer, AdminUserContextValidator<P> adminUserContextValidator, com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> parser, AuthProvider authProvider) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddTenantToUser(P savedUser, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected voidaddUserToApplication(P savedUser, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected voidTODO this is a workaround to support sending delete persistence messages as best as possible for now until soft-deletes are supported via https://github.com/BroadleafCommerce/AdminServices/issues/266.protected <T> OperationAwarePersistenceMessage<T>buildPersistenceMessage(T entity, com.broadleafcommerce.data.tracking.core.type.OperationType operationType, Instant timestamp) Creates a new user in the data store.voidDeletes an admin user or removes an admin user from an application, depending on the scenario.voiddeleteById(String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Deletes an admin user or removes an admin user from an application, depending on the scenario.booleanexistsById(String id) Performs an existence check to determine if there is a user in the data store matching the given id.protected org.springframework.data.domain.Page<D>findAll(String name, org.springframework.data.domain.Pageable page, cz.jirutka.rsql.parser.ast.Node filters) org.springframework.data.domain.Page<P>findAll(org.springframework.data.domain.Pageable page, cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) org.springframework.data.domain.Page<P>findAllByName(String name, org.springframework.data.domain.Pageable page, cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Find all users withAdminUser.namecontainingname, ignoring case.protected org.springframework.data.domain.Page<D>findAllByTenantAndApplicationId(String name, String tenantId, String applicationId, org.springframework.data.domain.Pageable page, cz.jirutka.rsql.parser.ast.Node filters) protected org.springframework.data.domain.Page<D>findAllByTenantId(String name, String tenantId, org.springframework.data.domain.Pageable page, cz.jirutka.rsql.parser.ast.Node filters) protected org.springframework.data.domain.Page<D>findAllWithContextDiscrimination(String name, org.springframework.data.domain.Pageable page, cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) findByEmail(String email, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Find a user by email address.findByIdWithContextDiscrimination(String userId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) findByUsername(String username, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Find a user by username.fromRepositoryDomain(Optional<D> optional, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected org.springframework.data.domain.Page<P>fromRepositoryDomainPage(org.springframework.data.domain.Page<D> page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected AdminUserAccessLevelPropertiesprotected AdminUserContextValidator<P>protected AuthProviderprotected com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManagerprotected com.broadleafcommerce.common.messaging.notification.MessageSerializationHelperprotected com.broadleafcommerce.common.messaging.notification.NotificationManagerprotected com.broadleafcommerce.common.messaging.notification.NotificationStateServiceprotected com.broadleafcommerce.data.tracking.core.type.OperationTypegetOperationTypeOrUnknown(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node>protected com.broadleafcommerce.common.messaging.PersistenceProducerprotected AdminUserRepository<D>protected StringgetSerializedRepresentation(Object object) protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManagerprotected PhydratePermissions(P user) Hydrate the values inAdminUser.getPermissions()andAdminUser.getRestrictedPermissions()protected PhydrateRoles(P user, boolean userAlreadyExists) Hydrate the values inAdminUser.getRoles()andAdminUser.getRestrictedRoles()protected PhydrateRolesAndPermissions(P user) Hydrate roles and permissions by using the definedauthProvider.protected PhydrateRolesAndPermissions(P user, boolean userAlreadyExists) Hydrate roles and permissions by using the definedauthProviderprotected voidinitializePersistenceProducerState(com.broadleafcommerce.common.messaging.notification.domain.NotificationStateAware repositoryDomain, com.broadleafcommerce.data.tracking.core.type.OperationType operationType) protected voidnotifyPersistenceProducer(D domain) voidremoveUserFromApplication(P user, String applicationId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Removes a user from an application.replace(String id, P user, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Replaces the user in the data store with the givenidwithuser.Saves the given user.protected PsaveInternal(P user, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Save the givenUserwithout hydrating roles and permissions first.voidsetAdminUserAccessLevelProperties(AdminUserAccessLevelProperties adminUserAccessLevelProperties) protected voidsetExternalRoles(P user, Set<String> externalRoleIds) Ensure that roles assigned from a third-party authentication provider are not added or removed by API operations.protected voidthrowIfErrors(org.springframework.validation.Errors errors) protected DtoRepositoryDomain(P user, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) updateUserPreferencesByName(String username, UserPreferences preferences, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected com.broadleafcommerce.data.tracking.core.context.ContextInfowithOperationTypeIfNull(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, com.broadleafcommerce.data.tracking.core.type.OperationType operationType)
-
Constructor Details
-
DefaultAdminUserService
public DefaultAdminUserService(AdminUserRepository<D> repository, com.broadleafcommerce.common.messaging.notification.NotificationStateService notificationStateService, com.broadleafcommerce.common.messaging.notification.NotificationManager notificationManager, com.broadleafcommerce.common.messaging.notification.MessageSerializationHelper messageSerializationHelper, com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager mapper, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator, com.broadleafcommerce.common.messaging.PersistenceProducer persistenceProducer, AdminUserContextValidator<P> adminUserContextValidator, com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> parser, AuthProvider authProvider)
-
-
Method Details
-
findById
public Optional<P> findById(String id, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) - Specified by:
findByIdin interfaceAdminUserService<P extends AdminUser>
-
existsById
Description copied from interface:AdminUserServicePerforms an existence check to determine if there is a user in the data store matching the given id.- Specified by:
existsByIdin interfaceAdminUserService<P extends AdminUser>- Parameters:
id- the id of the user to find- Returns:
- true if the user exists, false otherwise
-
findAll
public org.springframework.data.domain.Page<P> findAll(org.springframework.data.domain.Pageable page, cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) - Specified by:
findAllin interfaceAdminUserService<P extends AdminUser>
-
findAllByName
public org.springframework.data.domain.Page<P> findAllByName(String name, org.springframework.data.domain.Pageable page, cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:AdminUserServiceFind all users withAdminUser.namecontainingname, ignoring case.- Specified by:
findAllByNamein interfaceAdminUserService<P extends AdminUser>- Parameters:
name- The name to matchpage- The current pagefilters- Any filters to applycontextInfo- The current context.- Returns:
- A page of users matching the supplied
name.ß
-
findByIdWithContextDiscrimination
-
findAllWithContextDiscrimination
-
findAllByTenantId
-
findAllByTenantAndApplicationId
-
findAll
-
fromRepositoryDomainPage
-
create
public P create(P user, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:AdminUserServiceCreates a new user in the data store. Validation is performed to ensure the user is not assigned to an unauthorized tenant or application.Emits an
OperationAwarePersistenceMessageto thePersistenceProducer.TYPEchannel.- Specified by:
createin interfaceAdminUserService<P extends AdminUser>- Parameters:
user- the user to create- Returns:
- the final user after creation
-
addTenantToUser
protected void addTenantToUser(P savedUser, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
addUserToApplication
protected void addUserToApplication(P savedUser, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
withOperationTypeIfNull
protected com.broadleafcommerce.data.tracking.core.context.ContextInfo withOperationTypeIfNull(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, com.broadleafcommerce.data.tracking.core.type.OperationType operationType) -
replace
public P replace(String id, P user, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:AdminUserServiceReplaces the user in the data store with the givenidwithuser. Additional validation is also performed to prevent unauthorized addition/removal from an application.Emits an
OperationAwarePersistenceMessageto thePersistenceProducer.TYPEchannel.- Specified by:
replacein interfaceAdminUserService<P extends AdminUser>- Parameters:
id- the ID of the user to replaceuser- the replacement user- Returns:
- the final user after replacement
-
save
public P save(P user, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:AdminUserServiceSaves the given user.Emits an
OperationAwarePersistenceMessageto thePersistenceProducer.TYPEchannel.- Specified by:
savein interfaceAdminUserService<P extends AdminUser>- Parameters:
user- the user to savecontextInfo- context information surrounding multitenant state- Returns:
- the saved user
-
saveInternal
protected P saveInternal(P user, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Save the givenUserwithout hydrating roles and permissions first.- Parameters:
user- the user to savecontextInfo- context information surrounding multitenant state- Returns:
- the saved user
-
getOperationTypeOrUnknown
protected com.broadleafcommerce.data.tracking.core.type.OperationType getOperationTypeOrUnknown(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
initializePersistenceProducerState
protected void initializePersistenceProducerState(com.broadleafcommerce.common.messaging.notification.domain.NotificationStateAware repositoryDomain, com.broadleafcommerce.data.tracking.core.type.OperationType operationType) -
buildPersistenceMessage
protected <T> OperationAwarePersistenceMessage<T> buildPersistenceMessage(T entity, com.broadleafcommerce.data.tracking.core.type.OperationType operationType, Instant timestamp) -
getSerializedRepresentation
-
delete
public void delete(P user, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:AdminUserServiceDeletes an admin user or removes an admin user from an application, depending on the scenario.For an admin user assigned to 1 application, they are always deleted. For an admin user assigned to 2 or more applications, the operation depends on the context in which the delete is requested:
- In a tenant or global context: Delete the user
- In an application context: Remove the user from the application
Emits an
OperationAwarePersistenceMessageto thePersistenceProducer.TYPEchannel.- Specified by:
deletein interfaceAdminUserService<P extends AdminUser>- Parameters:
user- The user to deletecontextInfo- The context
-
attemptDirectlySendingDeletePersistenceMessage
TODO this is a workaround to support sending delete persistence messages as best as possible for now until soft-deletes are supported via https://github.com/BroadleafCommerce/AdminServices/issues/266. Once soft-deletes are implemented, replace the use of this method with durable notification behavior. -
deleteById
public void deleteById(String id, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:AdminUserServiceDeletes an admin user or removes an admin user from an application, depending on the scenario.For an admin user assigned to 1 application, they are always deleted. For an admin user assigned to 2 or more applications, the operation depends on the context in which the delete is requested:
- In a tenant or global context: Delete the user
- In an application context: Remove the user from the application
Emits an
OperationAwarePersistenceMessageto thePersistenceProducer.TYPEchannel.- Specified by:
deleteByIdin interfaceAdminUserService<P extends AdminUser>- Parameters:
id- The ID of the user to deletecontextInfo- The context- See Also:
-
findByEmail
public Optional<P> findByEmail(String email, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:AdminUserServiceFind a user by email address.- Specified by:
findByEmailin interfaceAdminUserService<P extends AdminUser>- Parameters:
email- The email address.contextInfo- The current context.- Returns:
- The user found, or
Optional.empty()
-
findByUsername
public Optional<P> findByUsername(String username, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:AdminUserServiceFind a user by username.- Specified by:
findByUsernamein interfaceAdminUserService<P extends AdminUser>- Parameters:
username- The username.contextInfo- The current context.- Returns:
- The user found, or
Optional.empty()
-
removeUserFromApplication
public void removeUserFromApplication(P user, String applicationId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:AdminUserServiceRemoves a user from an application. Intended for use in delete operations. When a user belongs to more than one application and a delete operation is performed in an application context, that user should be removed from that application instead of deleted.- Specified by:
removeUserFromApplicationin interfaceAdminUserService<P extends AdminUser>- Parameters:
user- The user to remove from an applicationapplicationId- The ID of the application to remove the user from.contextInfo- The current context.
-
updateUserPreferencesByName
public P updateUserPreferencesByName(String username, UserPreferences preferences, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) - Specified by:
updateUserPreferencesByNamein interfaceAdminUserService<P extends AdminUser>
-
notifyPersistenceProducer
-
throwIfErrors
protected void throwIfErrors(org.springframework.validation.Errors errors) -
fromRepositoryDomain
-
toRepositoryDomain
-
hydrateRolesAndPermissions
Hydrate roles and permissions by using the definedauthProvider. This assumes the user already exists. SeehydrateRolesAndPermissions(AdminUser, boolean)for the alternative.- Parameters:
user- The user to hydrate roles and permissions for- Returns:
- The user, with roles and permissions hydrated
-
hydrateRolesAndPermissions
Hydrate roles and permissions by using the definedauthProvider- Parameters:
user- The user to hydrate roles and permissions foruserAlreadyExists- whether the hydration logic can assume the user should already exist. Typically, this would be false if hydrating before a 'create' operation, and true otherwise.- Returns:
- The user, with roles and permissions hydrated
-
hydrateRoles
Hydrate the values inAdminUser.getRoles()andAdminUser.getRestrictedRoles()- Parameters:
user- The user to hydrate rolesuserAlreadyExists- whether the hydration logic can assume the user should already exist. Typically, this would be false if hydrating before a 'create' operation, and true otherwise.- Returns:
- The user, with roles hydrated
-
setExternalRoles
Ensure that roles assigned from a third-party authentication provider are not added or removed by API operations. SinceAdminRoleRef.setThirdPartyAssigned(boolean)is marked as@JsonIgnore, all role refs will have that field as false. This removes any existing external role references and adds new AdminRoleRef withthirdPartyAssigned == true. -
hydratePermissions
Hydrate the values inAdminUser.getPermissions()andAdminUser.getRestrictedPermissions()- Parameters:
user- The user to hydrate permissions- Returns:
- The user, with permissions hydrated
-
getRepository
-
getNotificationStateService
protected com.broadleafcommerce.common.messaging.notification.NotificationStateService getNotificationStateService() -
getNotificationManager
protected com.broadleafcommerce.common.messaging.notification.NotificationManager getNotificationManager() -
getMessageSerializationHelper
protected com.broadleafcommerce.common.messaging.notification.MessageSerializationHelper getMessageSerializationHelper() -
getMapper
protected com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager getMapper() -
getValidator
@NonNull protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager getValidator() -
getPersistenceProducer
protected com.broadleafcommerce.common.messaging.PersistenceProducer getPersistenceProducer() -
getAdminUserContextValidator
-
getParser
protected com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> getParser() -
getAuthProvider
-
getAdminUserAccessLevelProperties
-
setAdminUserAccessLevelProperties
@Autowired(required=false) public void setAdminUserAccessLevelProperties(AdminUserAccessLevelProperties adminUserAccessLevelProperties)
-