This content has been marked as final.
Show 1 reply
-
1. Re: Retrieve Username after authentication
kintar Jul 15, 2004 2:47 PM (in response to sorrentinov)Hi there.
I'm afraid I don't have terribly useful information, but I did want to let you know that in some instances, Principal.getName() does indeed return the username. I'm using a custom written database login module, and after returning from authentication, I can perform the following to locate the username (jsm is the variable name for a JaasSecurityManager looked up via JNDI using the JNDI name of the security realm my web app is using):Subject s = jsm.getActiveSubject(); Set pr = s.getPrincipals(); Iterator i = pr.iterator(); while (i.hasNext()) { Principal p = (Principal)i.next(); out.println("<h3>Principal: " + p.getName() + "</h3>"); }
This block iterates through all principals in the current user, and displays their name. The first principal entry comes back as the username used to log in, while the second entry comes back as "Roles". I'm not sure where that second one comes from, but I'm still rather new to JAAS, so it doesn't surprise me when weird things happen. ;)
Hope that helps a little. Maybe it will at least point you in a new direction to look.
-- Alec