Ejemplo n.º 1
0
  /**
   * Set the groups for this role manager This will replace any existing group that may exist
   * already
   *
   * @param groups the groups to add
   */
  public void setGroups(List<Group> groups) {
    this.roles = new HashMap<String, Role>();

    if (groups != null) {
      for (Group group : groups) {
        List<Role> currentGroupRoles = group.getRoles();

        for (Role role : currentGroupRoles) {
          Role existingRole = this.roles.get(role.getName());

          if (existingRole == null) {
            this.roles.put(role.getName(), new Role(role));
          } else {
            // Handle the very special case of read only and reply only
            if (role.getName().equals(SecurityConstants.FORUM_READ_ONLY)
                || role.getName().equals(SecurityConstants.FORUM_REPLY_ONLY)) {
              existingRole.getRoleValues().retainAll(role.getRoleValues());
            } else {
              existingRole.getRoleValues().addAll(role.getRoleValues());
            }
          }
        }
      }

      this.readReplyOnlySecondPass(SecurityConstants.FORUM_READ_ONLY, groups);
      this.readReplyOnlySecondPass(SecurityConstants.FORUM_REPLY_ONLY, groups);
    }
  }
Ejemplo n.º 2
0
  private void readReplyOnlySecondPass(String roleName, List<Group> groups) {
    Role role = this.roles.get(roleName);

    if (role != null) {
      for (int forumId : new ArrayList<Integer>(role.getRoleValues())) {
        for (Group g : groups) {
          if (g.roleExists(SecurityConstants.FORUM, forumId) && !g.roleExists(roleName, forumId)) {
            role.getRoleValues().remove((Object) forumId);
          }
        }
      }
    }
  }
Ejemplo n.º 3
0
  public void appendRole(Group group, String roleName, int roleValue) {
    for (Role role : group.getRoles()) {
      if (role.getName().equals(roleName)) {
        role.getRoleValues().add(roleValue);
        break;
      }
    }

    this.repository.update(group);
  }
Ejemplo n.º 4
0
  /**
   * Return all values (if any) associated to a specific role
   *
   * @param name the role name
   * @return the role values (if any)
   */
  public int[] getRoleValues(String name) {
    Role role = this.get(name);

    if (role == null || role.getRoleValues().size() == 0) {
      return new int[0];
    }

    // This is lame, but due to the dificulties of
    // working with int... versus Integer...
    // versus int[] and Integer[] in some other classes,
    // and that .toArray() does not work with int itself,
    // we do the copy by hand there.
    int[] data = new int[role.getRoleValues().size()];
    int counter = 0;
    for (int value : role.getRoleValues()) {
      data[counter++] = value;
    }

    return data;
  }
Ejemplo n.º 5
0
 public boolean roleExists(String name, int value) {
   Role role = this.get(name);
   return role != null && role.getRoleValues().contains(value);
 }
Ejemplo n.º 6
0
 public List<Integer> getRoleValuesAsList(String name) {
   Role role = this.get(name);
   return role != null ? role.getRoleValues() : new ArrayList<Integer>();
 }