Search in sources :

Example 36 with CLIException

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

the class RealmGetAssignableServices 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();
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String[] params = { realm };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_GET_ASSIGNABLE_SERVICES_OF_REALM", params);
    try {
        OrganizationConfigManager ocm = new OrganizationConfigManager(adminSSOToken, realm);
        Set serviceNames = ocm.getAssignableServices();
        Set dynamicServiceNames = getAssignableDynamicServiceNames(adminSSOToken, realm);
        if ((dynamicServiceNames != null) && !dynamicServiceNames.isEmpty()) {
            if ((serviceNames != null) && !serviceNames.isEmpty()) {
                serviceNames.addAll(dynamicServiceNames);
            } else {
                serviceNames = dynamicServiceNames;
            }
        }
        IOutput outputWriter = getOutputWriter();
        if ((serviceNames != null) && !serviceNames.isEmpty()) {
            String msg = getResourceString("realm-getassignable-services-result");
            outputWriter.printlnMessage(FormatUtils.printServiceNames(serviceNames, msg, adminSSOToken));
            outputWriter.printlnMessage(getResourceString("realm-getassignable-services-succeed"));
        } else {
            outputWriter.printlnMessage(getResourceString("realm-getassignable-services-no-services"));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_GET_ASSIGNABLE_SERVICES_OF_REALM", params);
    } catch (SSOException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmGetAssignableServices.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNABLE_SERVICES_OF_REALM", args);
    } catch (IdRepoException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmGetAssignableServices.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNABLE_SERVICES_OF_REALM", args);
    } catch (SMSException e) {
        String[] args = { realm, e.getMessage() };
        debugError("RealmGetAssignableServices.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_GET_ASSIGNABLE_SERVICES_OF_REALM", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) IdRepoException(com.sun.identity.idm.IdRepoException) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException)

Example 37 with CLIException

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

the class ExportServiceConfiguration method handleRequest.

/**
     * Handles request.
     *
     * @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();
    String outputFile = getStringOptionValue(IArgument.OUTPUT_FILE);
    String encryptSecret = getStringOptionValue(IArgument.ENCRYPT_SECRET);
    FileOutputStream fout = null;
    String[] param = { "tty" };
    String[] paramException = { "tty", "" };
    try {
        if ((outputFile != null) && (outputFile.length() > 0)) {
            fout = new FileOutputStream(outputFile);
            param[0] = outputFile;
            paramException[0] = outputFile;
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_EXPORT_SM_CONFIG_DATA", param);
        ServiceManager sm = new ServiceManager(adminSSOToken);
        AMEncryption encryptObj = new JCEEncryption();
        ((ConfigurableKey) encryptObj).setPassword(encryptSecret);
        String resultXML = sm.toXML(encryptObj);
        resultXML += "<!-- " + Hash.hash(encryptSecret) + " -->";
        if (fout != null) {
            fout.write(resultXML.getBytes("UTF-8"));
        } else {
            System.out.write(resultXML.getBytes("UTF-8"));
        }
        getOutputWriter().printlnMessage(getResourceString("export-service-configuration-succeeded"));
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_IMPORT_SM_CONFIG_DATA", param);
    } catch (UnsupportedEncodingException e) {
        paramException[1] = e.getMessage();
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_EXPORT_SM_CONFIG_DATA", paramException);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IOException e) {
        paramException[1] = e.getMessage();
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_EXPORT_SM_CONFIG_DATA", paramException);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        paramException[1] = e.getMessage();
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_EXPORT_SM_CONFIG_DATA", paramException);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        paramException[1] = e.getMessage();
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_EXPORT_SM_CONFIG_DATA", paramException);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (Exception e) {
        paramException[1] = e.getMessage();
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_EXPORT_SM_CONFIG_DATA", paramException);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } finally {
        if (fout != null) {
            try {
                fout.close();
            } catch (IOException ioe) {
            //ignored
            }
        }
    }
}
Also used : AMEncryption(com.iplanet.services.util.AMEncryption) SSOToken(com.iplanet.sso.SSOToken) JCEEncryption(com.iplanet.services.util.JCEEncryption) SMSException(com.sun.identity.sm.SMSException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException) ConfigurableKey(com.iplanet.services.util.ConfigurableKey) SMSException(com.sun.identity.sm.SMSException) IOException(java.io.IOException) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ServiceManager(com.sun.identity.sm.ServiceManager) FileOutputStream(java.io.FileOutputStream) CLIException(com.sun.identity.cli.CLIException)

Example 38 with CLIException

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

the class AddAttributeSchema method addAttributeSchemaXML.

private void addAttributeSchemaXML(ServiceSchema ss, String serviceName, String schemaType, String xml) throws CLIException {
    ByteArrayInputStream bis = null;
    try {
        bis = new ByteArrayInputStream(xml.getBytes());
        ss.addAttributeSchema(bis);
    } catch (SSOException e) {
        String[] args = { CLIConstants.WEB_INPUT, schemaType, xml, e.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_ADD_ATTRIBUTE_SCHEMA", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { CLIConstants.WEB_INPUT, schemaType, xml, e.getMessage() };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_ADD_ATTRIBUTE_SCHEMA", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } finally {
        if (bis != null) {
            try {
                bis.close();
            } catch (IOException ie) {
            //ignore if file input stream cannot be closed.
            }
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SMSException(com.sun.identity.sm.SMSException) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException)

Example 39 with CLIException

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

the class AddPluginInterface 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 i18nKey = getStringOptionValue(ARGUMENT_I18N_KEY);
    String interfaceName = getStringOptionValue(ARGUMENT_INTERFACE_NAME);
    String pluginName = getStringOptionValue(ARGUMENT_PLUGIN_NAME);
    ServiceSchemaManager ssm = getServiceSchemaManager();
    IOutput outputWriter = getOutputWriter();
    try {
        String[] params = { serviceName, pluginName };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_PLUGIN_INTERFACE", params);
        ssm.addPluginInterface(pluginName, interfaceName, i18nKey);
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ADD_PLUGIN_INTERFACE", params);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("add-plugin-interface-succeed"), (Object[]) params));
    } catch (SSOException e) {
        String[] args = { serviceName, pluginName, e.getMessage() };
        debugError("AddPluginInterface.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_PLUGIN_INTERFACE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serviceName, pluginName, e.getMessage() };
        debugError("AddPluginInterface.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_PLUGIN_INTERFACE", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Example 40 with CLIException

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

the class AddSubConfiguration 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 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);
    }
}
Also used : Set(java.util.Set) CLIException(com.sun.identity.cli.CLIException) List(java.util.List)

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