if (controlInfo.getServerDescriptor().getStatus() ==
ServerDescriptor.ServerStatus.STARTED) {
String bindDn;
String bindPwd;
if (argParser.isInteractive()) {
ManagementContext ctx = null;
// This is done because we do not need to ask the user about these
// parameters. If we force their presence the class
// LDAPConnectionConsoleInteraction will not prompt the user for
// them.
SecureConnectionCliArgs secureArgsList =
argParser.getSecureArgsList();
int port =
AdministrationConnector.DEFAULT_ADMINISTRATION_CONNECTOR_PORT;
controlInfo.setConnectionPolicy(
ConnectionProtocolPolicy.USE_ADMIN);
String ldapUrl = controlInfo.getURLToConnect();
try {
URI uri = new URI(ldapUrl);
port = uri.getPort();
} catch (Throwable t) {
LOG.log(Level.SEVERE, "Error parsing url: " + ldapUrl);
}
secureArgsList.hostNameArg.setPresent(true);
secureArgsList.portArg.setPresent(true);
secureArgsList.hostNameArg.addValue(
secureArgsList.hostNameArg.getDefaultValue());
secureArgsList.portArg.addValue(Integer.toString(port));
// We already know if SSL or StartTLS can be used. If we cannot
// use them we will not propose them in the connection parameters
// and if none of them can be used we will just not ask for the
// protocol to be used.
LDAPConnectionConsoleInteraction ci =
new LDAPConnectionConsoleInteraction(
this, argParser.getSecureArgsList());
try {
ci.run(true, false);
bindDn = ci.getBindDN();
bindPwd = ci.getBindPassword();
LDAPManagementContextFactory factory =
new LDAPManagementContextFactory(alwaysSSL);
ctx = factory.getManagementContext(this, ci);
interactiveTrustManager = ci.getTrustManager();
controlInfo.setTrustManager(interactiveTrustManager);
useInteractiveTrustManager = true;
} catch (ArgumentException e) {
println(e.getMessageObject());
return ErrorReturnCode.USER_CANCELLED_OR_DATA_ERROR.getReturnCode();
} catch (ClientException e) {
println(e.getMessageObject());
writeStatus(controlInfo);
return ErrorReturnCode.USER_CANCELLED_OR_DATA_ERROR.getReturnCode();
} finally {
if (ctx != null) {
try {
ctx.close();
} catch (Throwable t) {
}
}
}
} else {
bindDn = argParser.getBindDN();
bindPwd = argParser.getBindPassword();
}
authProvided = bindPwd != null;
if (bindDn == null) {
bindDn = "";
}
if (bindPwd == null) {
bindPwd = "";
}
if (authProvided) {
InitialLdapContext ctx = null;
try {
ctx = Utilities.getAdminDirContext(controlInfo, bindDn, bindPwd);
controlInfo.setDirContext(ctx);
controlInfo.regenerateDescriptor();
writeStatus(controlInfo);
if (!controlInfo.getServerDescriptor().getExceptions().isEmpty()) {
return ErrorReturnCode.ERROR_READING_CONFIGURATION_WITH_LDAP.
getReturnCode();
}
} catch (NamingException ne) {
// This should not happen but this is useful information to
// diagnose the error.
println();
println(INFO_ERROR_READING_SERVER_CONFIGURATION.get(
ne.toString()));
return ErrorReturnCode.ERROR_READING_CONFIGURATION_WITH_LDAP.
getReturnCode();
} catch (ConfigReadException cre) {
// This should not happen but this is useful information to
// diagnose the error.
println();
println(cre.getMessageObject());
return ErrorReturnCode.ERROR_READING_CONFIGURATION_WITH_LDAP.
getReturnCode();
} finally {
if (ctx != null) {
try {
ctx.close();
} catch (Throwable t) {
}
}
}
} else {