/** This method gets a users roles */
  public List authorizeUser(String userName) throws Exception {
    List roles = new ArrayList();
    List groups = new ArrayList();

    String administratorUserName = CmsPropertyHandler.getAdministratorUserName();

    boolean isAdministrator = userName.equalsIgnoreCase(administratorUserName) ? true : false;
    if (isAdministrator) return roles;

    if (transactionObject == null) {
      List roleVOList = RoleController.getController().getRoleVOList(userName);
      Iterator roleVOListIterator = roleVOList.iterator();
      while (roleVOListIterator.hasNext()) {
        RoleVO roleVO = (RoleVO) roleVOListIterator.next();
        InfoGlueRole infoGlueRole =
            new InfoGlueRole(roleVO.getRoleName(), roleVO.getDescription(), this);
        roles.add(infoGlueRole);
      }

      List groupVOList = GroupController.getController().getGroupVOList(userName);
      Iterator groupVOListIterator = groupVOList.iterator();
      while (groupVOListIterator.hasNext()) {
        GroupVO groupVO = (GroupVO) groupVOListIterator.next();
        InfoGlueGroup infoGlueGroup =
            new InfoGlueGroup(groupVO.getGroupName(), groupVO.getDescription(), this);
        groups.add(infoGlueGroup);
      }
    } else {
      Collection roleList = RoleController.getController().getRoleList(userName, transactionObject);
      Iterator roleListIterator = roleList.iterator();
      while (roleListIterator.hasNext()) {
        Role role = (Role) roleListIterator.next();
        InfoGlueRole infoGlueRole =
            new InfoGlueRole(role.getRoleName(), role.getDescription(), this);
        roles.add(infoGlueRole);
      }

      Collection groupList =
          GroupController.getController().getGroupList(userName, transactionObject);
      Iterator groupListIterator = groupList.iterator();
      while (groupListIterator.hasNext()) {
        Group group = (Group) groupListIterator.next();
        InfoGlueGroup infoGlueGroup =
            new InfoGlueGroup(group.getGroupName(), group.getDescription(), this);
        groups.add(infoGlueGroup);
      }
    }

    return groups;
  }
Ejemplo n.º 2
0
  public List getFilteredSystemUserList(
      String firstName,
      String lastName,
      String userName,
      String email,
      String[] roleNames,
      Database db)
      throws SystemException, Bug, Exception {
    List filteredList = new ArrayList();

    OQLQuery oql =
        db.getOQLQuery(
            "SELECT u FROM org.infoglue.cms.entities.management.impl.simple.SystemUserImpl u ORDER BY u.userName");

    QueryResults results = oql.execute(Database.ReadOnly);

    while (results.hasMore()) {
      SystemUser extranetUser = (SystemUser) results.next();
      boolean include = true;

      if (firstName != null
          && !firstName.equals("")
          && extranetUser.getFirstName().toLowerCase().indexOf(firstName.toLowerCase()) == -1)
        include = false;

      if (lastName != null
          && !lastName.equals("")
          && extranetUser.getLastName().toLowerCase().indexOf(lastName.toLowerCase()) == -1)
        include = false;

      if (userName != null
          && !userName.equals("")
          && extranetUser.getUserName().toLowerCase().indexOf(userName.toLowerCase()) == -1)
        include = false;

      if (email != null
          && !email.equals("")
          && extranetUser.getEmail().toLowerCase().indexOf(email.toLowerCase()) == -1)
        include = false;

      boolean hasRoles = true;
      if (roleNames != null && roleNames.length > 0) {
        for (int i = 0; i < roleNames.length; i++) {
          String roleName = roleNames[i];
          if (roleName != null && !roleName.equals("")) {
            Collection roles = extranetUser.getRoles();
            Iterator rolesIterator = roles.iterator();
            boolean hasRole = false;
            while (rolesIterator.hasNext()) {
              Role role = (Role) rolesIterator.next();
              if (role.getRoleName().equalsIgnoreCase(roleName)) {
                hasRole = true;
                break;
              }
            }

            if (!hasRole) {
              hasRoles = false;
              break;
            }
          }
        }
      }

      if (include && hasRoles) filteredList.add(extranetUser);
    }

    results.close();
    oql.close();

    return filteredList;
  }