callbacks[0] = new NameCallback("User name");
callbacks[1] = new PasswordCallback("Password", false);
try {
handler.handle(callbacks);
} catch (IOException ioe) {
throw (LoginException) new LoginException().initCause(ioe);
} catch (UnsupportedCallbackException uce) {
throw (LoginException) new LoginException().initCause(uce);
}
cbUsername = ((NameCallback) callbacks[0]).getName();
cbPassword = new String(((PasswordCallback) callbacks[1]).getPassword());
if (cbUsername == null || "".equals(cbUsername)
|| cbPassword == null || "".equals(cbPassword)) {
// Clear out the private state
cbUsername = null;
cbPassword = null;
groups.clear();
throw new FailedLoginException();
}
try {
boolean result = authenticate(cbUsername, cbPassword);
if (!result) {
throw new FailedLoginException();
}
} catch (LoginException e) {
// Clear out the private state
cbUsername = null;
cbPassword = null;
groups.clear();
throw e;
} catch (Exception e) {
// Clear out the private state
cbUsername = null;
cbPassword = null;
groups.clear();
throw (LoginException) new LoginException("LDAP Error").initCause(e);
}
loginSucceeded = true;
return true;
}