예제 #1
0
  /**
   * Removes a role from the given user
   *
   * @param loggedInUser The current user
   * @param login The login for the user you would like to remove the role from
   * @param role The role you would like to remove from the user
   * @return Returns 1 if successful (exception otherwise)
   * @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 Remove a role from a user.
   * @xmlrpc.param #param("string", "sessionKey")
   * @xmlrpc.param #param_desc("string", "login", "User login name to update.")
   * @xmlrpc.param #param_desc("string", "role", "Role label to remove. Can be any of:
   *     satellite_admin, org_admin, channel_admin, config_admin, system_group_admin,
   *     activation_key_admin, or monitoring_admin.")
   * @xmlrpc.returntype #return_int_success()
   */
  public int removeRole(User loggedInUser, String login, String role) throws FaultException {
    validateRoleInputs(role, loggedInUser);

    if (RoleFactory.SAT_ADMIN.getLabel().equals(role)) {
      return modifySatAdminRole(loggedInUser, login, false);
    }

    ensureOrgAdmin(loggedInUser);
    User target = XmlRpcUserHelper.getInstance().lookupTargetUser(loggedInUser, login);

    /*
     * Perform some error checking here... we need to make sure that this
     * isn't the last org_admin in the org trying to remove org_admin
     * status from himself.
     */
    if (role.equals(RoleFactory.ORG_ADMIN.getLabel())
        && target.hasRole(RoleFactory.ORG_ADMIN)
        && target.getOrg().numActiveOrgAdmins() <= 1) {
      throw new PermissionCheckFailureException();
    }

    // Retrieve the role object corresponding to the role label passed in and
    // remove from user
    Role r = RoleFactory.lookupByLabel(role);
    target.removePermanentRole(r);

    UserManager.storeUser(target);
    return 1;
  }
예제 #2
0
 /**
  * Adds a role to the given user
  *
  * @param loggedInUser The current user
  * @param login The login for the user you would like to add the role to
  * @param role The role you would like to give the user
  * @return Returns 1 if successful (exception otherwise)
  * @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 Adds a role to a user.
  * @xmlrpc.param #param("string", "sessionKey")
  * @xmlrpc.param #param_desc("string", "login", "User login name to update.")
  * @xmlrpc.param #param_desc("string", "role", "Role label to add. Can be any of: satellite_admin,
  *     org_admin, channel_admin, config_admin, system_group_admin, activation_key_admin, or
  *     monitoring_admin.")
  * @xmlrpc.returntype #return_int_success()
  */
 public int addRole(User loggedInUser, String login, String role) throws FaultException {
   validateRoleInputs(role, loggedInUser);
   if (RoleFactory.SAT_ADMIN.getLabel().equals(role)) {
     return modifySatAdminRole(loggedInUser, login, true);
   }
   User target = XmlRpcUserHelper.getInstance().lookupTargetUser(loggedInUser, login);
   // Retrieve the role object corresponding to the role label passed in and
   // add to user
   Role r = RoleFactory.lookupByLabel(role);
   target.addPermanentRole(r);
   UserManager.storeUser(target);
   return 1;
 }