How to get user's credentials then, without messing around with custom realms? In a GlassFish, the recipe is as follows:
- From GlassFish
lib/
directory addappserv-rt.jar
library to your class path in order to get allcom.sun.enterprise.*
become available in your application. - Get a subject:
import com.sun.enterprise.security.auth.login.PasswordCredential;
import javax.security.auth.Subject;
import javax.security.jacc.PolicyContext;
import javax.security.jacc.PolicyContextException;
...
Subject subject = null;
try {
subject = (Subject) PolicyContext
.getContext("javax.security.auth.Subject.container");
} catch (PolicyContextException ex) {
...
} - From the subject, get an iterator from private credentials object:
Iterator iter = subject.getPrivateCredentials().iterator();
while (iter.hasNext()) {
PasswordCredential credential = (PasswordCredential) iter.next();
...
} - Now you can get PasswordCredential object that contains: a) realm name as
getRealm()
, b) user ID asgetUser()
, c) password asgetPassword()
.
That's it.
2 comments:
I am very grateful to you for your help.
You helped me solve a problem that had stalled for days.
Thanks so much!
I am very grateful to you for your help.
You helped me solve a problem that had stalled for days.
Post a Comment