Search in sources :

Example 11 with ServiceManager

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

the class AddAMSDKIdRepoPlugin method loadDAIService.

private String loadDAIService() throws SMSException, SSOException, CLIException, IOException {
    SSOToken adminSSOToken = getAdminSSOToken();
    // Load DAI service, if not already loaded
    String xmlData = null;
    ServiceManager sm = new ServiceManager(adminSSOToken);
    if (!sm.getServiceNames().contains("DAI")) {
        xmlData = getResourceContent("ums.xml");
        // Tag swap: @USER_NAMING_ATTR & @ORG_NAMING_ATTR
        xmlData = xmlData.replaceAll("@USER_NAMING_ATTR@", namingAttr);
        xmlData = xmlData.replaceAll("@ORG_NAMING_ATTR@", orgAttr);
        registerService(xmlData, adminSSOToken);
    }
    return xmlData;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ServiceManager(com.sun.identity.sm.ServiceManager)

Example 12 with ServiceManager

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

the class AddAMSDKIdRepoPlugin 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) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream)

Example 13 with ServiceManager

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

the class AddPluginSchema 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 serviceName = getStringOptionValue(IArgument.SERVICE_NAME);
    String interfaceName = getStringOptionValue(ARGUMENT_INTERFACE_NAME);
    String pluginName = getStringOptionValue(ARGUMENT_PLUGIN_NAME);
    String i18nKey = getStringOptionValue(ARGUMENT_I18N_KEY);
    String i18nName = getStringOptionValue(ARGUMENT_I18N_NAME);
    String className = getStringOptionValue(ARGUMENT_CLASS_NAME);
    ServiceManager sm = null;
    try {
        sm = new ServiceManager(adminSSOToken);
    } catch (SMSException smse) {
        throw new CLIException(smse, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException ssoe) {
        throw new CLIException(ssoe, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
    IOutput outputWriter = getOutputWriter();
    try {
        String[] params = { serviceName, interfaceName, pluginName, i18nKey, i18nName, className };
        writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_ADD_PLUGIN_SCHEMA", params);
        Document pluginDoc = createPluginSchemaXML(serviceName, interfaceName, pluginName, i18nKey, i18nName, className);
        if (pluginDoc != null) {
            sm.addPluginSchema(pluginDoc);
            String[] params2 = { serviceName, pluginName };
            writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEED_ADD_PLUGIN_SCHEMA", params2);
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("add-plugin-schema-succeed"), (Object[]) params));
        } else {
            String[] args = { serviceName, pluginName, "Null XML Document" };
            debugError("AddPluginSchema.handleRequest:: Null XML Document");
            writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_PLUGIN_SCHEMA", args);
            throw new CLIException("Null XML Document", ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
    } catch (SSOException ssoe) {
        String[] args = { serviceName, pluginName, ssoe.getMessage() };
        debugError("AddPluginSchema.handleRequest", ssoe);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_PLUGIN_SCHEMA", args);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("add-plugin-schema-failed"), (Object[]) args));
        throw new CLIException(ssoe, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException smse) {
        String[] args = { serviceName, pluginName, smse.getMessage() };
        debugError("AddPluginSchema.handleRequest", smse);
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_ADD_PLUGIN_SCHEMA", args);
        outputWriter.printlnMessage(MessageFormat.format(getResourceString("add-plugin-schema-failed"), (Object[]) args));
        throw new CLIException(smse, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) ServiceManager(com.sun.identity.sm.ServiceManager) IOutput(com.sun.identity.cli.IOutput) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) Document(org.w3c.dom.Document)

Example 14 with ServiceManager

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

the class DefaultDebugRecorder method exportConfigExport.

/**
     * Export the OpenAM config export
     */
private void exportConfigExport() {
    if (currentRecord.getRecordProperties().isConfigExportEnabled()) {
        SSOToken adminSSOToken = AccessController.doPrivileged(AdminTokenAction.getInstance());
        try {
            ServiceManager sm = new ServiceManager(adminSSOToken);
            AMEncryption encryptObj = new JCEEncryption();
            ((ConfigurableKey) encryptObj).setPassword(currentRecord.getRecordProperties().getConfigExportPassword());
            String resultXML = sm.toXML(encryptObj);
            SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_UID);
            String xmlName = RecordConstants.OPENAM_CONFIG_EXPORT_FILE_NAME.replace("$DATE$", dateFormat.format(new Date()));
            File file = new File(currentRecord.getFolderPath() + File.separator + xmlName);
            PrintWriter printWriter = new PrintWriter(new FileWriter(file, false), true);
            printWriter.println(resultXML);
            printWriter.flush();
        } catch (Exception e) {
            debug.error("Can't export OpenAM configuration", e);
        }
    }
}
Also used : AMEncryption(com.iplanet.services.util.AMEncryption) SSOToken(com.iplanet.sso.SSOToken) JCEEncryption(com.iplanet.services.util.JCEEncryption) ServiceManager(com.sun.identity.sm.ServiceManager) FileWriter(java.io.FileWriter) ConfigurableKey(com.iplanet.services.util.ConfigurableKey) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) JSONException(org.json.JSONException) ParseException(java.text.ParseException) IOException(java.io.IOException) JsonValueException(org.forgerock.json.JsonValueException) PrintWriter(java.io.PrintWriter)

Example 15 with ServiceManager

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

the class UserIdRepo 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)

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