Class DefaultAccountMemberRoleChangeRequestHandler

java.lang.Object
com.broadleafcommerce.auth.user.service.DefaultAccountMemberRoleChangeRequestHandler
All Implemented Interfaces:
AccountMemberRoleChangeRequestHandler

public class DefaultAccountMemberRoleChangeRequestHandler extends Object implements AccountMemberRoleChangeRequestHandler
Respond to AccountMemberRoleChangeRequest to update User roles when an Account Member's roles are updated.
Author:
Cade Rea (cade-rea)
  • Field Details

  • Constructor Details

  • Method Details

    • handle

      public void handle(AccountMemberRoleChangeRequest request)
      When an AccountMember record is updated, update the account roles on the User. If an AccountMember is deleted, remove all roles the user has for that account.
      Specified by:
      handle in interface AccountMemberRoleChangeRequestHandler
      Parameters:
      request - The AccountMemberRoleChangeRequest message.
    • getRolesForAccount

      protected List<AccountRole> getRolesForAccount(List<AccountRole> accountRoles, String accountId)
      Get all of a user's AccountRoles for a particular account.
      Parameters:
      accountRoles - The list of all of a user's AccountRoles.
      accountId - The id of the account whose roles are being collected.
      Returns:
      A filtered list of AccountRoles for the given account id.
    • getNewRolesForAccount

      protected List<AccountRole> getNewRolesForAccount(AccountMemberRoleChangeRequest request)
      Build the list of AccountRoles from the updated AccountMember. If an AccountMember is deleted, return an empty list. If the account is not active, all AccountRoles returned will be inactive. The returned list will include the default account member roles.
      Parameters:
      request - The AccountMemberRoleChangeRequest message.
      Returns:
      The list of AccountRoles that should be assigned to the User.
    • shouldUpdateRoles

      protected boolean shouldUpdateRoles(List<AccountRole> existingRolesForAccount, List<AccountRole> newRolesForAccount)
      Sort the lists of AccountRoles by role id and then compare.
      Parameters:
      existingRolesForAccount - The list of AccountRoles that are already assigned to the User.
      newRolesForAccount - The list of AccountRoles that the User should have.
      Returns:
      true if the two lists do not contain the same roles.
    • getDefaultMemberRoles

      protected List<String> getDefaultMemberRoles()
      Get a list of role ids that all account members should receive.
      Returns:
      a list of role ids that all account members should receive.
    • buildAccountRolesList

      protected List<AccountRole> buildAccountRolesList(String accountId, String userId, Set<String> newRoleIdsForAccount, boolean accountIsActive)
      Transforms role IDs into Account Roles. This will validate that a given role id is a valid account role. This also ensures that the default account member role is present.
      Parameters:
      accountId - The id of the account of which the user is getting roles.
      userId - The id of the User that corresponds to the AccountMember that was updated.
      newRoleIdsForAccount - List of role ids to assign to the user for the account.
      accountIsActive - Indicates if the account is active and controls the status of new roles.
      Returns:
      A list of valid Account Roles from the given list of role IDs.
    • buildAccountRole

      protected AccountRole buildAccountRole(String accountId, String userId, UserRole role, boolean active)
      Build an AccountRole from account id, user, and role.
      Parameters:
      accountId - The id of the account to which the role will apply.
      userId - The id of the user receiving the role.
      role - The role to be assigned.
      active - If the role should be created as active. This is usually true, but here just in case roles are added to a member of a deactivated account.
      Returns:
      An new, non-persisted, AccountRole.
    • getUserService

      protected UserService<User> getUserService()
    • getUserRoleService

      protected UserRoleService<UserRole> getUserRoleService()