private boolean authenticate(String userDn, String password) {
try {
Control[] connCtls = new Control[]{};
ctx.getRequestControls();
ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, userDn);
ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, password);
ctx.reconnect(connCtls);
System.out.println("authenticate success !");
return true;
} catch (AuthenticationException e) {
return false;
} catch (NamingException e) {
return false;
} finally {
if (ctx != null) {
try {
//ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, transientInstance.getAccountName());
//ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, transientInstance.getAccountPwd());
ctx.reconnect(ctx.getConnectControls());
ctx.close();
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
try {
Control[] connCtls = new Control[]{};
ctx.getRequestControls();
ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, userDn);
ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, password);
ctx.reconnect(connCtls);
System.out.println("authenticate success !");
return true;
} catch (AuthenticationException e) {
return false;
} catch (NamingException e) {
return false;
} finally {
if (ctx != null) {
try {
//ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, transientInstance.getAccountName());
//ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, transientInstance.getAccountPwd());
ctx.reconnect(ctx.getConnectControls());
ctx.close();
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}