Search in sources :

Example 6 with ServiceManager

use of com.sun.identity.sm.ServiceManager in project OpenAM by OpenRock.

the class RegisterServices method registerService.

private void registerService(String xml, SSOToken adminSSOToken) throws SSOException, SMSException, IOException {
    ServiceManager serviceManager = new ServiceManager(adminSSOToken);
    InputStream serviceStream = null;
    try {
        serviceStream = (InputStream) new ByteArrayInputStream(xml.getBytes());
        serviceManager.registerServices(serviceStream);
    } finally {
        if (serviceStream != null) {
            serviceStream.close();
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ServiceManager(com.sun.identity.sm.ServiceManager) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 7 with ServiceManager

use of com.sun.identity.sm.ServiceManager 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 8 with ServiceManager

use of com.sun.identity.sm.ServiceManager 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 9 with ServiceManager

use of com.sun.identity.sm.ServiceManager 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 10 with ServiceManager

use of com.sun.identity.sm.ServiceManager in project OpenAM by OpenRock.

the class AccessControlModelImpl method getServiceNames.

private Set getServiceNames() {
    if (serviceNames == null) {
        SSOToken adminSSOToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
        try {
            ServiceManager sm = new ServiceManager(adminSSOToken);
            serviceNames = sm.getServiceNames();
        } catch (SSOException e) {
            AMModelBase.debug.error("AccessControlModelImpl.getServiceNames", e);
        } catch (SMSException e) {
            AMModelBase.debug.error("AccessControlModelImpl.getServiceNames", e);
        }
    }
    return serviceNames;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) ServiceManager(com.sun.identity.sm.ServiceManager) SSOException(com.iplanet.sso.SSOException)

Aggregations

ServiceManager (com.sun.identity.sm.ServiceManager)34 SMSException (com.sun.identity.sm.SMSException)20 SSOException (com.iplanet.sso.SSOException)17 SSOToken (com.iplanet.sso.SSOToken)11 IOException (java.io.IOException)10 CLIException (com.sun.identity.cli.CLIException)7 Iterator (java.util.Iterator)7 Set (java.util.Set)7 IOutput (com.sun.identity.cli.IOutput)6 FileInputStream (java.io.FileInputStream)6 HashSet (java.util.HashSet)6 ByteString (org.forgerock.opendj.ldap.ByteString)5 AMEncryption (com.iplanet.services.util.AMEncryption)4 ConfigurableKey (com.iplanet.services.util.ConfigurableKey)4 JCEEncryption (com.iplanet.services.util.JCEEncryption)4 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 List (java.util.List)4 AMException (com.iplanet.am.sdk.AMException)3