Пример #1
0
 public UserListWrapper(List<IPentahoUser> users) {
   List<String> userList = new ArrayList<String>();
   for (IPentahoUser user : users) {
     userList.add(user.getUsername());
   }
   this.users.addAll(userList);
 }
  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));
    }
  }
  /**
   * 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 List<IPentahoUser> getUsers(
     Session session, final ITenant theTenant, boolean includeSubtenants)
     throws RepositoryException {
   ArrayList<IPentahoUser> users = new ArrayList<IPentahoUser>();
   if (TenantUtils.isAccessibleTenant(theTenant)) {
     UserManager userMgr = getUserManager(theTenant, session);
     pPrincipalName = ((SessionImpl) session).getJCRName(P_PRINCIPAL_NAME);
     Iterator<Authorizable> it =
         userMgr.findAuthorizables(pPrincipalName, null, UserManager.SEARCH_TYPE_USER);
     while (it.hasNext()) {
       User user = (User) it.next();
       IPentahoUser pentahoUser = convertToPentahoUser(user);
       if (includeSubtenants) {
         users.add(pentahoUser);
       } else {
         if (pentahoUser.getTenant() != null && pentahoUser.getTenant().equals(theTenant)) {
           users.add(pentahoUser);
         }
       }
     }
   }
   return users;
 }
Пример #5
0
 /** Copy constructor */
 public PentahoUser(IPentahoUser userToCopy) {
   this.username = userToCopy.getUsername();
   this.description = userToCopy.getDescription();
   this.enabled = userToCopy.isEnabled();
 }