users@jersey.java.net

Re: [Jersey] HTTP Basic Authentication (header encoding)

From: Pavel Bucek <Pavel.Bucek_at_Sun.COM>
Date: Fri, 01 May 2009 00:40:54 +0200

Hello,

see MainTest.java in https-clientserver-grizzly sample:

==========

        Client c = Client.create();

        // client basic auth demonstration
        c.addFilter(new HTTPBasicAuthFilter("user", "password"));

        System.out.println("Client: GET " + Server.BASE_URI);

        WebResource r = c.resource(Server.BASE_URI);

        String page = (String) r.path("/").get(String.class);

==========

And how this works? When you create WebResource instance, it has
reference to the original client and every request is passed through it
(so filter will be used for all WebResource instances created from that
particular Client).

Or you can set filter even on WebResource instance:

==========
        Client c = Client.create();

        WebResource r = c.resource(Server.BASE_URI);

        r.addFilter(new HTTPBasicAuthFilter("user", "password"));

        String page = (String) r.path("/").get(String.class);
==========


Hope it helps.

Pavel


Rabick, Mark A (IS) wrote:
> I forgot to prefix the header with "Basic " but my I'm trying to figure
> out how to use the HTTPBasicAuthFilter and ClientHandler code but I
> can't find an example:
>
>
> HTTPBasicAuthFilter authFilter = new
> HTTPBasicAuthFilter("weblogic","weblogic");
> ClientConfig cc = new DefaultClientConfig();
> Client c = Client.create(cc);
> c.addFilter(authFilter);
> webResource =
> c.resource("http://localhost:7001/i3/cnodb/cdal/rest");
>
> but I'm not sure how this all harnesses together...
>
> -mark
>
> _______________________________________________
> Mark A. Rabick - Software Engineer
> Em: mark.rabick_at_ngc.com
>
>
>
>
> ________________________________
>
> From: Craig.McClanahan_at_Sun.COM [mailto:Craig.McClanahan_at_Sun.COM]
>
> Sent: Thursday, April 30, 2009 4:37 PM
> To: users_at_jersey.dev.java.net
> Subject: Re: [Jersey] HTTP Basic Authentication (header
> encoding)
>
>
> Rabick, Mark A (IS) wrote:
>
> Does anyone have a code snippet for creating the Base64
> encoded user/password combination for a Jersey server configured for
> BASIC authentication?
>
> In the Jersey client code, is it just:
>
> nodeBaseResource.header("Authorization",
> "base64encoded_userid:password").type("application/xml").post(nodeV1);
>
> ... for a post request?
>
> Close. The header value has to be slightly different, though:
>
>
>
> nodeBaseResource.header("Authorization", "Basic " +
> "base64encoded_userid:password").type("application/xml").post(nodeV1);
>
> Craig
>
>
> --mark
> _______________________________________________
> Mark A. Rabick
> Software Engineer
> Northrop Grumman - Integrated Mission Systems
> (IS/DSD/IMS)
> 3200 Samson Way
> Bellevue, NE 68123
> Ph: (402) 293-7091
> Em: mark.rabick_at_ngc.com
> Remember PFC Ross A. McGinnis...
> http://www.army.mil/medalofhonor/McGinnis/index.html
> <http://www.army.mil/medalofhonor/McGinnis/index.html>
> ... MA2 Michael A. Monsoor, Lt. Michael P. Murphy, Cpl.
> Jason Dunham, SFC Paul Ray Smith and the rest...
> http://www.cmohs.org/recipients/most_recent.htm
> <http://www.cmohs.org/recipients/most_recent.htm>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>