Search in sources :

Example 46 with CLIException

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

the class LoadSchema method loadSchema.

private void loadSchema(ServiceManager ssm, String fileName) throws CLIException {
    FileInputStream fis = null;
    try {
        fis = new FileInputStream(fileName);
        ssm.registerServices(fis);
    } catch (IOException e) {
        String[] args = { fileName, e.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_LOAD_SCHEMA", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        String[] args = { fileName, e.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_LOAD_SCHEMA", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { fileName, e.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_LOAD_SCHEMA", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (IOException ie) {
            //ignore if file input stream cannot be closed.
            }
        }
    }
}
Also used : SMSException(com.sun.identity.sm.SMSException) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 47 with CLIException

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

the class LoadSchema 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();
    boolean continueFlag = isOptionSet(IArgument.CONTINUE);
    IOutput outputWriter = getOutputWriter();
    List xmlFiles = (List) rc.getOption(IArgument.XML_FILE);
    ServiceManager ssm = null;
    try {
        ssm = new ServiceManager(adminSSOToken);
    } catch (SMSException e) {
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
    CommandManager mgr = getCommandManager();
    boolean bError = false;
    String url = mgr.getWebEnabledURL();
    if ((url != null) && (url.length() > 0)) {
        String[] param = { CLIConstants.WEB_INPUT };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_LOAD_SCHEMA", param);
        loadSchemaXML(ssm, (String) xmlFiles.iterator().next());
        outputWriter.printlnMessage(getResourceString("schema-added"));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCESS_LOAD_SCHEMA", param);
    } else {
        for (Iterator i = xmlFiles.iterator(); i.hasNext(); ) {
            String file = (String) i.next();
            String[] param = { file };
            try {
                writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_LOAD_SCHEMA", param);
                loadSchema(ssm, file);
                outputWriter.printlnMessage(getResourceString("schema-added"));
                writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCESS_LOAD_SCHEMA", param);
            } catch (CLIException e) {
                bError = true;
                if (continueFlag) {
                    outputWriter.printlnError(getResourceString("schema-failed") + e.getMessage());
                    if (isVerbose()) {
                        outputWriter.printlnError(Debugger.getStackTrace(e));
                    }
                } else {
                    throw e;
                }
            }
        }
    }
    // if continue flag is on; throw cannot process exception
    if (bError) {
        throw new CLIException(getResourceString("one-or-more-services-not-added"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) CommandManager(com.sun.identity.cli.CommandManager) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) ServiceManager(com.sun.identity.sm.ServiceManager) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) SSOException(com.iplanet.sso.SSOException)

Example 48 with CLIException

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

the class ModifyAttributeSchemaI18nKey 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);
    String i18nkey = getStringOptionValue(ARGUMENT_I18N_KEY);
    ServiceSchema ss = getServiceSchema();
    IOutput outputWriter = getOutputWriter();
    try {
        String[] params = { serviceName, schemaType, subSchemaName, attributeSchemaName, i18nkey };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_MODIFY_ATTRIBUTE_SCHEMA_I18N_KEY", params);
        AttributeSchema attrSchema = ss.getAttributeSchema(attributeSchemaName);
        if (attrSchema == null) {
            String[] args = { serviceName, schemaType, subSchemaName, attributeSchemaName, i18nkey, "attribute schema does not exist" };
            attributeSchemaNoExist(attributeSchemaName, "FAILED_MODIFY_ATTRIBUTE_SCHEMA_I18N_KEY", args);
        }
        attrSchema.setI18NKey(i18nkey);
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_MODIFY_ATTRIBUTE_SCHEMA_I18N_KEY", params);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("attribute-schema-modify-i18n-key-succeed"), (Object[]) params));
    } catch (SSOException e) {
        String[] args = { serviceName, schemaType, subSchemaName, attributeSchemaName, i18nkey, e.getMessage() };
        debugError("ModifyAttributeSchemaI18nKey.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_ATTRIBUTE_SCHEMA_I18N_KEY", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serviceName, schemaType, subSchemaName, attributeSchemaName, i18nkey, e.getMessage() };
        debugError("ModifyAttributeSchemaI18nKey.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_ATTRIBUTE_SCHEMA_I18N_KEY", 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) SSOException(com.iplanet.sso.SSOException)

Example 49 with CLIException

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

the class ModifyAttributeSchemaPropertiesViewBeanURL 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);
    String url = getStringOptionValue(ARGUMENT_URL);
    ServiceSchema ss = getServiceSchema();
    IOutput outputWriter = getOutputWriter();
    try {
        String[] params = { serviceName, schemaType, subSchemaName, attributeSchemaName, url };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_MODIFY_ATTRIBUTE_SCHEMA_PROPERTIES_VIEW_BEAN_URL", params);
        AttributeSchema attrSchema = ss.getAttributeSchema(attributeSchemaName);
        if (attrSchema == null) {
            String[] args = { serviceName, schemaType, subSchemaName, attributeSchemaName, url, "attribute schema does not exist" };
            attributeSchemaNoExist(attributeSchemaName, "FAILED_MODIFY_ATTRIBUTE_SCHEMA_PROPERTIES_VIEW_BEAN_URL", args);
        }
        attrSchema.setPropertiesViewBeanUR(url);
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_MODIFY_ATTRIBUTE_SCHEMA_PROPERTIES_VIEW_BEAN_URL", params);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("attribute-schema-modify-properties-view-bean-url-key-succeed"), (Object[]) params));
    } catch (SSOException e) {
        String[] args = { serviceName, schemaType, subSchemaName, attributeSchemaName, url, e.getMessage() };
        debugError("ModifyAttributeSchemaPropertiesViewBeanURL.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_ATTRIBUTE_SCHEMA_PROPERTIES_VIEW_BEAN_URL", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serviceName, schemaType, subSchemaName, attributeSchemaName, url, e.getMessage() };
        debugError("ModifyAttributeSchemaPropertiesViewBeanURL.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_ATTRIBUTE_SCHEMA_PROPERTIES_VIEW_BEAN_URL", 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) SSOException(com.iplanet.sso.SSOException)

Example 50 with CLIException

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

the class ModifyAttributeSchemaSyntax 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);
    String syntax = getStringOptionValue(ARGUMENT_SYNTAX);
    ServiceSchema ss = getServiceSchema();
    IOutput outputWriter = getOutputWriter();
    try {
        String[] params = { serviceName, schemaType, subSchemaName, attributeSchemaName, syntax };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_MODIFY_ATTRIBUTE_SCHEMA_SYNTAX", params);
        AttributeSchema attrSchema = ss.getAttributeSchema(attributeSchemaName);
        if (attrSchema == null) {
            String[] args = { serviceName, schemaType, subSchemaName, attributeSchemaName, syntax, "attribute schema does not exist" };
            attributeSchemaNoExist(attributeSchemaName, "FAILED_MODIFY_ATTRIBUTE_SCHEMA_SYNTAX", args);
        }
        attrSchema.setSyntax(syntax);
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_MODIFY_ATTRIBUTE_SCHEMA_SYNTAX", params);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("attribute-schema-modify-syntax-succeed"), (Object[]) params));
    } catch (SSOException e) {
        String[] args = { serviceName, schemaType, subSchemaName, attributeSchemaName, syntax, e.getMessage() };
        debugError("ModifyAttributeSchemaSyntax.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_ATTRIBUTE_SCHEMA_SYNTAX", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serviceName, schemaType, subSchemaName, attributeSchemaName, syntax, e.getMessage() };
        debugError("ModifyAttributeSchemaSyntax.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_MODIFY_ATTRIBUTE_SCHEMA_SYNTAX", 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) 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