You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Pratyush Chandra <co...@yahoo.com> on 2011/03/23 09:45:23 UTC

Doubt regarding basic http authentication

I tried using AuthenticationHandler extending RequestHandler...where i write
authentication logic...
but I donnot know how to access username in my service implementation

So, I tried instead having a ServiceImpl class where I have a :

	@Context MessageContext mc;

       public void getInfo() {
		AuthorizationPolicy policy =
(AuthorizationPolicy)mc.get(AuthorizationPolicy.class.getName());
		String userName = policy.getUserName();
		String password = policy.getPassword();
		logger.error(userName+" "+password);
	}

        public Response serviceMethod() {
              //do something
             getInfo();
        }

I am able to access the username and password..
My concern is whether MessageContext is set per service request and is value
of MessageContext jumbled up with value of some other service call  (or
remains steady per request). In that case I will have to pass it as service
function parameter.




--
View this message in context: http://cxf.547215.n5.nabble.com/Doubt-regarding-basic-http-authentication-tp4258402p4258402.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Doubt regarding basic http authentication

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

On Wed, Mar 23, 2011 at 8:45 AM, Pratyush Chandra
<co...@yahoo.com>wrote:

> I tried using AuthenticationHandler extending RequestHandler...where i
> write
> authentication logic...
> but I donnot know how to access username in my service implementation
>
> So, I tried instead having a ServiceImpl class where I have a :
>
>        @Context MessageContext mc;
>
>       public void getInfo() {
>                AuthorizationPolicy policy =
> (AuthorizationPolicy)mc.get(AuthorizationPolicy.class.getName());
>                String userName = policy.getUserName();
>                String password = policy.getPassword();
>                logger.error(userName+" "+password);
>        }
>
>        public Response serviceMethod() {
>              //do something
>             getInfo();
>        }
>
> I am able to access the username and password..
> My concern is whether MessageContext is set per service request and is
> value
> of MessageContext jumbled up with value of some other service call  (or
> remains steady per request). In that case I will have to pass it as service
> function parameter.
>
>
>
> All @Context annotated fields are thread-safe. You can actually do the same
in the RequestHandler, but use a current Message instead of MessageContext;
contexts can also be injected in handlers...

Cheers, Sergey