예제 #1
0
 /**
  * Returns all roles that are assignable to a given user
  *
  * @return all the role labels that are assignable to a user.
  */
 private Set<String> getAssignableRoles(User user) {
   Set<String> assignableRoles = new LinkedHashSet<String>();
   for (Role r : UserManager.listRolesAssignableBy(user)) {
     assignableRoles.add(r.getLabel());
   }
   return assignableRoles;
 }
예제 #2
0
  /**
   * Lists the roles for a user
   *
   * @param loggedInUser The current user
   * @param login The login for the user you want to get the roles for
   * @return Returns a list of roles for the user specified by login
   * @throws FaultException A FaultException is thrown if the user doesn't have access to lookup the
   *     user corresponding to login or if the user does not exist.
   * @xmlrpc.doc Returns a list of the user's roles.
   * @xmlrpc.param #param("string", "sessionKey")
   * @xmlrpc.param #param_desc("string", "login", "User's login name.")
   * @xmlrpc.returntype #array_single("string", "(role label)")
   */
  public Object[] listRoles(User loggedInUser, String login) throws FaultException {
    // Get the logged in user
    User target = XmlRpcUserHelper.getInstance().lookupTargetUser(loggedInUser, login);
    List roles = new ArrayList(); // List of role labels to return

    // Loop through the target users roles and stick the labels into the ArrayList
    Set roleObjects = target.getPermanentRoles();
    for (Iterator itr = roleObjects.iterator(); itr.hasNext(); ) {
      Role r = (Role) itr.next();
      roles.add(r.getLabel());
    }

    return roles.toArray();
  }