Skip to main content

accesing username outside of the PlainTextPasswordValidator method

3 replies [Last post]
neo1982
Offline
Joined: 2009-01-23
Points: 0

hi i have a PlainTextPasswordValidator class which validates the username password.

the code is as follows

public class PlainTextPasswordValidator implements
PasswordValidationCallback.PasswordValidator {

private Logger log = Logger.getLogger(this.getClass());

public boolean validate(PasswordValidationCallback.Request request)
throws PasswordValidationCallback.PasswordValidationException {

PasswordValidationCallback.PlainTextPasswordRequest plainTextRequest
= (PasswordValidationCallback.PlainTextPasswordRequest) request;
..............................
.............................
.............................
if( myownvalidatemethod(plainTextRequest.getUsername(),plainTextRequest.getPassword() ){
// can I store the username in some session/request object/anyother object so that i can access it from my implementation class
return true;
}
else {
return false;
}

can someone / anyone help me.
i have been strugling with for days.

thanks in advance

Neo

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kumarjayanti
Offline
Joined: 2003-12-10
Points: 0

Did you try the following
1. @Resource
private WebServiceContext context;

context.getUserPrincipal();

See also : http://weblogs.java.net/blog/kumarjayanti/archive/2008/09/index.html

2. If you are using older versions of GlassFish V2 and Metro (and not those indicated in the blog above) then try

Subject subj = SubjectAccessor.getRequesterSubject(context);
Set

set = subj.getPrincipals();
neo1982
Offline
Joined: 2009-01-23
Points: 0

hi kumarjayanti

i am using netbean 6.5 with tomcat 6 and metro 1.4

i am using PlainTextPasswordValidator implements PasswordwordValidationCallback.PasswordValidator

for my validation i tried using
@Resource
private WebServiceContext context;

context.getUserPrincipal();

but the Principal object is null.

can guide me how exactly to use
Subject subj = SubjectAccessor.getRequesterSubject(context);
Set

set = subj.getPrincipals(); thanks in advance Neo
waynetg
Offline
Joined: 2007-06-04
Points: 0

Hi, here's my 2c on this

> i am using netbean 6.5 with tomcat 6 and metro 1.4
I'm using the same but with glassfish.

>
> i am using PlainTextPasswordValidator implements
> PasswordwordValidationCallback.PasswordValidator
I use the default password validator.

>
> for my validation i tried using
> @Resource
> private WebServiceContext context;
>
> context.getUserPrincipal();
>
> but the Principal object is null.
Agreed, I also get null however the context doesn't seem to be null. Anyone have an idea as to how to make this work?

>
> can guide me how exactly to use
> Subject subj =
> SubjectAccessor.getRequesterSubject(context);
> Set

set = subj.getPrincipals(); This is how I got the above to work. try { subj = SubjectAccessor.getRequesterSubject(context); Set set = subj.getPrincipals(); Iterator i = set.iterator(); while(i.hasNext()) { Principal p = (Principal) i.next(); pname = p.getName(); } } catch (XWSSecurityException ex) { Logger.getLogger(ejbws.class.getName()).log(Level.SEVERE, null, ex); } } Is there any way to use the username used to access my webservice within my webservice its self? Principal seems to only include the role name.