Example #1
0
  /**
   * Services a Commandline Request.
   *
   * @param rc Request Context.
   * @throw CLIException if the request cannot serviced.
   */
  public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();

    SSOToken adminSSOToken = getAdminSSOToken();
    IOutput outputWriter = getOutputWriter();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String agentGroupName = getStringOptionValue(IArgument.AGENT_GROUP_NAME);
    List agentNames = rc.getOption(IArgument.AGENT_NAMES);
    String[] params = {realm, agentGroupName, ""};
    String agentName = "";
    try {
      AMIdentity amidGroup =
          new AMIdentity(adminSSOToken, agentGroupName, IdType.AGENTGROUP, realm, null);

      for (Iterator i = agentNames.iterator(); i.hasNext(); ) {
        agentName = (String) i.next();
        params[2] = agentName;
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_AGENT_TO_GROUP", params);
        AMIdentity amid = new AMIdentity(adminSSOToken, agentName, IdType.AGENTONLY, realm, null);
        AgentConfiguration.AddAgentToGroup(amidGroup, amid);
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ADD_AGENT_TO_GROUP", params);
      }

      if (agentNames.size() > 1) {
        outputWriter.printlnMessage(getResourceString("add-agent-to-group-succeeded-pural"));
      } else {
        outputWriter.printlnMessage(getResourceString("add-agent-to-group-succeeded"));
      }
    } catch (IdRepoException e) {
      String[] args = {realm, agentGroupName, agentName, e.getMessage()};
      debugError("AddAgentsToGroup.handleRequest", e);
      writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_AGENT_TO_GROUP", args);
      throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (ConfigurationException e) {
      String[] args = {realm, agentGroupName, agentName, e.getMessage()};
      debugError("AddAgentsToGroup.handleRequest", e);
      writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_AGENT_TO_GROUP", args);
      throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
      String[] args = {realm, agentGroupName, agentName, e.getMessage()};
      debugError("AddAgentsToGroup.handleRequest", e);
      writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_AGENT_TO_GROUP", args);
      throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
  }
Example #2
0
  /**
   * Services a Commandline Request.
   *
   * @param rc Request Context.
   * @throw CLIException if the request cannot serviced.
   */
  public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    SSOToken adminSSOToken = getAdminSSOToken();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String pattern = getStringOptionValue(IArgument.FILTER);
    boolean recursive = isOptionSet(IArgument.RECURSIVE);
    String strRecursive = (recursive) ? "recursive" : "non recursive";

    if ((pattern == null) || (pattern.trim().length() == 0)) {
      pattern = "*";
    }

    String[] params = {realm, pattern, strRecursive};
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SEARCH_REALM", params);

    try {
      OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
      Set results = ocm.getSubOrganizationNames(pattern, recursive);

      IOutput outputWriter = getOutputWriter();
      if ((results != null) && !results.isEmpty()) {
        String template = getResourceString("search-realm-results");
        String[] arg = new String[1];

        for (Iterator i = results.iterator(); i.hasNext(); ) {
          arg[0] = (String) i.next();
          outputWriter.printlnMessage(MessageFormat.format(template, (Object[]) arg));
        }

        outputWriter.printlnMessage(getResourceString("search-realm-succeed"));
      } else {
        outputWriter.printlnMessage(getResourceString("search-realm-no-results"));
      }

      writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SEARCH_REALM", params);
    } catch (SMSException e) {
      String[] args = {realm, strRecursive, e.getMessage()};
      debugError("SearchRealms.handleRequest", e);
      writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SEARCH_REALM", args);
      throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
  }
Example #3
0
  /**
   * Services a Commandline Request.
   *
   * @param rc Request Context.
   * @throws CLIException if the request cannot serviced.
   */
  public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    SSOToken adminSSOToken = getAdminSSOToken();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    boolean recursive = isOptionSet(IArgument.RECURSIVE);
    String strRecursive = (recursive) ? "recursive" : "non recursive";

    String[] params = {realm, strRecursive};
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_REALM", params);

    try {
      OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
      ocm.deleteSubOrganization(null, recursive);
      getOutputWriter().printlnMessage(getResourceString("delete-realm-succeed"));
      writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_DELETE_REALM", params);
    } catch (SMSException e) {
      String[] args = {realm, strRecursive, e.getMessage()};
      debugError("DeleteRealm.handleRequest", e);
      writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_DELETE_REALM", args);
      throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
  }
Example #4
0
  /**
   * Services a Commandline Request.
   *
   * @param rc Request Context.
   * @throws CLIException if the request cannot serviced.
   */
  public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();

    SSOToken adminSSOToken = getAdminSSOToken();
    IOutput outputWriter = getOutputWriter();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String agentGroupName = getStringOptionValue(IArgument.AGENT_GROUP_NAME);
    String outfile = getStringOptionValue(IArgument.OUTPUT_FILE);
    String[] params = {realm, agentGroupName};

    try {
      writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SHOW_AGENT_GROUP", params);
      AMIdentity amid =
          new AMIdentity(adminSSOToken, agentGroupName, IdType.AGENTGROUP, realm, null);
      if (!amid.isExists()) {
        String[] args = {realm, agentGroupName, "agent group did not exist"};
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT_GROUP", args);
        Object[] p = {agentGroupName};
        String msg = MessageFormat.format(getResourceString("show-agent-group-does-not-exist"), p);
        throw new CLIException(msg, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
      }
      Map values = AgentConfiguration.getAgentGroupAttributes(adminSSOToken, realm, agentGroupName);

      Set passwords =
          AgentConfiguration.getAttributesSchemaNames(amid, AttributeSchema.Syntax.PASSWORD);

      if ((values != null) && !values.isEmpty()) {
        StringBuilder buff = new StringBuilder();
        // Used to generated a sorted list of property names for easier viewing
        List<String> sortedKeys = new ArrayList<String>(values.keySet());
        Collections.sort(sortedKeys);
        for (String attrName : sortedKeys) {

          if (passwords.contains(attrName)) {
            buff.append(attrName).append("=********\n");
          } else {
            Set vals = (Set) values.get(attrName);

            if (vals.isEmpty()) {
              buff.append(attrName).append("=").append("\n");
            } else {
              for (Iterator j = vals.iterator(); j.hasNext(); ) {
                String val = (String) j.next();
                buff.append(attrName).append("=").append(val).append("\n");
              }
            }
          }
        }
        if (outfile == null) {
          outputWriter.printlnMessage(buff.toString());
        } else {
          writeToFile(outfile, buff.toString());
          outputWriter.printlnMessage(getResourceString("show-agent-group-to-file"));
        }
      } else {
        outputWriter.printlnMessage(getResourceString("show-agent-group-no-attributes"));
      }
      writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SHOW_AGENT_GROUP", params);
    } catch (SMSException e) {
      String[] args = {realm, agentGroupName, e.getMessage()};
      debugError("ShowAgentGroup.handleRequest", e);
      writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT_GROUP", args);
      throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IdRepoException e) {
      String[] args = {realm, agentGroupName, e.getMessage()};
      debugError("ShowAgentGroup.handleRequest", e);
      writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT_GROUP", args);
      throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
      String[] args = {realm, agentGroupName, e.getMessage()};
      debugError("ShowAgentGroup.handleRequest", e);
      writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SHOW_AGENT_GROUP", args);
      throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
  }