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

    String realm = getStringOptionValue(IArgument.REALM_NAME);
    List<String> appNames = (List) rc.getOption(PARAM_APPL_NAMES);
    String[] param = {realm};
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_APPLICATIONS", param);

    Subject adminSubject = getAdminSubject();
    try {
      for (String a : appNames) {
        ApplicationManager.deleteApplication(adminSubject, "/", a);
      }
      IOutput writer = getOutputWriter();
      writer.printlnMessage(
          MessageFormat.format(
              getResourceString("delete-applications-succeeded"), (Object[]) param));
      writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_DELETE_APPLICATIONS", param);
    } catch (EntitlementException e) {
      String[] params = {realm, e.getMessage()};
      writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_DELETE_APPLICATIONS", params);
      throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
  }
Exemplo n.º 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);

    SSOToken adminSSOToken = getAdminSSOToken();
    IOutput outputWriter = getOutputWriter();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String idName = getStringOptionValue(ARGUMENT_ID_NAME);
    String type = getStringOptionValue(ARGUMENT_ID_TYPE);
    String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    IdType idType = convert2IdType(type);
    String datafile = getStringOptionValue(IArgument.DATA_FILE);
    List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);

    if ((datafile == null) && (attrValues == null)) {
      throw new CLIException(
          getResourceString("missing-attributevalues"),
          ExitCodes.INCORRECT_OPTION,
          rc.getSubCommand().getName());
    }

    Map attributeValues = AttributeValues.parse(getCommandManager(), datafile, attrValues);
    String[] params = {realm, type, idName, serviceName};

    try {
      writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_IDREPO_ASSIGN_SERVICE", params);
      AMIdentity amid = new AMIdentity(adminSSOToken, idName, idType, realm, null);
      amid.assignService(serviceName, attributeValues);

      outputWriter.printlnMessage(
          MessageFormat.format(
              getResourceString("idrepo-assign-service-succeed"), (Object[]) params));
      writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_IDREPO_ASSIGN_SERVICE", params);
    } catch (IdRepoException e) {
      String[] args = {realm, type, idName, serviceName, e.getMessage()};
      debugError("AssignService.handleRequest", e);
      writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_ASSIGN_SERVICE", args);
      throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
      String[] args = {realm, type, idName, serviceName, e.getMessage()};
      debugError("AssignService.handleRequest", e);
      writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_ASSIGN_SERVICE", args);
      throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
  }
Exemplo n.º 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();

    String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    String subConfigName = getStringOptionValue(IArgument.SUB_CONFIGURATION_NAME);
    String realmName = getStringOptionValue(IArgument.REALM_NAME);
    String subConfigId = getStringOptionValue(IArgument.SUB_CONFIGURATION_ID);
    String datafile = getStringOptionValue(IArgument.DATA_FILE);
    List attrValues = rc.getOption(IArgument.ATTRIBUTE_VALUES);

    if ((datafile == null) && (attrValues == null)) {
      throw new CLIException(
          getResourceString("missing-attributevalues"),
          ExitCodes.INCORRECT_OPTION,
          rc.getSubCommand().getName());
    }

    int priority = 0;
    String strPriority = getStringOptionValue(OPTION_PRIORITY);
    if ((strPriority != null) && (strPriority.length() > 0)) {
      try {
        priority = Integer.parseInt(strPriority);
      } catch (NumberFormatException ex) {
        throw new CLIException(
            getResourceString("add-sub-configuration-priority-no-integer"),
            ExitCodes.INVALID_OPTION_VALUE);
      }
    }

    Map<String, Set<String>> attributeValues =
        AttributeValues.parse(getCommandManager(), datafile, attrValues);

    attributeValues = processFileAttributes(attributeValues);

    if ((realmName == null) || (realmName.length() == 0)) {
      addSubConfigToRoot(serviceName, subConfigName, subConfigId, attributeValues, priority);
    } else {
      addSubConfigToRealm(
          realmName, serviceName, subConfigName, subConfigId, attributeValues, priority);
    }
  }
Exemplo n.º 4
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);
    }
  }
Exemplo n.º 5
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);

    SSOToken adminSSOToken = getAdminSSOToken();
    IOutput outputWriter = getOutputWriter();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String idName = getStringOptionValue(ARGUMENT_ID_NAME);
    String type = getStringOptionValue(ARGUMENT_ID_TYPE);
    List privileges = (List) rc.getOption(IArgument.PRIVILEGES);
    IdType idType = convert2IdType(type);
    String[] params = {realm, type, idName};

    try {
      writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_IDREPO_ADD_PRIVILEGES", params);

      DelegationManager mgr = new DelegationManager(adminSSOToken, realm);
      Set privilegeObjects = mgr.getPrivileges();

      AMIdentity amid = new AMIdentity(adminSSOToken, idName, idType, realm, null);
      if (!amid.isExists()) {
        Object[] p = {idName, type};
        throw new CLIException(
            MessageFormat.format(getResourceString("idrepo-add-privileges-do-not-exist"), p),
            ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
      }
      String uid = amid.getUniversalId();

      DelegationPrivilege newDp = null;
      for (Iterator i = privileges.iterator(); i.hasNext(); ) {
        String name = (String) i.next();
        DelegationPrivilege dp = getDelegationPrivilege(name, privilegeObjects);
        if (dp != null) {
          Set subjects = dp.getSubjects();
          if (!subjects.contains(uid)) {
            subjects.add(uid);
            newDp = new DelegationPrivilege(name, subjects, realm);
            mgr.addPrivilege(newDp);
          } else {
            String[] args = {idName, name};
            String msg =
                MessageFormat.format(
                    getResourceString("delegation-already-has-privilege"), (Object[]) args);
            throw new CLIException(msg, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
          }
        } else {
          Set subjects = new HashSet(2);
          subjects.add(uid);
          newDp = new DelegationPrivilege(name, subjects, realm);
          mgr.addPrivilege(newDp);
        }
      }

      outputWriter.printlnMessage(
          MessageFormat.format(
              getResourceString("idrepo-add-privileges-succeed"), (Object[]) params));
      writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_IDREPO_ADD_PRIVILEGES", params);
    } catch (IdRepoException e) {
      String[] args = {realm, type, idName, e.getMessage()};
      debugError("AddPrivileges.handleRequest", e);
      writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_ADD_PRIVILEGES", args);
      throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (DelegationException e) {
      String[] args = {realm, type, idName, e.getMessage()};
      debugError("AddPrivileges.handleRequest", e);
      writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_ADD_PRIVILEGES", args);
      throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
      String[] args = {realm, type, idName, e.getMessage()};
      debugError("AddPrivileges.handleRequest", e);
      writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IDREPO_ADD_PRIVILEGES", args);
      throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
  }