If the principal is an instanceof UserDetails, UserDetails.getUsername();
This commit is contained in:
Ray Krueger 2005-08-23 15:15:06 +00:00
parent 438130ef4c
commit 2bda6ec25c
1 changed files with 14 additions and 2 deletions

View File

@ -16,6 +16,7 @@
package net.sf.acegisecurity.providers.jaas;
import net.sf.acegisecurity.Authentication;
import net.sf.acegisecurity.UserDetails;
import java.io.IOException;
@ -54,10 +55,21 @@ public class JaasNameCallbackHandler
* @throws UnsupportedCallbackException
*/
public void handle(Callback callback, Authentication authentication)
throws IOException, UnsupportedCallbackException {
throws IOException, UnsupportedCallbackException {
if (callback instanceof NameCallback) {
NameCallback ncb = (NameCallback) callback;
ncb.setName(authentication.getPrincipal().toString());
String username = "";
Object principal = authentication.getPrincipal();
if (principal instanceof UserDetails) {
username = ((UserDetails) principal).getUsername();
} else {
username = principal.toString();
}
ncb.setName(username);
}
}
}