Esempio n. 1
0
  /**
   * remove system group association from a user
   *
   * @param loggedInUser The current user
   * @param login the user's login that we want to remove the association from
   * @param systemGroupNames list of system group names to remove
   * @param setDefault if true the default group will be removed from the users's group defaults
   * @return 1 on success
   * @xmlrpc.doc Remove system groups from a user's list of assigned system groups.
   * @xmlrpc.param #param("string", "sessionKey")
   * @xmlrpc.param #param_desc("string", "login", "User's login name.")
   * @xmlrpc.param #array_single("string", "serverGroupName")
   * @xmlrpc.param #param_desc("boolean", "setDefault", "Should system groups also be removed from
   *     the user's list of default system groups.")
   * @xmlrpc.returntype #return_int_success()
   */
  public int removeAssignedSystemGroups(
      User loggedInUser, String login, List<String> systemGroupNames, Boolean setDefault) {
    ensureUserRole(loggedInUser, RoleFactory.ORG_ADMIN);

    if (setDefault) {
      removeDefaultSystemGroups(loggedInUser, login, systemGroupNames);
    }

    User user = UserManager.lookupUser(loggedInUser, login);
    ServerGroupManager manager = ServerGroupManager.getInstance();

    // Iterate once to lookup the server groups and avoid removing some when
    // an exception will only be thrown later:
    List<ManagedServerGroup> groups = new LinkedList<ManagedServerGroup>();
    for (String name : systemGroupNames) {
      ManagedServerGroup sg = null;
      try {
        sg = manager.lookup(name, user);
      } catch (LookupException e) {
        throw new InvalidServerGroupException();
      }
      groups.add(sg);
    }

    for (ManagedServerGroup sg : groups) {
      UserManager.revokeServerGroupPermission(user, sg.getId().longValue());
    }

    return 1;
  }
Esempio n. 2
0
  /**
   * Add to the user's list of assigned system groups.
   *
   * @param loggedInUser The current user
   * @param login User to modify.
   * @param sgNames List of server group Names.
   * @param setDefault True to also add groups to the user's default system groups.
   * @return Returns 1 if successful (exception thrown otherwise)
   * @xmlrpc.doc Add system groups to user's list of assigned system groups.
   * @xmlrpc.param #param("string", "sessionKey")
   * @xmlrpc.param #param_desc("string", "login", "User's login name.")
   * @xmlrpc.param #array_single("string", "serverGroupName")
   * @xmlrpc.param #param_desc("boolean", "setDefault", "Should system groups also be added to
   *     user's list of default system groups.")
   * @xmlrpc.returntype #return_int_success()
   */
  public int addAssignedSystemGroups(
      User loggedInUser, String login, List sgNames, Boolean setDefault) {

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

    if (sgNames == null || sgNames.size() < 1) {
      throw new IllegalArgumentException("no servergroup names supplied");
    }

    // Iterate once just to make sure all the server groups exist. Done to
    // prevent adding a bunch of valid groups and then throwing an exception
    // when coming across one that doesn't exist.
    List<ManagedServerGroup> groups = new LinkedList<ManagedServerGroup>();
    for (Iterator it = sgNames.iterator(); it.hasNext(); ) {
      String serverGroupName = (String) it.next();

      // Make sure the server group exists:
      ServerGroupManager manager = ServerGroupManager.getInstance();
      ManagedServerGroup group;
      try {
        group = manager.lookup(serverGroupName, loggedInUser);
      } catch (LookupException e) {
        throw new InvalidServerGroupException();
      }
      groups.add(group);
    }

    // Now do the actual add:
    for (ManagedServerGroup group : groups) {
      UserManager.grantServerGroupPermission(targetUser, group.getId());
    }

    // Follow up with a call to addDefaultSystemGroups if setDefault is true:
    if (setDefault.booleanValue()) {
      addDefaultSystemGroups(loggedInUser, login, sgNames);
    }

    return 1;
  }