コード例 #1
0
  /**
   * Returns a collection with all roles matching a given key-value pair.
   *
   * @param key the key to search for;
   * @param value the value to search for.
   * @return a list with all matching roles, can be empty, but never <code>null</code>.
   */
  public List getRoles(String key, String value) {
    if (key == null) {
      throw new IllegalArgumentException("Key cannot be null!");
    }
    if (value == null) {
      throw new IllegalArgumentException("Value cannot be null!");
    }

    List matchingRoles = new ArrayList();

    try {
      String criteria = "(".concat(key).concat("=").concat(value).concat(")");

      Role[] roles = m_store.getRoles(criteria);
      for (int i = 0; i < roles.length; i++) {
        Role role = roles[i];
        if (!isPredefinedRole(role.getName())) {
          matchingRoles.add(wireChangeListener(role));
        }
      }
    } catch (Exception e) {
      throw new BackendException("Failed to get roles!", e);
    }

    return matchingRoles;
  }
コード例 #2
0
 /**
  * Removes a given role as (required)member from any groups it is member of.
  *
  * @param removedRole the role that is removed from the store already, cannot be <code>null</code>
  *     .
  * @throws BackendException in case of problems accessing the store.
  */
 private void removeRoleFromAllGroups(Role removedRole) {
   try {
     Role[] roles = m_store.getRoles(null);
     for (int i = 0; i < roles.length; i++) {
       if (roles[i].getType() == Role.GROUP) {
         Group group = (Group) roles[i];
         // Don't check whether the given role is actually a member
         // of the group, but let the group itself figure this out...
         group.removeMember(removedRole);
       }
     }
   } catch (Exception e) {
     throw new BackendException("Failed to get all roles!", e);
   }
 }
コード例 #3
0
  /**
   * Returns a collection with all roles matching a given filter.
   *
   * @param filter the filter to match the individual roles against, can be <code>null</code> if all
   *     roles should be returned.
   * @return a list with all matching roles, can be empty, but never <code>null</code>.
   */
  public List getRoles(String filter) {
    List matchingRoles = new ArrayList();

    try {
      Role[] roles = m_store.getRoles(sanitizeFilter(filter));
      for (int i = 0; i < roles.length; i++) {
        Role role = roles[i];
        if (!isPredefinedRole(role.getName())) {
          matchingRoles.add(wireChangeListener(role));
        }
      }
    } catch (Exception e) {
      throw new BackendException("Failed to get roles!", e);
    }

    return matchingRoles;
  }