use of com.iplanet.services.util.ConfigurableKey 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
}
}
}
}
use of com.iplanet.services.util.ConfigurableKey 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);
}
}
}
use of com.iplanet.services.util.ConfigurableKey in project OpenAM by OpenRock.
the class UpgradeServices method writeBackup.
/**
* Creates a backup of the services/subconfigurations in case there is a need for a rollback.
*
* @param adminToken Valid admin SSOToken.
* @throws UpgradeException If there was an error while creating the backup.
*/
protected void writeBackup(SSOToken adminToken) throws UpgradeException {
FileOutputStream fout = null;
String baseDir = SystemProperties.get(SystemProperties.CONFIG_PATH);
String backupDir = baseDir + File.separator + "backups" + File.separator;
File backupFile = new File(backupDir + "servicebackup." + createdDate);
File backupPasswdFile = new File(backupDir + "servicebackup.password." + createdDate);
String backupPassword = generateBackupPassword();
if (backupFile.exists()) {
debug.error("Upgrade cannot continue as backup file exists! " + backupFile.getName());
throw new UpgradeException("Upgrade cannot continue as backup file exists");
}
try {
fout = new FileOutputStream(backupFile);
ServiceManager sm = new ServiceManager(adminToken);
AMEncryption encryptObj = new JCEEncryption();
((ConfigurableKey) encryptObj).setPassword(backupPassword);
String resultXML = sm.toXML(encryptObj);
resultXML += "<!-- " + Hash.hash(backupPassword) + " -->";
fout.write(resultXML.getBytes("UTF-8"));
} catch (Exception ex) {
debug.error("Unable to write backup: ", ex);
throw new UpgradeException("Unable to write backup: " + ex.getMessage());
} finally {
if (fout != null) {
try {
fout.close();
} catch (IOException ioe) {
//ignored
}
}
}
if (backupPasswdFile.exists()) {
debug.error("Upgrade cannot continue as backup password file exists! " + backupPasswdFile.getName());
throw new UpgradeException("Upgrade cannot continue as backup password file exists");
}
PrintWriter out = null;
try {
out = new PrintWriter(new FileOutputStream(backupPasswdFile));
out.println(backupPassword);
out.flush();
} catch (IOException ioe) {
debug.error("Unable to write backup: ", ioe);
throw new UpgradeException("Unable to write backup: " + ioe.getMessage());
} catch (Exception ex) {
debug.error("Unable to write backup: ", ex);
throw new UpgradeException("Unable to write backup: " + ex.getMessage());
} finally {
if (out != null) {
out.close();
}
}
}
use of com.iplanet.services.util.ConfigurableKey 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.
}
}
}
}
use of com.iplanet.services.util.ConfigurableKey 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;
}
Aggregations