Beispiel #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);

    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);
    }
  }
  /**
   * 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);
    }
  }