Search in sources :

Example 11 with CommandManager

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

the class IdRepoTest method suiteSetup.

/**
     * Create the CLIManager.
     */
@BeforeTest(groups = { "cli-idrepo" })
public void suiteSetup() throws CLIException {
    Map<String, Object> env = new HashMap<String, Object>();
    env.put(CLIConstants.SYS_PROPERTY_COMMAND_NAME, "amadm");
    env.put(CLIConstants.SYS_PROPERTY_DEFINITION_FILES, "com.sun.identity.cli.AccessManager");
    env.put(CLIConstants.SYS_PROPERTY_OUTPUT_WRITER, outputWriter);
    cmdManager = new CommandManager(env);
}
Also used : CommandManager(com.sun.identity.cli.CommandManager) HashMap(java.util.HashMap) BeforeTest(org.testng.annotations.BeforeTest)

Example 12 with CommandManager

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

the class SAML2Test method suiteSetup.

/**
     * Create the CLIManager.
     */
@BeforeTest(groups = { "cli" })
public void suiteSetup() throws CLIException {
    Map<String, Object> env = new HashMap<String, Object>();
    env.put(CLIConstants.SYS_PROPERTY_COMMAND_NAME, "famadm");
    env.put(CLIConstants.SYS_PROPERTY_DEFINITION_FILES, "com.sun.identity.federation.cli.FederationManager");
    env.put(CLIConstants.SYS_PROPERTY_OUTPUT_WRITER, outputWriter);
    cmdManager = new CommandManager(env);
}
Also used : CommandManager(com.sun.identity.cli.CommandManager) HashMap(java.util.HashMap) BeforeTest(org.testng.annotations.BeforeTest)

Example 13 with CommandManager

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

the class AddSubSchema 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);
    String fileName = getStringOptionValue(ARGUMENT_FILENAME);
    if (subSchemaName == null) {
        subSchemaName = "/";
    }
    IOutput outputWriter = getOutputWriter();
    String[] params = { serviceName, schemaType, subSchemaName };
    ServiceSchema ss = getServiceSchema();
    CommandManager mgr = getCommandManager();
    String url = mgr.getWebEnabledURL();
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_SUB_SCHEMA", params);
    try {
        if ((url != null) && (url.length() > 0)) {
            ss.addSubSchema(new ByteArrayInputStream(fileName.getBytes()));
        } else {
            ss.addSubSchema(new FileInputStream(fileName));
        }
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ADD_SUB_SCHEMA", params);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("add-subschema-succeed"), (Object[]) params));
    } catch (SSOException e) {
        String[] args = { serviceName, schemaType, subSchemaName, e.getMessage() };
        debugError("AddSubSchema.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_SUB_SCHEMA", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        String[] args = { serviceName, schemaType, subSchemaName, e.getMessage() };
        debugError("AddSubSchema.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_SUB_SCHEMA", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IOException e) {
        String[] args = { serviceName, schemaType, subSchemaName, e.getMessage() };
        debugError("AddSubSchema.handleRequest", e);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_SUB_SCHEMA", args);
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) CommandManager(com.sun.identity.cli.CommandManager) ByteArrayInputStream(java.io.ByteArrayInputStream) SMSException(com.sun.identity.sm.SMSException) IOutput(com.sun.identity.cli.IOutput) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 14 with CommandManager

use of com.sun.identity.cli.CommandManager 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 15 with CommandManager

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

the class ImportMetaData method handleRequest.

/**
     * Imports Meta Data.
     *
     * @param rc Request Context.
     * @throws CLIException if unable to process this request.
     */
@Override
public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    ldapLogin();
    realm = getStringOptionValue(FedCLIConstants.ARGUMENT_REALM, "/");
    metadata = getStringOptionValue(FedCLIConstants.ARGUMENT_METADATA);
    extendedData = getStringOptionValue(FedCLIConstants.ARGUMENT_EXTENDED_DATA);
    cot = getStringOptionValue(FedCLIConstants.ARGUMENT_COT);
    spec = FederationManager.getIDFFSubCommandSpecification(rc);
    String[] params = { realm, metadata, extendedData, cot, spec };
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_IMPORT_ENTITY", params);
    if ((metadata == null) && (extendedData == null)) {
        String[] args = { realm, metadata, extendedData, cot, spec, getResourceString("import-entity-exception-no-datafile") };
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IMPORT_ENTITY", args);
        throw new CLIException(getResourceString("import-entity-exception-no-datafile"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
    validateCOT();
    CommandManager mgr = getCommandManager();
    String url = mgr.getWebEnabledURL();
    webAccess = (url != null) && (url.length() > 0);
    try {
        if (spec.equals(FederationManager.DEFAULT_SPECIFICATION)) {
            handleSAML2Request(rc);
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_IMPORT_ENTITY", params);
        } else if (spec.equals(FedCLIConstants.IDFF_SPECIFICATION)) {
            handleIDFFRequest(rc);
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_IMPORT_ENTITY", params);
        } else if (spec.equals(FedCLIConstants.WSFED_SPECIFICATION)) {
            handleWSFedRequest(rc);
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_IMPORT_ENTITY", params);
        } else {
            throw new CLIException(getResourceString("unsupported-specification"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
    } catch (CLIException e) {
        String[] args = { realm, metadata, extendedData, cot, spec, e.getMessage() };
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_IMPORT_ENTITY", args);
        throw e;
    }
}
Also used : CommandManager(com.sun.identity.cli.CommandManager) CLIException(com.sun.identity.cli.CLIException)

Aggregations

CommandManager (com.sun.identity.cli.CommandManager)15 HashMap (java.util.HashMap)7 CLIException (com.sun.identity.cli.CLIException)6 BeforeTest (org.testng.annotations.BeforeTest)6 List (java.util.List)5 IOutput (com.sun.identity.cli.IOutput)4 Iterator (java.util.Iterator)4 SSOException (com.iplanet.sso.SSOException)3 SMSException (com.sun.identity.sm.SMSException)3 FileInputStream (java.io.FileInputStream)3 ArrayList (java.util.ArrayList)3 SSOToken (com.iplanet.sso.SSOToken)2 ServiceManager (com.sun.identity.sm.ServiceManager)2 ServiceSchema (com.sun.identity.sm.ServiceSchema)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)1 Connection (org.forgerock.opendj.ldap.Connection)1 ConnectionFactory (org.forgerock.opendj.ldap.ConnectionFactory)1