コード例 #1
0
 public Map getAttributeValues(String universalId) throws AMConsoleException {
   try {
     AMIdentity amid = IdUtils.getIdentity(adminSSOToken, universalId);
     Map values = AgentConfiguration.getAgentAttributes(amid, true);
     return values;
   } catch (IdRepoException re) {
     throw new AMConsoleException(re.getMessage());
   } catch (SMSException se) {
     throw new AMConsoleException(se.getMessage());
   } catch (SSOException ssoe) {
     throw new AMConsoleException(ssoe.getMessage());
   }
 }
コード例 #2
0
ファイル: AddAgentsToGroup.java プロジェクト: aldaris/opensso
  /**
   * 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);
    }
  }
コード例 #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();
    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);
    }
  }