Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public class ImportServiceConfiguration extends AuthenticatedCommand {
* @param rc Request Context.
* @throws CLIException if the request cannot serviced.
*/
public void handleRequest(RequestContext rc)
public void handleRequest(RequestContext rc)
throws CLIException {
super.handleRequest(rc);

Expand All @@ -98,7 +98,7 @@ public void handleRequest(RequestContext rc)
//There is no encryptSecret file
}
validateEncryptSecret(xmlFile, encryptSecret);

// disable notification
SystemProperties.initializeProperties(
Constants.SMS_ENABLE_DB_NOTIFICATION, "true");
Expand All @@ -112,25 +112,26 @@ public void handleRequest(RequestContext rc)
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)
if (!vendor.name.equals(DirectoryServerVendor.WRENDS)
&& !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);
}

if (vendor.name.equals(DirectoryServerVendor.ODSEE)) {
loadLDIF(vendor, ldConnection);
}

String ouServices = "ou=services," + initSys.getRootSuffix();

if (this.isOuServicesExists(ssoToken, ouServices)) {
System.out.print(getResourceString(
"import-service-configuration-prompt-delete") + " ");
Expand Down Expand Up @@ -171,15 +172,15 @@ public void handleRequest(RequestContext rc)
"exception-LDAP-login-failed"), ExitCodes.LDAP_LOGIN_FAILED);
}
}

private String getEncKey(String xmlFile)
throws IOException {
String encKey = null;
BufferedReader reader = null;

try {
reader = new BufferedReader(new FileReader(xmlFile));

String line = reader.readLine();
String prefix = "<Value>" + Constants.ENC_PWD_PROPERTY + "=";
while ((line != null) && (encKey == null)) {
Expand All @@ -206,17 +207,17 @@ private String getEncKey(String xmlFile)
}
return encKey;
}

private boolean isOuServicesExists(SSOToken ssoToken, String ouServices)
throws SMSException, SSOException {
CachedSubEntries smsEntry = CachedSubEntries.getInstance(
ssoToken, ouServices);
Set children = smsEntry.getSubEntries(ssoToken, "*");
return (children != null) && !children.isEmpty();
}

private void deleteOuServicesDescendents(
SSOToken ssoToken,
SSOToken ssoToken,
String ouServices
) throws SSOException, SMSException {
CachedSubEntries smsEntry = CachedSubEntries.getInstance(
Expand Down Expand Up @@ -251,8 +252,8 @@ private void deleteOuServicesDescendents(
}

private void importData(
String xmlFile,
String encryptSecret,
String xmlFile,
String encryptSecret,
SSOToken ssoToken
) throws CLIException, SSOException, SMSException, IOException {
// set the correct password encryption key.
Expand All @@ -263,21 +264,21 @@ private void importData(
encKey);
Crypt.reinitialize();
}
IOutput outputWriter = getOutputWriter();
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,
ServerConfiguration.setServerConfigXML(ssoToken, instanceName,
serverConfigXML);
outputWriter.printlnMessage(getResourceString(
"import-service-configuration-succeeded"));
Expand Down Expand Up @@ -306,7 +307,7 @@ private Connection getLDAPConnection() throws CLIException {
if (isVerbose()) {
outputWriter.printlnMessage(getResourceString("import-service-configuration-connecting-to-ds"));
}

try {
Connection conn;
DSConfigMgr dsCfg = DSConfigMgr.getDSConfigMgr();
Expand All @@ -317,7 +318,7 @@ private Connection getLDAPConnection() throws CLIException {
throw new CLIException(getResourceString("import-service-configuration-not-connect-to-ds"),
ExitCodes.REQUEST_CANNOT_BE_PROCESSED, null);
}

if (isVerbose()) {
outputWriter.printlnMessage(getResourceString("import-service-configuration-connected-to-ds"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,40 @@
import org.forgerock.opendj.ldif.ConnectionEntryReader;

/**
* This singleton attempts to query vendor information of a Directory Server.
* This singleton attempts to query vendor information of a Directory Server.
*/
public class DirectoryServerVendor {

public static String OPENDS = "opends";
public static String OPENDJ = "opendj";
public static String WRENDS = "wrends";
public static String ODSEE = "odsee";

private static String VENDOR_WRENDS = "Wren:DS ";
private static String VENDOR_OPENDJ = "OpenDJ ";
private static String VENDOR_OPENDS = "OpenDS Directory Server ";
private static String VENDOR_SUNDS_5 = "Sun-ONE-Directory/";
private static String VENDOR_SUNDS_6 = "Sun-Java(tm)-System-Directory/";
private static String VENDOR_SUNDS_7 = "Sun-Directory-Server/";
private static String VENDOR_ODSEE_11 = "Oracle Directory Server Enterprise Edition";
private static DirectoryServerVendor instance = new DirectoryServerVendor();

private String[] attrs = {
"vendorversion", "rootDomainNamingContext", "forestFunctionality"};
private Vendor unknownVendor = new Vendor("unknown", "unknown");

private DirectoryServerVendor () {
}

/**
* Returns an instance of this class.
*
*
* @return an instance of this class.
*/
public static DirectoryServerVendor getInstance() {
return instance;
}

/**
* Returns the vendor of Directory Server.
* @param conn LDAP connection to the server.
Expand Down Expand Up @@ -106,7 +109,10 @@ public Vendor query(Connection conn) throws LdapException, SearchResultReference
Vendor vendor = unknownVendor;

if (result != null) {
if (result.startsWith(VENDOR_OPENDJ)) {
if (result.startsWith(VENDOR_WRENDS)) {
String version = result.substring(VENDOR_WRENDS.length());
vendor = new Vendor(WRENDS, version);
} else if (result.startsWith(VENDOR_OPENDJ)) {
String version = result.substring(VENDOR_OPENDJ.length());
vendor = new Vendor(OPENDJ, version);
} else if (result.startsWith(VENDOR_OPENDS)) {
Expand All @@ -129,17 +135,17 @@ public Vendor query(Connection conn) throws LdapException, SearchResultReference

return vendor;
}

public class Vendor {

public String name;
public String version;

public Vendor(String name, String version) {
this.name = name;
this.version = version;
}

public String toString() {
return name + " " + version;
}
Expand Down