StartTlsResponse response = null;
try {
if (LdapProtocol.TLS.equals(Protocol)) {
StartTlsRequest request = new StartTlsRequest();
response = (StartTlsResponse) ctx.extendedOperation(request);
response.negotiate();
if (username != null && password != null) {
ctx.addToEnvironment(Context.SECURITY_AUTHENTICATION,
"simple");
ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, username);
ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, password);