users@jersey.java.net

Re: [Jersey] Jersey Client and Basic Authentication

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Wed, 20 Aug 2008 09:58:48 -0400

Try adding the following to your code before you use the client API:

final String username ="...";
final String password ="...";
Authenticator.setDefault(new Authenticator() {
  protected PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication (username,
password.toCharArray());
  }
});

HTH,
Marc.

On Aug 20, 2008, at 6:45 AM, Mike Jones wrote:

> Hello
>
> I'm using Jersey with Spring security and I'm in the process of
> creating some tests that use embedded Jetty and the Jersey client. I
> need to perform some basic authentication with the client - do I need
> to encode the credentials in Base64 myself and add them to the headers
> in the jersey client? Am I missing some nice (and probably obvious)
> helper methods for this?
>
> Cheers
> Mike
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.