Search in sources :

Example 56 with CLIException

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

the class RemoveAttributeDefaults 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);
    Set attributeNames = new HashSet();
    attributeNames.addAll(rc.getOption(IArgument.ATTRIBUTE_NAMES));
    ServiceSchema ss = getServiceSchema();
    IOutput outputWriter = getOutputWriter();
    try {
        String[] params = { serviceName, schemaType, subSchemaName, attributeNames.toString() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REMOVE_SCHEMA_ATTR_DEFAULTS", params);
        ss.removeAttributeDefaults(attributeNames);
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REMOVE_SCHEMA_ATTR_DEFAULTS", params);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("schema-remove-attribute-defaults-succeed"), (Object[]) params));
    } catch (SSOException e) {
        String[] args = { serviceName, schemaType, subSchemaName, attributeNames.toString(), e.getMessage() };
        debugError("RemoveAttributeDefaults.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_SCHEMA_ATTR_DEFAULTS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serviceName, schemaType, subSchemaName, attributeNames.toString(), e.getMessage() };
        debugError("RemoveAttributeDefaults.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_SCHEMA_ATTR_DEFAULTS", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) Set(java.util.Set) HashSet(java.util.HashSet) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) HashSet(java.util.HashSet)

Example 57 with CLIException

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

the class RemoveAttributeSchemaChoiceValues 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);
    List choiceValues = (List) rc.getOption(IArgument.CHOICE_VALUES);
    ServiceSchema ss = getServiceSchema();
    IOutput outputWriter = getOutputWriter();
    String[] params = { serviceName, schemaType, subSchemaName, attributeName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_REMOVE_ATTRIBUTE_SCHEMA_CHOICE_VALUE", params);
    try {
        AttributeSchema attrSchema = ss.getAttributeSchema(attributeName);
        if (attrSchema == null) {
            String[] args = { serviceName, schemaType, subSchemaName, attributeName, "attribute schema does not exist" };
            attributeSchemaNoExist(attributeName, "FAILED_REMOVE_ATTRIBUTE_SCHEMA_CHOICE_VALUE", args);
        }
        for (Iterator i = choiceValues.iterator(); i.hasNext(); ) {
            String choiceValue = (String) i.next();
            attrSchema.removeChoiceValue(choiceValue);
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_REMOVE_ATTRIBUTE_SCHEMA_CHOICE_VALUE", params);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("attribute-schema-remove-choice-value-succeed"), (Object[]) params));
    } catch (SSOException e) {
        String[] args = { serviceName, schemaType, subSchemaName, attributeName, e.getMessage() };
        debugError("RemoveAttributeSchemaChoiceValues.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_ATTRIBUTE_SCHEMA_CHOICE_VALUE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serviceName, schemaType, subSchemaName, attributeName, e.getMessage() };
        debugError("RemoveAttributeSchemaChoiceValues.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_REMOVE_ATTRIBUTE_SCHEMA_CHOICE_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) AttributeSchema(com.sun.identity.sm.AttributeSchema) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) List(java.util.List) SSOException(com.iplanet.sso.SSOException)

Example 58 with CLIException

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

the class UpdateService method deleteService.

private void deleteService(RequestContext rc, ServiceManager ssm, String serviceName, SSOToken adminSSOToken) throws CLIException {
    try {
        ServiceConfigManager scm = new ServiceConfigManager(serviceName, adminSSOToken);
        if (scm.getGlobalConfig(null) != null) {
            scm.removeGlobalConfiguration(null);
        }
        ssm.deleteService(serviceName);
    } catch (SSOException e) {
        String[] args = { serviceName, e.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_DELETE_SERVICE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serviceName, e.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_DELETE_SERVICE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SMSException(com.sun.identity.sm.SMSException) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 59 with CLIException

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

the class UpdateService method handleRequest.

/**
     * Updates service schema. Delete the service schema if it exists and
     * load the schema.
     *
     * @param rc Request Context.
     * @throws CLIException if request cannot be processed.
     */
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();
    String url = mgr.getWebEnabledURL();
    if ((url != null) && (url.length() > 0)) {
        String strXML = (String) xmlFiles.iterator().next();
        try {
            List serviceNames = getServiceNames(SMSSchema.getXMLDocument(strXML, true));
            deleteServices(rc, ssm, serviceNames, adminSSOToken, continueFlag, outputWriter);
            loadSchemaXML(ssm, strXML);
            outputWriter.printlnMessage(getResourceString("service-updated"));
        } catch (SMSException e) {
            throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
    } else {
        for (Iterator i = xmlFiles.iterator(); i.hasNext(); ) {
            String file = (String) i.next();
            FileInputStream fis = null;
            try {
                fis = new FileInputStream(file);
                List serviceNames = getServiceNames(SMSSchema.getXMLDocument(fis));
                deleteServices(rc, ssm, serviceNames, adminSSOToken, continueFlag, outputWriter);
                loadSchema(ssm, file);
                outputWriter.printlnMessage(getResourceString("service-updated"));
            } catch (CLIException e) {
                if (continueFlag) {
                    outputWriter.printlnError(getResourceString("service-updated-failed") + e.getMessage());
                    if (isVerbose()) {
                        outputWriter.printlnError(Debugger.getStackTrace(e));
                    }
                } else {
                    throw e;
                }
            } catch (SMSException e) {
                if (continueFlag) {
                    outputWriter.printlnError(getResourceString("service-updated-failed") + e.getMessage());
                    if (isVerbose()) {
                        outputWriter.printlnError(Debugger.getStackTrace(e));
                    }
                } else {
                    throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
                }
            } catch (FileNotFoundException e) {
                if (continueFlag) {
                    outputWriter.printlnError(getResourceString("service-updated-failed") + e.getMessage());
                    if (isVerbose()) {
                        outputWriter.printlnError(Debugger.getStackTrace(e));
                    }
                } else {
                    throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
                }
            } finally {
                if (fis != null) {
                    try {
                        fis.close();
                    } catch (IOException ie) {
                    //igore if file input stream cannot be closed.
                    }
                }
            }
        }
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) FileNotFoundException(java.io.FileNotFoundException) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) CommandManager(com.sun.identity.cli.CommandManager) IOutput(com.sun.identity.cli.IOutput) ServiceManager(com.sun.identity.sm.ServiceManager) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List)

Example 60 with CLIException

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

the class UpdateService method loadSchema.

private void loadSchema(ServiceManager ssm, String fileName) throws CLIException {
    String[] param = { fileName };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_LOAD_SCHEMA", param);
    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) {
            //igore 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)

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