Search in sources :

Example 86 with IOutput

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

the class RemoveAttributeSchemaDefaultValues 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 attributeSchemaName = getStringOptionValue(IArgument.ATTRIBUTE_SCHEMA);
    List defaultValues = (List) rc.getOption(IArgument.DEFAULT_VALUES);
    ServiceSchema ss = getServiceSchema();
    IOutput outputWriter = getOutputWriter();
    String defaultValue = null;
    try {
        for (Iterator i = defaultValues.iterator(); i.hasNext(); ) {
            defaultValue = (String) i.next();
            String[] params = { serviceName, schemaType, subSchemaName, attributeSchemaName, defaultValue };
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REMOVE_ATTRIBUTE_SCHEMA_DEFAULT_VALUE", params);
            AttributeSchema attrSchema = ss.getAttributeSchema(attributeSchemaName);
            if (attrSchema == null) {
                String[] args = { serviceName, schemaType, subSchemaName, attributeSchemaName, defaultValue, "attribute schema does not exist" };
                attributeSchemaNoExist(attributeSchemaName, "FAILED_REMOVE_ATTRIBUTE_SCHEMA_DEFAULT_VALUE", args);
            }
            attrSchema.removeDefaultValue(defaultValue);
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REMOVE_ATTRIBUTE_SCHEMA_DEFAULT_VALUE", params);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("attribute-schema-remove-default-values-succeed"), (Object[]) params));
        }
    } catch (SSOException e) {
        String[] args = { serviceName, schemaType, subSchemaName, attributeSchemaName, defaultValue, e.getMessage() };
        debugError("RemoveAttributeSchemaDefaultValues.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_ATTRIBUTE_SCHEMA_DEFAULT_VALUE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serviceName, schemaType, subSchemaName, attributeSchemaName, defaultValue, e.getMessage() };
        debugError("RemoveAttributeSchemaDefaultValues.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_ATTRIBUTE_SCHEMA_DEFAULT_VALUE", 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) AttributeSchema(com.sun.identity.sm.AttributeSchema) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) SSOException(com.iplanet.sso.SSOException)

Example 87 with IOutput

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

the class RemoveSubSchema 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 serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    String schemaType = getStringOptionValue(IArgument.SCHEMA_TYPE);
    String subSchemaName = getStringOptionValue(IArgument.SUBSCHEMA_NAME);
    List schemaNames = rc.getOption(ARGUMENT_SCHEMA_NAMES);
    IOutput outputWriter = getOutputWriter();
    if (subSchemaName == null) {
        subSchemaName = "/";
    }
    String[] params = new String[4];
    params[0] = serviceName;
    params[1] = schemaType;
    params[2] = subSchemaName;
    ServiceSchema ss = getServiceSchema();
    String schemaName = "";
    try {
        for (Iterator iter = schemaNames.iterator(); iter.hasNext(); ) {
            schemaName = (String) iter.next();
            params[3] = schemaName;
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REMOVE_SUB_SCHEMA", params);
            ss.removeSubSchema(schemaName);
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REMOVE_SUB_SCHEMA", params);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("remove-subschema-succeed"), (Object[]) params));
        }
    } catch (SSOException e) {
        String[] args = { serviceName, schemaType, subSchemaName, schemaName, e.getMessage() };
        debugError("RemoveSubSchema.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_SUB_SCHEMA", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serviceName, schemaType, subSchemaName, schemaName, e.getMessage() };
        debugError("RemoveSubSchema.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_SUB_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)

Example 88 with IOutput

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

the class SetAttributeDefaults 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 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);
    ServiceSchema ss = getServiceSchema();
    IOutput outputWriter = getOutputWriter();
    try {
        String[] params = { serviceName, schemaType, subSchemaName };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_SET_SCHEMA_ATTR_DEFAULTS", params);
        ss.setAttributeDefaults(attributeValues);
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_SET_SCHEMA_ATTR_DEFAULTS", params);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("schema-set-attribute-defaults-succeed"), (Object[]) params));
    } catch (SSOException e) {
        String[] args = { serviceName, schemaType, subSchemaName, e.getMessage() };
        debugError("SetAttributeDefaults.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SCHEMA_ATTR_DEFAULTS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serviceName, schemaType, subSchemaName, e.getMessage() };
        debugError("SetAttributeDefaults.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_SET_SCHEMA_ATTR_DEFAULTS", 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) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) SSOException(com.iplanet.sso.SSOException) Map(java.util.Map)

Example 89 with IOutput

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

the class AddAttributeSchema 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();
    List listContinues = (List) rc.getOption(IArgument.CONTINUE);
    boolean continueFlag = (listContinues != null);
    IOutput outputWriter = getOutputWriter();
    List fileNames = (List) rc.getOption(ARGUMENT_SCHEMA_FILES);
    String serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    String schemaType = getStringOptionValue(IArgument.SCHEMA_TYPE);
    ServiceSchema ss = getServiceSchema();
    CommandManager mgr = getCommandManager();
    String url = mgr.getWebEnabledURL();
    if ((url != null) && (url.length() > 0)) {
        String[] param = { CLIConstants.WEB_INPUT };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_ATTRIBUTE_SCHEMA", param);
        addAttributeSchemaXML(ss, serviceName, schemaType, (String) fileNames.iterator().next());
        outputWriter.printlnMessage(getResourceString("attribute-schema-added"));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ADD_ATTRIBUTE_SCHEMA", param);
    } else {
        for (Iterator i = fileNames.iterator(); i.hasNext(); ) {
            String name = (String) i.next();
            String[] param = { serviceName, schemaType, name };
            try {
                writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_ATTRIBUTE_SCHEMA", param);
                addAttributeSchema(ss, serviceName, schemaType, name);
                outputWriter.printlnMessage(getResourceString("attribute-schema-added"));
                writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ADD_ATTRIBUTE_SCHEMA", param);
            } catch (CLIException e) {
                if (continueFlag) {
                    outputWriter.printlnError(getResourceString("add-attribute-schema-failed") + e.getMessage());
                    if (isVerbose()) {
                        outputWriter.printlnError(Debugger.getStackTrace(e));
                    }
                } else {
                    throw e;
                }
            }
        }
    }
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) CommandManager(com.sun.identity.cli.CommandManager) IOutput(com.sun.identity.cli.IOutput) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) List(java.util.List)

Example 90 with IOutput

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

the class AddSubConfiguration method addSubConfigToRoot.

private void addSubConfigToRoot(String serviceName, String subConfigName, String subConfigId, Map attrValues, int priority) throws CLIException {
    SSOToken adminSSOToken = getAdminSSOToken();
    IOutput outputWriter = getOutputWriter();
    String[] params = { subConfigName, serviceName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_SUB_CONFIGURATION", params);
    try {
        ServiceConfigManager scm = new ServiceConfigManager(serviceName, adminSSOToken);
        ServiceConfig sc = scm.getGlobalConfig(null);
        if (sc == null) {
            String[] args = { subConfigName, serviceName, "no global configiration" };
            writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_SUB_CONFIGURATION", args);
            String[] ar = { serviceName };
            String message = MessageFormat.format(getResourceString("add-sub-configuration-no-global-config"), (Object[]) ar);
            throw new CLIException(message, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        addSubConfig(sc, subConfigName, subConfigId, attrValues, priority);
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ADD_SUB_CONFIGURATION", params);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("add-sub-configuration-succeed"), (Object[]) params));
    } catch (SSOException e) {
        String[] args = { subConfigName, serviceName, e.getMessage() };
        debugError("AddSubConfiguration.addSubConfigToRoot", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_SUB_CONFIGURATION", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        e.printStackTrace();
        String[] args = { subConfigName, serviceName, e.getMessage() };
        debugError("AddSubConfiguration.addSubConfigToRoot", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_SUB_CONFIGURATION", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Aggregations

IOutput (com.sun.identity.cli.IOutput)152 CLIException (com.sun.identity.cli.CLIException)137 SSOException (com.iplanet.sso.SSOException)123 SSOToken (com.iplanet.sso.SSOToken)99 SMSException (com.sun.identity.sm.SMSException)98 Set (java.util.Set)61 Iterator (java.util.Iterator)53 IdRepoException (com.sun.identity.idm.IdRepoException)45 List (java.util.List)45 AMIdentity (com.sun.identity.idm.AMIdentity)42 Map (java.util.Map)35 AMIdentityRepository (com.sun.identity.idm.AMIdentityRepository)26 ServiceSchema (com.sun.identity.sm.ServiceSchema)26 IdType (com.sun.identity.idm.IdType)19 IOException (java.io.IOException)18 ConfigurationException (com.sun.identity.common.configuration.ConfigurationException)17 OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)15 HashMap (java.util.HashMap)15 HashSet (java.util.HashSet)15 AttributeSchema (com.sun.identity.sm.AttributeSchema)14