Class DefaultAdminUserService<P extends AdminUser,D extends com.broadleafcommerce.data.tracking.core.mapping.BusinessTypeAware & com.broadleafcommerce.common.messaging.notification.domain.NotificationStateAware>

java.lang.Object
com.broadleafcommerce.adminuser.user.service.DefaultAdminUserService<P,D>
All Implemented Interfaces:
AdminUserService<P>

public class DefaultAdminUserService<P extends AdminUser,D extends com.broadleafcommerce.data.tracking.core.mapping.BusinessTypeAware & com.broadleafcommerce.common.messaging.notification.domain.NotificationStateAware> extends Object implements AdminUserService<P>
Author:
Nathan Moore (nathanmoore)., Samarth Dhruva (samarthd).
  • Constructor Summary

    Constructors
    Constructor
    Description
    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 Summary

    Modifier and Type
    Method
    Description
    protected 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.
    buildPersistenceMessage(T entity, com.broadleafcommerce.data.tracking.core.type.OperationType operationType, Instant timestamp)
     
    create(P user, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Creates a new user in the data store.
    void
    delete(P user, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    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
    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 with AdminUser.name containing name, 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.
    findById(String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
     
    protected Optional<D>
    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.
    protected Optional<P>
    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 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 String
     
    protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager
     
    protected P
    protected P
    hydrateRoles(P user, boolean userAlreadyExists)
    protected P
    Hydrate roles and permissions by using the defined authProvider.
    protected P
    hydrateRolesAndPermissions(P user, boolean userAlreadyExists)
    Hydrate roles and permissions by using the defined authProvider
    protected void
    initializePersistenceProducerState(com.broadleafcommerce.common.messaging.notification.domain.NotificationStateAware repositoryDomain, com.broadleafcommerce.data.tracking.core.type.OperationType operationType)
     
    protected void
     
    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 given id with user.
    save(P user, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Saves the given user.
    protected P
    saveInternal(P user, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Save the given User without hydrating roles and permissions first.
    void
     
    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)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 interface AdminUserService<P extends AdminUser>
    • existsById

      public boolean existsById(String id)
      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 interface AdminUserService<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 interface AdminUserService<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 with AdminUser.name containing name, ignoring case.
      Specified by:
      findAllByName in interface AdminUserService<P extends AdminUser>
      Parameters:
      name - The name to match
      page - The current page
      filters - Any filters to apply
      contextInfo - The current context.
      Returns:
      A page of users matching the supplied name
    • findByIdWithContextDiscrimination

      protected Optional<D> findByIdWithContextDiscrimination(String userId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • findAllWithContextDiscrimination

      protected org.springframework.data.domain.Page<D> findAllWithContextDiscrimination(@Nullable String name, org.springframework.data.domain.Pageable page, cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • findAllByTenantId

      protected org.springframework.data.domain.Page<D> findAllByTenantId(@Nullable String name, String tenantId, org.springframework.data.domain.Pageable page, cz.jirutka.rsql.parser.ast.Node filters)
    • findAllByTenantAndApplicationId

      protected org.springframework.data.domain.Page<D> findAllByTenantAndApplicationId(@Nullable String name, String tenantId, String applicationId, org.springframework.data.domain.Pageable page, cz.jirutka.rsql.parser.ast.Node filters)
    • findAll

      protected org.springframework.data.domain.Page<D> findAll(@Nullable String name, org.springframework.data.domain.Pageable page, cz.jirutka.rsql.parser.ast.Node filters)
    • fromRepositoryDomainPage

      protected org.springframework.data.domain.Page<P> fromRepositoryDomainPage(org.springframework.data.domain.Page<D> page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • 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 the PersistenceProducer.TYPE channel.

      Specified by:
      create in interface AdminUserService<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 given id with user. Additional validation is also performed to prevent unauthorized addition/removal from an application.

      Emits an OperationAwarePersistenceMessage to the PersistenceProducer.TYPE channel.

      Specified by:
      replace in interface AdminUserService<P extends AdminUser>
      Parameters:
      id - the ID of the user to replace
      user - 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 the PersistenceProducer.TYPE channel.

      Specified by:
      save in interface AdminUserService<P extends AdminUser>
      Parameters:
      user - the user to save
      contextInfo - 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 given User without hydrating roles and permissions first.
      Parameters:
      user - the user to save
      contextInfo - 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

      protected String getSerializedRepresentation(Object object)
    • 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
      Note that, to avoid unauthorized removal of a user from an unrelated application, this always reads the user from the data store before performing a delete.

      Emits an OperationAwarePersistenceMessage to the PersistenceProducer.TYPE channel.

      Specified by:
      delete in interface AdminUserService<P extends AdminUser>
      Parameters:
      user - The user to delete
      contextInfo - The context
    • attemptDirectlySendingDeletePersistenceMessage

      protected void attemptDirectlySendingDeletePersistenceMessage(String id, D user)
      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 the PersistenceProducer.TYPE channel.

      Specified by:
      deleteById in interface AdminUserService<P extends AdminUser>
      Parameters:
      id - The ID of the user to delete
      contextInfo - 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 interface AdminUserService<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 interface AdminUserService<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 interface AdminUserService<P extends AdminUser>
      Parameters:
      user - The user to remove from an application
      applicationId - 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 interface AdminUserService<P extends AdminUser>
    • notifyPersistenceProducer

      protected void notifyPersistenceProducer(D domain)
    • throwIfErrors

      protected void throwIfErrors(org.springframework.validation.Errors errors)
    • fromRepositoryDomain

      protected Optional<P> fromRepositoryDomain(Optional<D> optional, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • toRepositoryDomain

      @Nullable protected D toRepositoryDomain(P user, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • hydrateRolesAndPermissions

      protected P hydrateRolesAndPermissions(P user)
      Hydrate roles and permissions by using the defined authProvider. This assumes the user already exists. See hydrateRolesAndPermissions(AdminUser, boolean) for the alternative.
      Parameters:
      user - The user to hydrate roles and permissions for
      Returns:
      The user, with roles and permissions hydrated
    • hydrateRolesAndPermissions

      protected P hydrateRolesAndPermissions(P user, boolean userAlreadyExists)
      Hydrate roles and permissions by using the defined authProvider
      Parameters:
      user - The user to hydrate roles and permissions for
      userAlreadyExists - 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

      protected P hydrateRoles(P user, boolean userAlreadyExists)
      Parameters:
      user - The user to hydrate roles
      userAlreadyExists - 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

      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. Since AdminRoleRef.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 with thirdPartyAssigned == true.
      Parameters:
      user - The User whose roles are being hydrated.
      externalRoleIds - The ids of the User's roles that have been assigned by a third-party authentication provider.
    • hydratePermissions

      protected P hydratePermissions(P user)
      Parameters:
      user - The user to hydrate permissions
      Returns:
      The user, with permissions hydrated
    • getRepository

      protected AdminUserRepository<D> 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

      protected AdminUserContextValidator<P> getAdminUserContextValidator()
    • getParser

      protected com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> getParser()
    • getAuthProvider

      protected AuthProvider getAuthProvider()
    • getAdminUserAccessLevelProperties

      protected AdminUserAccessLevelProperties getAdminUserAccessLevelProperties()
    • setAdminUserAccessLevelProperties

      @Autowired(required=false) public void setAdminUserAccessLevelProperties(AdminUserAccessLevelProperties adminUserAccessLevelProperties)