public LDAPRealmAuthenticationCallbackHandler(Subject subject) {
this.subject = subject;
}
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
BasicAuthenticationPrincipal principal = SecurityUtil.getPrincipal(subject, BasicAuthenticationPrincipal.class);
if (principal != null){
/*
System.out.println(">>> LDAPRealmAuthenticationCallbackHandler" +
" Username: " + principal.getName() +
" Password: " + principal.getPassword());
*/
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof NameCallback) {
NameCallback nc = (NameCallback)callbacks[i];
nc.setName(principal.getName());
} else if (callbacks[i] instanceof PasswordCallback) {
PasswordCallback pc = (PasswordCallback)callbacks[i];
pc.setPassword(principal.getPassword().toCharArray());
} else {
throw new UnsupportedCallbackException
(callbacks[i], "Unsupported Callback!");
}
}