Search in sources :

Example 6 with JCEEncryption

use of com.iplanet.services.util.JCEEncryption in project OpenAM by OpenRock.

the class ImportServiceConfiguration method importData.

private void importData(String xmlFile, String encryptSecret, SSOToken ssoToken) throws CLIException, SSOException, SMSException, IOException {
    // set the correct password encryption key.
    // without doing so, the default encryption key will be used.
    String encKey = getEncKey(xmlFile);
    if (encKey != null) {
        SystemProperties.initializeProperties(Constants.ENC_PWD_PROPERTY, encKey);
        Crypt.reinitialize();
    }
    IOutput outputWriter = getOutputWriter();
    FileInputStream fis = null;
    try {
        AMEncryption encryptObj = new JCEEncryption();
        ((ConfigurableKey) encryptObj).setPassword(encryptSecret);
        ServiceManager ssm = new ServiceManager(ssoToken);
        fis = new FileInputStream(xmlFile);
        ssm.registerServices(fis, encryptObj);
        InitializeSystem initSys = CommandManager.initSys;
        String instanceName = initSys.getInstanceName();
        String serverConfigXML = initSys.getServerConfigXML();
        ServerConfiguration.setServerConfigXML(ssoToken, instanceName, serverConfigXML);
        outputWriter.printlnMessage(getResourceString("import-service-configuration-succeeded"));
    } catch (IOException e) {
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SSOException e) {
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (SMSException e) {
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (Exception e) {
        throw new CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (IOException ie) {
            //ignore if file input stream cannot be closed.
            }
        }
    }
}
Also used : AMEncryption(com.iplanet.services.util.AMEncryption) JCEEncryption(com.iplanet.services.util.JCEEncryption) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException) ConfigurableKey(com.iplanet.services.util.ConfigurableKey) FileInputStream(java.io.FileInputStream) LoginException(javax.security.auth.login.LoginException) LDAPServiceException(com.iplanet.services.ldap.LDAPServiceException) InvalidAuthContextException(com.sun.identity.authentication.internal.InvalidAuthContextException) LdapException(org.forgerock.opendj.ldap.LdapException) SMSException(com.sun.identity.sm.SMSException) IOException(java.io.IOException) CLIException(com.sun.identity.cli.CLIException) SSOException(com.iplanet.sso.SSOException) InitializeSystem(com.sun.identity.cli.InitializeSystem) IOutput(com.sun.identity.cli.IOutput) ServiceManager(com.sun.identity.sm.ServiceManager) CLIException(com.sun.identity.cli.CLIException)

Example 7 with JCEEncryption

use of com.iplanet.services.util.JCEEncryption in project OpenAM by OpenRock.

the class JCECrypt method createInstance.

private static AMEncryption createInstance(String password) {
    AMEncryption instance;
    // Construct the encryptor class
    String encClass = System.getProperty(ENCRYPTOR_CLASS_PROPERTY, DEFAULT_ENCRYPTOR_CLASS);
    try {
        instance = Class.forName(encClass).asSubclass(AMEncryption.class).newInstance();
    } catch (Exception e) {
        Debug debug = Debug.getInstance("amSDK");
        debug.error("JCECrypt.createInstance Unable to get class instance: " + encClass + ", falling back to the" + " default implementation: " + DEFAULT_ENCRYPTOR_CLASS, e);
        instance = new JCEEncryption();
    }
    try {
        ((ConfigurableKey) instance).setPassword(password);
    } catch (Exception e) {
        Debug debug = Debug.getInstance("amSDK");
        if (debug != null) {
            debug.error("JCECrypt.createInstance: failed to set password-based key", e);
        }
    }
    return instance;
}
Also used : AMEncryption(com.iplanet.services.util.AMEncryption) JCEEncryption(com.iplanet.services.util.JCEEncryption) ConfigurableKey(com.iplanet.services.util.ConfigurableKey) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Debug(com.sun.identity.shared.debug.Debug)

Aggregations

JCEEncryption (com.iplanet.services.util.JCEEncryption)7 IOException (java.io.IOException)6 AMEncryption (com.iplanet.services.util.AMEncryption)5 ConfigurableKey (com.iplanet.services.util.ConfigurableKey)5 ServiceManager (com.sun.identity.sm.ServiceManager)4 SSOException (com.iplanet.sso.SSOException)2 SSOToken (com.iplanet.sso.SSOToken)2 CLIException (com.sun.identity.cli.CLIException)2 PWResetException (com.sun.identity.password.ui.model.PWResetException)2 SMSException (com.sun.identity.sm.SMSException)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 PrintWriter (java.io.PrintWriter)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 LDAPServiceException (com.iplanet.services.ldap.LDAPServiceException)1 InvalidAuthContextException (com.sun.identity.authentication.internal.InvalidAuthContextException)1 IOutput (com.sun.identity.cli.IOutput)1 InitializeSystem (com.sun.identity.cli.InitializeSystem)1