Hi all
I have a java application that accesses EJBs on a JBoss application server. My application requires the user to log in, providing username and password. After successful authentication, the user can access the application.
I would now like to be able to extract the users credentials (username) while he is logged in and workin in the application. How can this be done? how can i extract credential from a current session?
I currently use the following code (client side):
-----------------------
public static String getUserSubject(LoginContext lc) throws Exception
{
String subject = "";
try
{
Subject sub = lc.getSubject();
Set principals = sub.getPrivateCredentials();
Object[] objCredentials = principals.toArray();
String[] sPrincipals = null;
for(int i=0; i< objCredentials.length; i++)
{
sPrincipals = (String)objCredentials;
System.out.println("Credentials (lc): " +sPrincipals);
}
}
catch (Exception ex)
{
logger.error("Problem getting login context information.");
System.out.println("ERROR: "+ex);
}
return subject;
}
---------------------------------------
But the above code returns only 'null'. What's wrong here?
Cheers,
M.
-
getting credentials of logged in user (4 messages)
- Posted by: Michael Boeni
- Posted on: September 26 2004 15:25 EDT
Threaded Messages (4)
- getting credentials of logged in user by Benjamin Possolo on October 05 2004 19:15 EDT
- getting credentials of logged in user by Michael Boeni on October 13 2004 08:23 EDT
-
getting credentials of logged in user by Michael Boeni on October 13 2004 12:47 EDT
- getting credentials of logged in user by Alfonso Alfonso on January 06 2005 07:58 EST
-
getting credentials of logged in user by Michael Boeni on October 13 2004 12:47 EDT
- getting credentials of logged in user by Michael Boeni on October 13 2004 08:23 EDT
-
getting credentials of logged in user[ Go to top ]
- Posted by: Benjamin Possolo
- Posted on: October 05 2004 19:15 EDT
- in response to Michael Boeni
u set
<code>String subject = "";</code>
at the very beginning.
but then u never do anything else with the variable again.
are u expecting it to return the emptry string "" instead of null or what? -
getting credentials of logged in user[ Go to top ]
- Posted by: Michael Boeni
- Posted on: October 13 2004 08:23 EDT
- in response to Benjamin Possolo
Hi there
Right you are. But that I am not currently relying on the subject string. I get nothing back if I, for example, use:
Subject sub = lc.getSubject();
Set principals = sub.getPrivateCredentials();
System.out.println("Principals: "+principals.size());
principals.size() returns 0, so there seems to be nothing to get...
Any ideas?
Michael -
getting credentials of logged in user[ Go to top ]
- Posted by: Michael Boeni
- Posted on: October 13 2004 12:47 EDT
- in response to Michael Boeni
No worries! I have been able to resolve the issue in the mean time.
Cheers,
Michael -
getting credentials of logged in user[ Go to top ]
- Posted by: Alfonso Alfonso
- Posted on: January 06 2005 19:58 EST
- in response to Michael Boeni
can you write the solution, please!! I've the same problem and I looking for a solution.
thanks