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 void
addTenantToUser
(P savedUser, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected void
addUserToApplication
(P savedUser, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected void
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.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.void
Deletes an admin user or removes an admin user from an application, depending on the scenario.void
deleteById
(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.boolean
existsById
(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.name
containingname
, 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 AdminUserAccessLevelProperties
protected AdminUserContextValidator<P>
protected AuthProvider
protected com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager
protected com.broadleafcommerce.common.messaging.notification.MessageSerializationHelper
protected com.broadleafcommerce.common.messaging.notification.NotificationManager
protected com.broadleafcommerce.common.messaging.notification.NotificationStateService
protected com.broadleafcommerce.data.tracking.core.type.OperationType
getOperationTypeOrUnknown
(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.PersistenceProducer
protected AdminUserRepository<D>
protected String
getSerializedRepresentation
(Object object) protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager
protected P
hydratePermissions
(P user) Hydrate the values inAdminUser.getPermissions()
andAdminUser.getRestrictedPermissions()
protected P
hydrateRoles
(P user, boolean userAlreadyExists) Hydrate the values inAdminUser.getRoles()
andAdminUser.getRestrictedRoles()
protected P
hydrateRolesAndPermissions
(P user) Hydrate roles and permissions by using the definedauthProvider
.protected P
hydrateRolesAndPermissions
(P user, boolean userAlreadyExists) Hydrate roles and permissions by using the definedauthProvider
protected void
initializePersistenceProducerState
(com.broadleafcommerce.common.messaging.notification.domain.NotificationStateAware repositoryDomain, com.broadleafcommerce.data.tracking.core.type.OperationType operationType) protected void
notifyPersistenceProducer
(D domain) void
removeUserFromApplication
(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 givenid
withuser
.Saves the given user.protected P
saveInternal
(P user, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Save the givenUser
without hydrating roles and permissions first.void
setAdminUserAccessLevelProperties
(AdminUserAccessLevelProperties adminUserAccessLevelProperties) protected void
setExternalRoles
(P user, Set<String> externalRoleIds) Ensure that roles assigned from a third-party authentication provider are not added or removed by API operations.protected void
throwIfErrors
(org.springframework.validation.Errors errors) protected D
toRepositoryDomain
(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.ContextInfo
withOperationTypeIfNull
(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:
findById
in interfaceAdminUserService<P extends AdminUser>
-
existsById
Description copied from interface:AdminUserService
Performs an existence check to determine if there is a user in the data store matching the given id.- Specified by:
existsById
in 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:
findAll
in 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:AdminUserService
Find all users withAdminUser.name
containingname
, ignoring case.- Specified by:
findAllByName
in 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:AdminUserService
Creates 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
OperationAwarePersistenceMessage
to thePersistenceProducer.TYPE
channel.- Specified by:
create
in 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:AdminUserService
Replaces the user in the data store with the givenid
withuser
. Additional validation is also performed to prevent unauthorized addition/removal from an application.Emits an
OperationAwarePersistenceMessage
to thePersistenceProducer.TYPE
channel.- Specified by:
replace
in 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:AdminUserService
Saves the given user.Emits an
OperationAwarePersistenceMessage
to thePersistenceProducer.TYPE
channel.- Specified by:
save
in 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 givenUser
without 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:AdminUserService
Deletes 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
OperationAwarePersistenceMessage
to thePersistenceProducer.TYPE
channel.- Specified by:
delete
in 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:AdminUserService
Deletes 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
OperationAwarePersistenceMessage
to thePersistenceProducer.TYPE
channel.- Specified by:
deleteById
in 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:AdminUserService
Find a user by email address.- Specified by:
findByEmail
in 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:AdminUserService
Find a user by username.- Specified by:
findByUsername
in 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:AdminUserService
Removes 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:
removeUserFromApplication
in 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:
updateUserPreferencesByName
in 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)
-