Class CustomerServiceImpl

java.lang.Object
org.broadleafcommerce.profile.core.service.CustomerServiceImpl
All Implemented Interfaces:
CustomerService

@Service("blCustomerService") public class CustomerServiceImpl extends Object implements CustomerService
  • Field Details

    • postRegisterListeners

      protected final List<PostRegistrationObserver> postRegisterListeners
    • eventPublisher

      @Autowired @Qualifier("blApplicationEventPublisher") protected org.broadleafcommerce.common.event.BroadleafApplicationEventPublisher eventPublisher
    • customerDao

      protected CustomerDao customerDao
    • customerAddressDao

      protected CustomerAddressDao customerAddressDao
    • idGenerationService

      protected org.broadleafcommerce.common.id.service.IdGenerationService idGenerationService
    • customerForgotPasswordSecurityTokenDao

      protected CustomerForgotPasswordSecurityTokenDao customerForgotPasswordSecurityTokenDao
    • passwordEncoderBean

      protected org.springframework.security.crypto.password.PasswordEncoder passwordEncoderBean
    • roleDao

      protected RoleDao roleDao
    • tokenExpiredMinutes

      protected int tokenExpiredMinutes
    • passwordTokenLength

      protected int passwordTokenLength
    • passwordResetHandlers

      protected List<PasswordUpdatedHandler> passwordResetHandlers
    • passwordChangedHandlers

      protected List<PasswordUpdatedHandler> passwordChangedHandlers
  • Constructor Details

    • CustomerServiceImpl

      public CustomerServiceImpl()
  • Method Details

    • saveCustomer

      @Transactional("blTransactionManager") public Customer saveCustomer(Customer customer)
      Specified by:
      saveCustomer in interface CustomerService
    • saveCustomer

      @Transactional("blTransactionManager") public Customer saveCustomer(Customer customer, boolean register)
      Specified by:
      saveCustomer in interface CustomerService
    • generateSecurePassword

      protected String generateSecurePassword()
    • registerCustomer

      @Transactional("blTransactionManager") public Customer registerCustomer(Customer customer, String password, String passwordConfirm)
      Specified by:
      registerCustomer in interface CustomerService
    • createRegisteredCustomerRoles

      public void createRegisteredCustomerRoles(Customer customer)
      Description copied from interface: CustomerService
      Subclassed implementations can assign unique roles for various customer types
      Specified by:
      createRegisteredCustomerRoles in interface CustomerService
      Parameters:
      customer - Customer to create roles for
    • readCustomerByEmail

      public Customer readCustomerByEmail(String emailAddress)
      Specified by:
      readCustomerByEmail in interface CustomerService
    • changePassword

      @Transactional("blTransactionManager") public Customer changePassword(org.broadleafcommerce.common.security.util.PasswordChange passwordChange)
      Specified by:
      changePassword in interface CustomerService
    • resetPassword

      @Transactional("blTransactionManager") public Customer resetPassword(org.broadleafcommerce.common.security.util.PasswordReset passwordReset)
      Specified by:
      resetPassword in interface CustomerService
    • addPostRegisterListener

      public void addPostRegisterListener(PostRegistrationObserver postRegisterListeners)
      Specified by:
      addPostRegisterListener in interface CustomerService
    • removePostRegisterListener

      public void removePostRegisterListener(PostRegistrationObserver postRegisterListeners)
      Specified by:
      removePostRegisterListener in interface CustomerService
    • notifyPostRegisterListeners

      protected void notifyPostRegisterListeners(Customer customer)
    • createCustomer

      public Customer createCustomer()
      Specified by:
      createCustomer in interface CustomerService
    • createCustomerWithNullId

      public Customer createCustomerWithNullId()
      Description copied from interface: CustomerService
      Returns a non-persisted Customer with a null id. Typically used with registering a new customer or creating a new anonymous customer. Creating a customer with null id so that we don't need to query the database for the next id everytime an anonymous customer browses the site.
      Specified by:
      createCustomerWithNullId in interface CustomerService
    • createCustomerFromId

      public Customer createCustomerFromId(Long customerId)
      Description copied from interface: CustomerService
      Returns a Customer by first looking in the database, otherwise creating a new non-persisted Customer
      Specified by:
      createCustomerFromId in interface CustomerService
      Parameters:
      customerId - the id of the customer to lookup
    • findNextCustomerId

      public Long findNextCustomerId()
      Description copied from interface: CustomerService
      Allow customers to call from subclassed service.
      Specified by:
      findNextCustomerId in interface CustomerService
      Returns:
      the next customerId to be used
    • createNewCustomer

      @Deprecated public Customer createNewCustomer()
      Deprecated.
      Description copied from interface: CustomerService
      Returns a non-persisted Customer.
      Specified by:
      createNewCustomer in interface CustomerService
    • deleteCustomer

      public void deleteCustomer(Customer customer)
      Description copied from interface: CustomerService
      Delete the customer entity from the persistent store
      Specified by:
      deleteCustomer in interface CustomerService
      Parameters:
      customer - the customer entity to remove
    • detachCustomer

      public void detachCustomer(Customer customer)
      Description copied from interface: CustomerService
      Detaches the given Customer instance from the entity manager.
      Specified by:
      detachCustomer in interface CustomerService
    • readCustomerByUsername

      public Customer readCustomerByUsername(String username)
      Specified by:
      readCustomerByUsername in interface CustomerService
    • readCustomerByUsername

      public Customer readCustomerByUsername(String username, Boolean cacheable)
      Specified by:
      readCustomerByUsername in interface CustomerService
    • readCustomerById

      public Customer readCustomerById(Long id)
      Specified by:
      readCustomerById in interface CustomerService
    • readCustomerByExternalId

      public Customer readCustomerByExternalId(String userExternalId)
      Specified by:
      readCustomerByExternalId in interface CustomerService
    • setCustomerDao

      public void setCustomerDao(CustomerDao customerDao)
    • encodePassword

      public String encodePassword(String rawPassword)
      Description copied from interface: CustomerService
      Encodes the clear text parameter, using the salt provided by PasswordEncoder. Does not change the customer properties. This method only encodes the password and returns the encoded result.

      This method can only be called once per password. The salt is randomly generated internally in the PasswordEncoder and appended to the hash to provide the resulting encoded password. Once this has been called on a password, going forward all checks for authenticity must be done by CustomerService.isPasswordValid(String, String) as encoding the same password twice will result in different encoded passwords.

      Specified by:
      encodePassword in interface CustomerService
      Parameters:
      rawPassword - the unencoded password
      Returns:
      the encoded password
    • isPasswordValid

      public boolean isPasswordValid(String rawPassword, String encodedPassword)
      Description copied from interface: CustomerService
      Determines if a password is valid by comparing it to the encoded string, salting is handled internally to the PasswordEncoder.

      This method must always be called to verify if a password is valid after the original encoded password is generated due to PasswordEncoder randomly generating salts internally and appending them to the resulting hash.

      Specified by:
      isPasswordValid in interface CustomerService
      Parameters:
      rawPassword - the unencoded password
      encodedPassword - the encoded password to compare against
      Returns:
      true if the unencoded password matches the encoded password, false otherwise
    • customerPassesCustomerRule

      public boolean customerPassesCustomerRule(Customer customer, CustomerRuleHolder customerRuleHolder)
      Description copied from interface: CustomerService
      Determines if the given customer passes the MVEL customer rule
      Specified by:
      customerPassesCustomerRule in interface CustomerService
      customerRuleHolder - an MVEL rule targeting Customers
      Returns:
      true if the customer passes the rule, false otherwise
    • buildCustomerRuleParams

      protected Map<String,Object> buildCustomerRuleParams(Customer customer)
    • getPasswordResetHandlers

      public List<PasswordUpdatedHandler> getPasswordResetHandlers()
      Specified by:
      getPasswordResetHandlers in interface CustomerService
    • setPasswordResetHandlers

      public void setPasswordResetHandlers(List<PasswordUpdatedHandler> passwordResetHandlers)
      Specified by:
      setPasswordResetHandlers in interface CustomerService
    • getPasswordChangedHandlers

      public List<PasswordUpdatedHandler> getPasswordChangedHandlers()
      Specified by:
      getPasswordChangedHandlers in interface CustomerService
    • setPasswordChangedHandlers

      public void setPasswordChangedHandlers(List<PasswordUpdatedHandler> passwordChangedHandlers)
      Specified by:
      setPasswordChangedHandlers in interface CustomerService
    • sendForgotUsernameNotification

      @Transactional("blTransactionManager") public org.broadleafcommerce.common.service.GenericResponse sendForgotUsernameNotification(String emailAddress)
      Description copied from interface: CustomerService
      Looks up the corresponding Customer and emails the address on file with the associated username.
      Specified by:
      sendForgotUsernameNotification in interface CustomerService
      Parameters:
      emailAddress - user's email address
      Returns:
      Response can contain errors including (notFound)
    • sendForgotPasswordNotification

      @Transactional("blTransactionManager") public org.broadleafcommerce.common.service.GenericResponse sendForgotPasswordNotification(String username, String resetPasswordUrl)
      Description copied from interface: CustomerService
      Generates an access token and then emails the user.
      Specified by:
      sendForgotPasswordNotification in interface CustomerService
      Parameters:
      username - - the user to send a reset password email to.
      resetPasswordUrl - - Base url to include in the email.
      Returns:
      Response can contain errors including (invalidEmail, invalidUsername, inactiveUser)
    • sendForcedPasswordChangeNotification

      @Transactional("blTransactionManager") public org.broadleafcommerce.common.service.GenericResponse sendForcedPasswordChangeNotification(String username, String resetPasswordUrl)
      Description copied from interface: CustomerService
      Generates an access token and then emails the user.
      Specified by:
      sendForcedPasswordChangeNotification in interface CustomerService
      Parameters:
      username - - the user to send a reset password email to.
      resetPasswordUrl - - Base url to include in the email.
      Returns:
      Response can contain errors including (invalidEmail, invalidUsername, inactiveUser)
    • checkPasswordResetToken

      public org.broadleafcommerce.common.service.GenericResponse checkPasswordResetToken(String token, Customer customer)
      Description copied from interface: CustomerService
      Verifies that a customer has a valid token.
      Specified by:
      checkPasswordResetToken in interface CustomerService
      Parameters:
      token - password reset token
      customer - Customer who owns the token
      Returns:
      Response can contain errors including (invalidToken, tokenUsed, and tokenExpired)
    • checkPasswordResetToken

      protected CustomerForgotPasswordSecurityToken checkPasswordResetToken(String token, Customer customer, org.broadleafcommerce.common.service.GenericResponse response)
    • resetPasswordUsingToken

      @Transactional("blTransactionManager") public org.broadleafcommerce.common.service.GenericResponse resetPasswordUsingToken(String username, String token, String password, String confirmPassword)
      Description copied from interface: CustomerService
      Updates the password for the passed in customer only if the passed in token is valid for that customer.
      Specified by:
      resetPasswordUsingToken in interface CustomerService
      Parameters:
      username - Username of the customer
      token - Valid reset token
      password - new password
      Returns:
      Response can contain errors including (invalidUsername, inactiveUser, invalidToken, invalidPassword, tokenExpired)
    • invalidateAllTokensForCustomer

      protected void invalidateAllTokensForCustomer(Customer customer)
    • checkCustomer

      protected void checkCustomer(Customer customer, org.broadleafcommerce.common.service.GenericResponse response)
    • checkPassword

      protected void checkPassword(String password, String confirmPassword, org.broadleafcommerce.common.service.GenericResponse response)
    • isTokenExpired

      protected boolean isTokenExpired(CustomerForgotPasswordSecurityToken fpst)
    • getTokenExpiredMinutes

      public int getTokenExpiredMinutes()
    • setTokenExpiredMinutes

      public void setTokenExpiredMinutes(int tokenExpiredMinutes)
    • getPasswordTokenLength

      public int getPasswordTokenLength()
    • setPasswordTokenLength

      public void setPasswordTokenLength(int passwordTokenLength)
    • readBatchCustomers

      public List<Customer> readBatchCustomers(int start, int pageSize)
      Specified by:
      readBatchCustomers in interface CustomerService
    • readNumberOfCustomers

      public Long readNumberOfCustomers()
      Specified by:
      readNumberOfCustomers in interface CustomerService