public UserListWrapper(List<IPentahoUser> users) {
   List<String> userList = new ArrayList<String>();
   for (IPentahoUser user : users) {
     userList.add(user.getUsername());
   }
   this.users.addAll(userList);
 }
  /**
   * Checks to see if the removal of the received roles and users would cause the system to have no
   * login associated with the Admin role. This check is to be made before any changes take place
   *
   * @param deleteRoles Roles to be deleted separated with | char
   * @param deleteUsers Users to be deleted separated with | char
   * @return Error message if invalid or null if ok
   * @throws RepositoryException
   */
  private boolean canDeleteUser(Session session, final IPentahoUser user)
      throws RepositoryException {
    boolean userHasAdminRole = false;
    List<IPentahoRole> roles = getUserRoles(null, user.getUsername());
    for (IPentahoRole role : roles) {
      if (tenantAdminRoleName.equals(role.getName())) {
        userHasAdminRole = true;
        break;
      }
    }
    if (userHasAdminRole) {
      List<IPentahoUser> usersWithAdminRole = getRoleMembers(session, null, tenantAdminRoleName);
      if (usersWithAdminRole != null) {

      } else {
        throw new RepositoryException(
            Messages.getInstance()
                .getString(
                    "AbstractJcrBackedUserRoleDao.ERROR_0004_LAST_USER_NEEDED_IN_ROLE",
                    tenantAdminRoleName));
      }
      if (usersWithAdminRole.size() > 1) {
        return true;
      } else if (usersWithAdminRole.size() == 1) {
        return false;
      } else {
        throw new RepositoryException(
            Messages.getInstance()
                .getString(
                    "AbstractJcrBackedUserRoleDao.ERROR_0004_LAST_USER_NEEDED_IN_ROLE",
                    tenantAdminRoleName));
      }
    }
    return true;
  }
  public void deleteUser(Session session, final IPentahoUser user)
      throws NotFoundException, RepositoryException {
    if (canDeleteUser(session, user)) {
      User jackrabbitUser = getJackrabbitUser(user.getTenant(), user.getUsername(), session);
      if (jackrabbitUser != null
          && TenantUtils.isAccessibleTenant(
              tenantedUserNameUtils.getTenant(jackrabbitUser.getID()))) {

        // [BISERVER-9215] Adding new user with same user name as a previously deleted user,
        // defaults to all previous roles
        Iterator<Group> currentGroups = jackrabbitUser.memberOf();
        while (currentGroups.hasNext()) {
          currentGroups.next().removeMember(jackrabbitUser);
        }
        // [BISERVER-9215]

        jackrabbitUser.remove();
      } else {
        throw new NotFoundException(""); // $NON-NLS-1$
      }
    } else {
      throw new RepositoryException(
          Messages.getInstance()
              .getString(
                  "AbstractJcrBackedUserRoleDao.ERROR_0004_LAST_USER_NEEDED_IN_ROLE",
                  tenantAdminRoleName));
    }
  }
Esempio n. 4
0
 /** Copy constructor */
 public PentahoUser(IPentahoUser userToCopy) {
   this.username = userToCopy.getUsername();
   this.description = userToCopy.getDescription();
   this.enabled = userToCopy.isEnabled();
 }