}
for (Argument arg : firstServerCommandBuilder.getArguments())
{
if (arg.getLongIdentifier().equals(OPTION_LONG_HOST))
{
StringArgument host = new StringArgument("host1", OPTION_SHORT_HOST,
"host1", false, false, true, INFO_HOST_PLACEHOLDER.get(),
null,
null, INFO_DESCRIPTION_ENABLE_REPLICATION_HOST1.get());
host.addValue(uData.getHostName1());
commandBuilder.addArgument(host);
}
else if (arg.getLongIdentifier().equals(OPTION_LONG_PORT))
{
IntegerArgument port = new IntegerArgument("port1", OPTION_SHORT_PORT,
"port1",
false, false, true, INFO_PORT_PLACEHOLDER.get(), 4444, null,
INFO_DESCRIPTION_ENABLE_REPLICATION_SERVER_PORT1.get());
port.addValue(String.valueOf(uData.getPort1()));
commandBuilder.addArgument(port);
if (forceAddBindDN1)
{
StringArgument bindDN = new StringArgument("bindDN1",
OPTION_SHORT_BINDDN,
"bindDN1", false, false, true, INFO_BINDDN_PLACEHOLDER.get(),
"cn=Directory Manager", null,
INFO_DESCRIPTION_ENABLE_REPLICATION_BINDDN1.get());
bindDN.addValue(uData.getBindDn1());
commandBuilder.addArgument(bindDN);
if (forceAddBindPwdFile1)
{
FileBasedArgument bindPasswordFileArg = new FileBasedArgument(
"bindPasswordFile1",
null, "bindPasswordFile1", false, false,
INFO_BINDPWD_FILE_PLACEHOLDER.get(), null, null,
INFO_DESCRIPTION_ENABLE_REPLICATION_BINDPASSWORDFILE1.get());
bindPasswordFileArg.getNameToValueMap().put("{password file}",
"{password file}");
commandBuilder.addArgument(bindPasswordFileArg);
}
else
{
StringArgument bindPasswordArg = new StringArgument(
"bindPassword1",
null, "bindPassword1", false, false, true,
INFO_BINDPWD_PLACEHOLDER.get(), null, null,
INFO_DESCRIPTION_ENABLE_REPLICATION_BINDPASSWORD1.get());
bindPasswordArg.addValue(arg.getValue());
commandBuilder.addObfuscatedArgument(bindPasswordArg);
}
}
}
else if (arg.getLongIdentifier().equals(OPTION_LONG_BINDDN))
{
StringArgument bindDN = new StringArgument("bindDN1",
OPTION_SHORT_BINDDN,
"bindDN1", false, false, true, INFO_BINDDN_PLACEHOLDER.get(),
"cn=Directory Manager", null,
INFO_DESCRIPTION_ENABLE_REPLICATION_BINDDN1.get());
bindDN.addValue(uData.getBindDn1());
commandBuilder.addArgument(bindDN);
}
else if (arg.getLongIdentifier().equals(OPTION_LONG_BINDPWD))
{
if (useAdminUID)
{
adminInformationAdded = true;
StringArgument bindPasswordArg = new StringArgument("adminPassword",
OPTION_SHORT_BINDPWD, "adminPassword", false, false, true,
INFO_BINDPWD_PLACEHOLDER.get(), null, null,
INFO_DESCRIPTION_REPLICATION_ADMIN_BINDPASSWORD.get());
bindPasswordArg.addValue(arg.getValue());
commandBuilder.addObfuscatedArgument(bindPasswordArg);
}
else
{
StringArgument bindPasswordArg = new StringArgument("bindPassword1",
null, "bindPassword1", false, false, true,
INFO_BINDPWD_PLACEHOLDER.get(), null, null,
INFO_DESCRIPTION_ENABLE_REPLICATION_BINDPASSWORD1.get());
bindPasswordArg.addValue(arg.getValue());
commandBuilder.addObfuscatedArgument(bindPasswordArg);
}
}
else if (arg.getLongIdentifier().equals(OPTION_LONG_BINDPWD_FILE))
{
if (useAdminUID)
{
FileBasedArgument bindPasswordFileArg = new FileBasedArgument(
"adminPasswordFile",
OPTION_SHORT_BINDPWD_FILE, "adminPasswordFile", false, false,
INFO_BINDPWD_FILE_PLACEHOLDER.get(), null, null,
INFO_DESCRIPTION_REPLICATION_ADMIN_BINDPASSWORDFILE.get());
bindPasswordFileArg.getNameToValueMap().putAll(
((FileBasedArgument)arg).getNameToValueMap());
commandBuilder.addArgument(bindPasswordFileArg);
}
else
{
FileBasedArgument bindPasswordFileArg = new FileBasedArgument(
"bindPasswordFile1",
null, "bindPasswordFile1", false, false,
INFO_BINDPWD_FILE_PLACEHOLDER.get(), null, null,
INFO_DESCRIPTION_ENABLE_REPLICATION_BINDPASSWORDFILE1.get());
bindPasswordFileArg.getNameToValueMap().putAll(
((FileBasedArgument)arg).getNameToValueMap());
commandBuilder.addArgument(bindPasswordFileArg);
}
}
else
{
if (arg.getLongIdentifier().equals(OPTION_LONG_ADMIN_UID))
{
adminInformationAdded = true;
}
if (firstServerCommandBuilder.isObfuscated(arg))
{
commandBuilder.addObfuscatedArgument(arg);
}
else
{
commandBuilder.addArgument(arg);
}
}
}
}
if ((ci != null) && (ci.getCommandBuilder() != null))
{
CommandBuilder interactionBuilder = ci.getCommandBuilder();
boolean useAdminUID = false;
boolean hasBindDN = false;
for (Argument arg : interactionBuilder.getArguments())
{
if (arg.getLongIdentifier().equals(OPTION_LONG_ADMIN_UID))
{
useAdminUID = true;
}
else if (arg.getLongIdentifier().equals(OPTION_LONG_BINDDN))
{
hasBindDN = true;
}
if (useAdminUID && hasBindDN)
{
break;
}
}
// This is required when both the bindDN and the admin UID are provided
// in the command-line.
boolean forceAddBindDN2 = false;
boolean forceAddBindPwdFile2 = false;
if (useAdminUID)
{
String bindDN2 = uData.getBindDn2();
String adminUID = uData.getAdminUid();
if (bindDN2 != null && adminUID != null)
{
if (!Utils.areDnsEqual(ADSContext.getAdministratorDN(adminUID),
bindDN2))
{
forceAddBindDN2 = true;
for (Argument arg : interactionBuilder.getArguments())
{
if (arg.getLongIdentifier().equals(OPTION_LONG_BINDPWD_FILE))
{
forceAddBindPwdFile2 = true;
break;
}
}
}
}
}
ArrayList<Argument> argsToAnalyze = new ArrayList<Argument>();
for (Argument arg : interactionBuilder.getArguments())
{
if (arg.getLongIdentifier().equals(OPTION_LONG_HOST))
{
StringArgument host = new StringArgument("host2", 'O',
"host2", false, false, true, INFO_HOST_PLACEHOLDER.get(),
null,
null, INFO_DESCRIPTION_ENABLE_REPLICATION_HOST2.get());
host.addValue(uData.getHostName2());
commandBuilder.addArgument(host);
}
else if (arg.getLongIdentifier().equals(OPTION_LONG_PORT))
{
IntegerArgument port = new IntegerArgument("port2", null, "port2",
false, false, true, INFO_PORT_PLACEHOLDER.get(), 4444, null,
INFO_DESCRIPTION_ENABLE_REPLICATION_SERVER_PORT2.get());
port.addValue(String.valueOf(uData.getPort2()));
commandBuilder.addArgument(port);
if (forceAddBindDN2)
{
StringArgument bindDN = new StringArgument("bindDN2",
OPTION_SHORT_BINDDN,
"bindDN2", false, false, true, INFO_BINDDN_PLACEHOLDER.get(),
"cn=Directory Manager", null,
INFO_DESCRIPTION_ENABLE_REPLICATION_BINDDN2.get());
bindDN.addValue(uData.getBindDn2());
commandBuilder.addArgument(bindDN);
if (forceAddBindPwdFile2)
{
FileBasedArgument bindPasswordFileArg = new FileBasedArgument(
"bindPasswordFile2",
null, "bindPasswordFile2", false, false,
INFO_BINDPWD_FILE_PLACEHOLDER.get(), null, null,
INFO_DESCRIPTION_ENABLE_REPLICATION_BINDPASSWORDFILE2.get());
bindPasswordFileArg.getNameToValueMap().put("{password file}",
"{password file}");
commandBuilder.addArgument(bindPasswordFileArg);
}
else
{
StringArgument bindPasswordArg = new StringArgument(
"bindPassword2",
null, "bindPassword2", false, false, true,
INFO_BINDPWD_PLACEHOLDER.get(), null, null,
INFO_DESCRIPTION_ENABLE_REPLICATION_BINDPASSWORD2.get());
bindPasswordArg.addValue(arg.getValue());
commandBuilder.addObfuscatedArgument(bindPasswordArg);
}
}
}
else if (arg.getLongIdentifier().equals(OPTION_LONG_BINDDN))
{
StringArgument bindDN = new StringArgument("bindDN2", null,
"bindDN2", false, false, true, INFO_BINDDN_PLACEHOLDER.get(),
"cn=Directory Manager", null,
INFO_DESCRIPTION_ENABLE_REPLICATION_BINDDN2.get());
bindDN.addValue(uData.getBindDn2());
commandBuilder.addArgument(bindDN);
}
else if (arg.getLongIdentifier().equals(OPTION_LONG_BINDPWD))
{
if (useAdminUID && !adminInformationAdded)
{
adminInformationAdded = true;
StringArgument bindPasswordArg = new StringArgument("adminPassword",
OPTION_SHORT_BINDPWD, "adminPassword", false, false, true,
INFO_BINDPWD_PLACEHOLDER.get(), null, null,
INFO_DESCRIPTION_REPLICATION_ADMIN_BINDPASSWORD.get());
bindPasswordArg.addValue(arg.getValue());
commandBuilder.addObfuscatedArgument(bindPasswordArg);
}
else if (hasBindDN)
{
StringArgument bindPasswordArg = new StringArgument("bindPassword2",
null, "bindPassword2", false, false, true,
INFO_BINDPWD_PLACEHOLDER.get(), null, null,
INFO_DESCRIPTION_ENABLE_REPLICATION_BINDPASSWORD2.get());
bindPasswordArg.addValue(arg.getValue());
commandBuilder.addObfuscatedArgument(bindPasswordArg);
}
}
else if (arg.getLongIdentifier().equals(OPTION_LONG_BINDPWD_FILE))
{
if (useAdminUID && !adminInformationAdded)
{
adminInformationAdded = true;
FileBasedArgument bindPasswordFileArg = new FileBasedArgument(
"adminPasswordFile",
OPTION_SHORT_BINDPWD_FILE, "adminPasswordFile", false, false,
INFO_BINDPWD_FILE_PLACEHOLDER.get(), null, null,
INFO_DESCRIPTION_REPLICATION_ADMIN_BINDPASSWORDFILE.get());
bindPasswordFileArg.getNameToValueMap().putAll(
((FileBasedArgument)arg).getNameToValueMap());
commandBuilder.addArgument(bindPasswordFileArg);
}
else if (hasBindDN)
{
FileBasedArgument bindPasswordFileArg = new FileBasedArgument(
"bindPasswordFile2",
null, "bindPasswordFile2", false, false,
INFO_BINDPWD_FILE_PLACEHOLDER.get(), null, null,
INFO_DESCRIPTION_ENABLE_REPLICATION_BINDPASSWORDFILE2.get());
bindPasswordFileArg.getNameToValueMap().putAll(
((FileBasedArgument)arg).getNameToValueMap());
commandBuilder.addArgument(bindPasswordFileArg);
}
}
else
{
argsToAnalyze.add(arg);
}
}
for (Argument arg : argsToAnalyze)
{
// Just check that the arguments have not already been added.
boolean found = false;
for (Argument a : commandBuilder.getArguments())
{
if (a.getLongIdentifier().equals(arg.getLongIdentifier()))
{
found = true;
break;
}
}
if (!found)
{
if (interactionBuilder.isObfuscated(arg))
{
commandBuilder.addObfuscatedArgument(arg);
}
else
{
commandBuilder.addArgument(arg);
}
}
}
}
// Try to add the new administration information.
if (!adminInformationAdded)
{
StringArgument adminUID = new StringArgument(OPTION_LONG_ADMIN_UID, 'I',
OPTION_LONG_ADMIN_UID, false, false, true,
INFO_ADMINUID_PLACEHOLDER.get(),
Constants.GLOBAL_ADMIN_UID, null,
INFO_DESCRIPTION_REPLICATION_ADMIN_UID.get(
ReplicationCliArgumentParser.ENABLE_REPLICATION_SUBCMD_NAME));
if (uData.getAdminUid() != null)
{
adminUID.addValue(uData.getAdminUid());
commandBuilder.addArgument(adminUID);
}
if (userProvidedAdminPwdFile != null)
{
commandBuilder.addArgument(userProvidedAdminPwdFile);
}
else
{
Argument bindPasswordArg = new StringArgument("adminPassword",
OPTION_SHORT_BINDPWD, "adminPassword", false, false, true,
INFO_BINDPWD_PLACEHOLDER.get(), null, null,
INFO_DESCRIPTION_REPLICATION_ADMIN_BINDPASSWORD.get());
if (uData.getAdminPwd() != null)
{
bindPasswordArg.addValue(uData.getAdminPwd());
commandBuilder.addObfuscatedArgument(bindPasswordArg);
}
}
}