users@jersey.java.net

Re: Basic User authentication using SecurityContext

From: Lars Tackmann <lars_at_randompage.org>
Date: Mon, 31 Mar 2008 18:39:14 +0200

On Mon, Mar 31, 2008 at 4:31 PM, Leif Gensert <leifg_at_gmx.de> wrote:
> For my implementation I need to access data sources using username &
> password. Therefore the client must deliver these information to the
> web-service.
>
> I'd like to use the basic authorization of http (something like this:
> "Authorization: Basic c2FkZmFzZGY6c2FkZmRzYWRzYWY=")
>
> On the other side I need to get username and password for access. Is
> there a way to get this information using @Content SecurityContext? Or
> do I need to set the Authorization String manually.
>
> Leif Gensert

I think that SecurityContext is intended for container managed seurity
(i.e. JDBC realm). You can
however inject the http headers into your class yourself and the info
from there i.e:

@Context
private HTTPHeaders headers;

and decode the headers yourself (I have a example of that here
http://svn.randompage.org/java/jeeSamples/jax-rs/bookmarking/src/main/java/org/randompage/samples/jaxrs/bookmarking/common/Utils.java).

As for the client you can set the appropiate info using the splendid
JAX-RS client - I also have a example of this here
http://svn.randompage.org/java/jeeSamples/jax-rs/bookmarking/src/test/java/org/randompage/samples/jaxrs/bookmarking/test/WSTest.java

Hope it helps


-- 
Yours sincerely
Lars Tackmann