How to retrieve user name from a given Subject?
843811Jul 11 2005 — edited Jul 12 2005I am in a situation where I need to retrieve user name from the Subject that is populated when user logs in. I have the active Subject and I do following to get the principals in the subject and iterate through them:
Set principals = subject.getPrincipals();
Iterator ite = principals.iterator();
while (ite.hasNext()) {
Principal prin = (Principal)ite.next();
String name = prin.getName();
}
But this contains all the principals, including user name, roles, password, etc. How do I programmatically determine which one is user name?