Search in sources :

Example 1 with CommandManager

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

the class CreateXACML method getXacmlInputStream.

private InputStream getXacmlInputStream(String realm) throws CLIException {
    InputStream inputStream;
    String datafile = getStringOptionValue(IArgument.XML_FILE);
    CommandManager mgr = getCommandManager();
    String url = mgr.getWebEnabledURL();
    if ((url != null) && (url.length() > 0)) {
        inputStream = new ByteArrayInputStream(datafile.getBytes());
    } else {
        try {
            inputStream = new FileInputStream(datafile);
        } catch (FileNotFoundException e) {
            debugError("CreateXACML.handleRequest", e);
            logException(realm, e);
            throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
    }
    return inputStream;
}
Also used : CommandManager(com.sun.identity.cli.CommandManager) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) CLIException(com.sun.identity.cli.CLIException) FileInputStream(java.io.FileInputStream)

Example 2 with CommandManager

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

the class AddAMSDKIdRepoPlugin method loadLDIFs.

private void loadLDIFs() throws Exception {
    CommandManager mgr = getCommandManager();
    List ldifs = getLDIFs();
    for (Iterator i = directoryServers.iterator(); i.hasNext(); ) {
        String dshost = (String) i.next();
        try (ConnectionFactory factory = getLDAPConnection(new DSEntry(dshost));
            Connection ld = factory.getConnection()) {
            String dbName = LDAPUtils.getDBName(basedn, ld);
            for (Iterator j = ldifs.iterator(); j.hasNext(); ) {
                String file = (String) j.next();
                String content = CLIUtil.getFileContent(mgr, file);
                String swapped = tagswap(content, dbName);
                loadLDIF(ld, swapped);
            }
        }
    }
}
Also used : ConnectionFactory(org.forgerock.opendj.ldap.ConnectionFactory) LDAPConnectionFactory(org.forgerock.opendj.ldap.LDAPConnectionFactory) CommandManager(com.sun.identity.cli.CommandManager) Iterator(java.util.Iterator) Connection(org.forgerock.opendj.ldap.Connection) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with CommandManager

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

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

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

the class UpdateAuthConfigurationEntries method parse.

private List parse(String fileName, List listEntries) throws CLIException, AMConfigurationException {
    CommandManager mgr = getCommandManager();
    List results = null;
    if (fileName != null) {
        results = parse(mgr, fileName);
    }
    if ((listEntries != null) && !listEntries.isEmpty()) {
        if (results != null) {
            results.addAll(parse(mgr, listEntries));
        } else {
            results = parse(mgr, listEntries);
        }
    }
    return (results == null) ? new ArrayList() : results;
}
Also used : CommandManager(com.sun.identity.cli.CommandManager) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

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