コード例 #1
0
ファイル: UserHandler.java プロジェクト: pgervase/spacewalk
 /**
  * Handles the vagaries related to granting or revoking sat admin role
  *
  * @param loggedInUser the logged in user
  * @param login the login of the user who needs to be granted/revoked sat admin role
  * @param grant true if granting the role to the login, false for revoking...
  * @return 1 if it success.. Ofcourse error on failure..
  */
 private int modifySatAdminRole(User loggedInUser, String login, boolean grant) {
   ensureUserRole(loggedInUser, RoleFactory.SAT_ADMIN);
   SatManager manager = SatManager.getInstance();
   User user = UserFactory.lookupByLogin(login);
   if (grant) {
     manager.grantSatAdminRoleTo(user, loggedInUser);
   } else {
     manager.revokeSatAdminRoleFrom(user, loggedInUser);
   }
   UserManager.storeUser(user);
   return 1;
 }
コード例 #2
0
ファイル: UserHandler.java プロジェクト: pgervase/spacewalk
  /**
   * @param loggedInUser The current user
   * @param login User to modify.
   * @param readOnly readOnly flag to set
   * @return 1 (should always succeed)
   * @xmlrpc.doc Sets whether the target user should have only read-only API access or standard full
   *     scale access.
   * @xmlrpc.param #param("string", "sessionKey")
   * @xmlrpc.param #param_desc("string", "login", "User's login name.")
   * @xmlrpc.param #param_desc("boolean", "readOnly", "Sets whether the target user should have only
   *     read-only API access or standard full scale access.")
   * @xmlrpc.returntype #return_int_success()
   */
  public int setReadOnly(User loggedInUser, String login, Boolean readOnly) {
    // Logged in user must be an org admin.
    ensureOrgAdmin(loggedInUser);

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

    if (readOnly
        && targetUser.hasRole(RoleFactory.ORG_ADMIN)
        && targetUser.getOrg().numActiveOrgAdmins() < 2) {
      throw new InvalidOperationException(
          "error.readonly_org_admin", targetUser.getOrg().getName());
    }
    if (readOnly
        && targetUser.hasRole(RoleFactory.SAT_ADMIN)
        && SatManager.getActiveSatAdmins().size() < 2) {
      throw new InvalidOperationException("error.readonly_sat_admin");
    }
    targetUser.setReadOnly(readOnly);
    return 1;
  }