use of com.sun.identity.cli.InitializeSystem in project OpenAM by OpenRock.
the class ImportServiceConfiguration 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);
String xmlFile = getStringOptionValue(IArgument.XML_FILE);
String encryptSecret = getStringOptionValue(IArgument.ENCRYPT_SECRET);
try {
encryptSecret = CLIUtil.getFileContent(getCommandManager(), encryptSecret).trim();
} catch (CLIException clie) {
//There is no encryptSecret file
}
validateEncryptSecret(xmlFile, encryptSecret);
// disable notification
SystemProperties.initializeProperties(Constants.SMS_ENABLE_DB_NOTIFICATION, "true");
SystemProperties.initializeProperties("com.sun.am.event.connection.disable.list", "sm,aci,um");
// disable error debug messsage
SystemProperties.initializeProperties(Constants.SYS_PROPERTY_INSTALL_TIME, "true");
IOutput outputWriter = getOutputWriter();
try (Connection ldConnection = getLDAPConnection()) {
InitializeSystem initSys = CommandManager.initSys;
SSOToken ssoToken = initSys.getSSOToken(getAdminPassword());
DirectoryServerVendor.Vendor vendor = DirectoryServerVendor.getInstance().query(ldConnection);
if (!vendor.name.equals(DirectoryServerVendor.OPENDJ) && !vendor.name.equals(DirectoryServerVendor.OPENDS) && !vendor.name.equals(DirectoryServerVendor.ODSEE)) {
throw new CLIException(getResourceString("import-service-configuration-unknown-ds"), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
loadLDIF(vendor, ldConnection);
String ouServices = "ou=services," + initSys.getRootSuffix();
if (this.isOuServicesExists(ssoToken, ouServices)) {
System.out.print(getResourceString("import-service-configuration-prompt-delete") + " ");
String value = (new BufferedReader(new InputStreamReader(System.in))).readLine();
value = value.trim();
if (value.equalsIgnoreCase("y") || value.equalsIgnoreCase("yes")) {
outputWriter.printlnMessage(getResourceString("import-service-configuration-processing"));
deleteOuServicesDescendents(ssoToken, ouServices);
importData(xmlFile, encryptSecret, ssoToken);
}
} else {
outputWriter.printlnMessage(getResourceString("import-service-configuration-processing"));
importData(xmlFile, encryptSecret, ssoToken);
}
} catch (SMSException e) {
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (LdapException e) {
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (SSOException e) {
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IOException e) {
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (LoginException e) {
throw new CLIException(getCommandManager().getResourceBundle().getString("exception-LDAP-login-failed"), ExitCodes.LDAP_LOGIN_FAILED);
} catch (InvalidAuthContextException e) {
throw new CLIException(getCommandManager().getResourceBundle().getString("exception-LDAP-login-failed"), ExitCodes.LDAP_LOGIN_FAILED);
}
}
use of com.sun.identity.cli.InitializeSystem 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.
}
}
}
}
Aggregations