Пример #1
0
  /**
   * Returns default system groups for the given login.
   *
   * @param loggedInUser The current user in user.
   * @param login The login for the user whose Default ServerGroup list is sought.
   * @return default system groups for the given login
   * @xmlrpc.doc Returns a user's list of default system groups.
   * @xmlrpc.param #param("string", "sessionKey")
   * @xmlrpc.param #param_desc("string", "login", "User's login name.")
   * @xmlrpc.returntype #array() #struct("system group") #prop("int", "id") #prop("string", "name")
   *     #prop("string", "description") #prop("int", "system_count") #prop_desc("int", "org_id",
   *     "Organization ID for this system group.") #struct_end() #array_end()
   */
  public Object[] listDefaultSystemGroups(User loggedInUser, String login) {
    User target = XmlRpcUserHelper.getInstance().lookupTargetUser(loggedInUser, login);
    Set<Long> ids = target.getDefaultSystemGroupIds();

    List<ServerGroup> sgs = new ArrayList(ids.size());
    for (Long id : ids) {
      sgs.add(ServerGroupFactory.lookupByIdAndOrg(id, target.getOrg()));
    }
    return sgs.toArray();
  }
Пример #2
0
  /**
   * Add ServerGroups to the list of Default System groups. The ServerGroups <strong>MUST</strong>
   * exist otherwise a IllegalArgumentException is thrown.
   *
   * @param loggedInUser The current user in user.
   * @param login The login for the user whose Default ServerGroup list will be affected.
   * @param sgNames names of ServerGroups.
   * @return Returns 1 if successful (exception otherwise)
   * @xmlrpc.doc Add system groups to user's list of default system groups.
   * @xmlrpc.param #param("string", "sessionKey")
   * @xmlrpc.param #param_desc("string", "login", "User's login name.")
   * @xmlrpc.param #array_single("string", "serverGroupName")
   * @xmlrpc.returntype #return_int_success()
   */
  public int addDefaultSystemGroups(User loggedInUser, String login, List sgNames) {

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

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

    List groups = ServerGroupFactory.listManagedGroups(target.getOrg());

    Map groupMap = new HashMap();

    // sigh.  After looking through all of the apache collections package
    // I couldn't find anything that would create a map from a list using
    // a property from the object in the list as the key. This is where
    // python would be useful.
    for (Iterator itr = groups.iterator(); itr.hasNext(); ) {
      ServerGroup sg = (ServerGroup) itr.next();
      groupMap.put(sg.getName(), sg);
    }

    // Doing full check of all supplied names, if one is bad
    // throw an exception, prior to altering the DefaultSystemGroup Set.
    for (Iterator itr = sgNames.iterator(); itr.hasNext(); ) {
      String name = (String) itr.next();
      ServerGroup sg = (ServerGroup) groupMap.get(name);
      if (sg == null) {
        throw new LookupServerGroupException(name);
      }
    }

    // now for the real reason we're in this method.
    Set defaults = target.getDefaultSystemGroupIds();
    for (Iterator itr = sgNames.iterator(); itr.hasNext(); ) {
      ServerGroup sg = (ServerGroup) groupMap.get(itr.next());
      if (sg != null) {
        // not a simple add to the groups.  Needs to call
        // UserManager as DataSource is being used.
        defaults.add(sg.getId());
      }
    }

    UserManager.setDefaultSystemGroupIds(target, defaults);
    UserManager.storeUser(target);

    return 1;
  }
Пример #3
0
 /**
  * Get the set of ManagedServerGroups that this Org is a member of.
  *
  * @return List of ServerGroup classes
  */
 public List<ManagedServerGroup> getManagedServerGroups() {
   return ServerGroupFactory.listManagedGroups(this);
 }
Пример #4
0
 /**
  * Get the set of EntitlementServerGroups that this Org is a member of.
  *
  * @return List of ServerGroup classes
  */
 public List<EntitlementServerGroup> getEntitledServerGroups() {
   return ServerGroupFactory.listEntitlementGroups(this);
 }
Пример #5
0
 /**
  * Returns the ServerGroups that the user can administer.
  *
  * @param loggedInUser The current user in user.
  * @param login The login for the user whose ServerGroups are sought.
  * @return the ServerGroups that the user can administer.
  * @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 the system groups that a user can administer.
  * @xmlrpc.param #param("string", "sessionKey")
  * @xmlrpc.param #param_desc("string", "login", "User's login name.")
  * @xmlrpc.returntype #array() #struct("system group") #prop("int", "id") #prop("string", "name")
  *     #prop("string", "description") #prop("int", "system_count") #prop_desc("int", "org_id",
  *     "Organization ID for this system group.") #struct_end() #array_end()
  */
 public Object[] listAssignedSystemGroups(User loggedInUser, String login) throws FaultException {
   User target = XmlRpcUserHelper.getInstance().lookupTargetUser(loggedInUser, login);
   List groups = ServerGroupFactory.listAdministeredServerGroups(target);
   return groups.toArray();
 }