Search in sources :

Example 61 with CLIException

use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.

the class UpdateService method deleteServices.

private void deleteServices(RequestContext rc, ServiceManager ssm, List serviceNames, SSOToken adminSSOToken, boolean continueFlag, IOutput outputWriter) throws CLIException {
    for (Iterator i = serviceNames.iterator(); i.hasNext(); ) {
        String name = (String) i.next();
        try {
            String[] param = { name };
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_DELETE_SERVICE", param);
            deleteService(rc, ssm, name, adminSSOToken);
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCESS_DELETE_SERVICE", param);
        } catch (CLIException e) {
            if (continueFlag) {
                if (isVerbose()) {
                    outputWriter.printlnError(Debugger.getStackTrace(e));
                }
            } else {
                throw e;
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException)

Example 62 with CLIException

use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.

the class AddSiteFailoverURLs method handleRequest.

/**
     * 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 siteName = getStringOptionValue(IArgument.SITE_NAME);
    List secondaryURLs = (List) rc.getOption(IArgument.SECONDARY_URLS);
    String[] params = { siteName };
    try {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_SITE_FAILOVER_URLS", params);
        if (SiteConfiguration.isSiteExist(adminSSOToken, siteName)) {
            SiteConfiguration.addSiteSecondaryURLs(adminSSOToken, siteName, secondaryURLs);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("add-site-secondary-urls-succeeded"), (Object[]) params));
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("add-site-secondary-urls-no-exists"), (Object[]) params));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ADD_SITE_FAILOVER_URLS", params);
    } catch (SSOException e) {
        String[] args = { siteName, e.getMessage() };
        debugError("AddSiteFailoverURLs.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_SITE_FAILOVER_URLS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (ConfigurationException e) {
        String[] args = { siteName, e.getMessage() };
        debugError("AddSiteFailoverURLs.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_SITE_FAILOVER_URLS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { siteName, e.getMessage() };
        debugError("AddSiteFailoverURLs.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_SITE_FAILOVER_URLS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) SSOException(com.iplanet.sso.SSOException)

Example 63 with CLIException

use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.

the class AddSiteMembers method handleRequest.

/**
     * Adds members to a site.
     *
     * @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 siteName = getStringOptionValue(IArgument.SITE_NAME);
    List serverNames = (List) rc.getOption(IArgument.SERVER_NAMES);
    IOutput outputWriter = getOutputWriter();
    try {
        String[] params = { siteName };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_SITE_MEMBERS", params);
        if (SiteConfiguration.isSiteExist(adminSSOToken, siteName)) {
            SiteConfiguration.addServersToSite(adminSSOToken, siteName, serverNames);
            outputWriter.printlnMessage(getResourceString("add-site-members-succeeded"));
        } else {
            outputWriter.printlnMessage(getResourceString("add-site-members-site-not-exist"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ADD_SITE_MEMBERS", params);
    } catch (ConfigurationException e) {
        String[] args = { siteName, e.getMessage() };
        debugError("AddSiteMembers.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_SITE_MEMBERS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { siteName, e.getMessage() };
        debugError("AddSiteMembers.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_SITE_MEMBERS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { siteName, e.getMessage() };
        debugError("AddSiteMembers.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_SITE_MEMBERS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) SSOException(com.iplanet.sso.SSOException)

Example 64 with CLIException

use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.

the class SetAttributeSchemaChoiceValues method handleRequest.

/**
     * 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 schemaType = getStringOptionValue(IArgument.SCHEMA_TYPE);
    String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    String subSchemaName = getStringOptionValue(IArgument.SUBSCHEMA_NAME);
    String attributeName = getStringOptionValue(IArgument.ATTRIBUTE_NAME);
    String datafile = getStringOptionValue(IArgument.DATA_FILE);
    List choiceValues = rc.getOption(IArgument.CHOICE_VALUES);
    boolean toAdd = isOptionSet(ARGUMENT_ADD);
    if ((datafile == null) && (choiceValues == null)) {
        throw new CLIException(getResourceString("missing-choicevalues"), ExitCodes.INCORRECT_OPTION, rc.getSubCommand().getName());
    }
    Map attributeValues = AttributeValues.parse(getCommandManager(), datafile, choiceValues);
    ServiceSchema ss = getServiceSchema();
    IOutput outputWriter = getOutputWriter();
    String[] params = { serviceName, schemaType, subSchemaName, attributeName };
    if (toAdd) {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_ATTRIBUTE_SCHEMA_CHOICE_VALUES", params);
    } else {
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SET_ATTRIBUTE_SCHEMA_CHOICE_VALUES", params);
    }
    try {
        AttributeSchema attrSchema = ss.getAttributeSchema(attributeName);
        if (attrSchema == null) {
            String[] args = { serviceName, schemaType, subSchemaName, attributeName, "attribute schema does not exist" };
            attributeSchemaNoExist(attributeName, (toAdd) ? "FAILED_ADD_ATTRIBUTE_SCHEMA_CHOICE_VALUES" : "FAILED_SET_ATTRIBUTE_SCHEMA_CHOICE_VALUES", args);
        }
        if (toAdd) {
            addChoiceValues(attrSchema, attributeValues);
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ADD_ATTRIBUTE_SCHEMA_CHOICE_VALUES", params);
        } else {
            setChoiceValues(attrSchema, attributeValues);
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SET_ATTRIBUTE_SCHEMA_CHOICE_VALUES", params);
        }
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("attribute-schema-set-choice-value-succeed"), (Object[]) params));
    } catch (SSOException e) {
        String[] args = { serviceName, schemaType, subSchemaName, attributeName, e.getMessage() };
        debugError("SetAttributeSchemaChoiceValues.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, (toAdd) ? "FAILED_ADD_ATTRIBUTE_SCHEMA_CHOICE_VALUES" : "FAILED_SET_ATTRIBUTE_SCHEMA_CHOICE_VALUES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serviceName, schemaType, subSchemaName, attributeName, e.getMessage() };
        debugError("SetAttributeSchemaChoiceValues.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, (toAdd) ? "FAILED_ADD_ATTRIBUTE_SCHEMA_CHOICE_VALUES" : "FAILED_SET_ATTRIBUTE_SCHEMA_CHOICE_VALUES", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) AttributeSchema(com.sun.identity.sm.AttributeSchema) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) SSOException(com.iplanet.sso.SSOException) Map(java.util.Map)

Example 65 with CLIException

use of com.sun.identity.cli.CLIException in project OpenAM by OpenRock.

the class RemoveAttributeSchemas method handleRequest.

/**
     * 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 schemaType = getStringOptionValue(IArgument.SCHEMA_TYPE);
    String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    String subSchemaName = getStringOptionValue(IArgument.SUBSCHEMA_NAME);
    List attributeSchemaNames = (List) rc.getOption(IArgument.ATTRIBUTE_SCHEMA);
    ServiceSchema ss = getServiceSchema();
    IOutput outputWriter = getOutputWriter();
    String attributeSchemaName = null;
    try {
        for (Iterator i = attributeSchemaNames.iterator(); i.hasNext(); ) {
            attributeSchemaName = (String) i.next();
            String[] params = { serviceName, schemaType, subSchemaName, attributeSchemaName };
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REMOVE_ATTRIBUTE_SCHEMA", params);
            ss.removeAttributeSchema(attributeSchemaName);
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REMOVE_ATTRIBUTE_SCHEMA", params);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("remove-attribute-schema-succeed"), (Object[]) params));
        }
    } catch (SSOException e) {
        String[] args = { serviceName, schemaType, subSchemaName, attributeSchemaName, e.getMessage() };
        debugError("RemoveAttributeSchemas.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_ATTRIBUTE_SCHEMA", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serviceName, schemaType, subSchemaName, attributeSchemaName, e.getMessage() };
        debugError("RemoveAttributeSchemas.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_ATTRIBUTE_SCHEMA", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) SSOException(com.iplanet.sso.SSOException)

Aggregations

CLIException (com.sun.identity.cli.CLIException)282 SSOException (com.iplanet.sso.SSOException)171 SMSException (com.sun.identity.sm.SMSException)150 IOutput (com.sun.identity.cli.IOutput)136 SSOToken (com.iplanet.sso.SSOToken)116 Set (java.util.Set)88 Iterator (java.util.Iterator)62 List (java.util.List)61 IOException (java.io.IOException)53 IdRepoException (com.sun.identity.idm.IdRepoException)48 ServiceSchema (com.sun.identity.sm.ServiceSchema)46 AMIdentity (com.sun.identity.idm.AMIdentity)43 Map (java.util.Map)42 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)33 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)29 AttributeSchema (com.sun.identity.sm.AttributeSchema)28 CLIRequest (com.sun.identity.cli.CLIRequest)27 AfterTest (org.testng.annotations.AfterTest)27 BeforeTest (org.testng.annotations.BeforeTest)27 Test (org.testng.annotations.Test)27