I have the following scenario:
Server: Jetty (with configured JAAS)
Client: Jersey invoked via JUnit (via Maven)
I have JAAS set up in the web server. I am using the client part as a test.
On the server side users are authenticated through a form with Basic authentication handled via JAAS. Obviously, users need to be authenticated before being able to view certain pages.
I would like to be able to login via the Jersey before trying to access a secured page. How can this be done? I have checked that you can define a filter, but I'm not quite sure how to use that. And -- once the user is logged in via the form, how can I proceed (from the client-side) to the page I'm actually interested in?
I would really appreciate it, if somebody could show me an example how this is done on the client side with Jersey.
I have the following JUnit test case method:
@Test
public void testLogin()
throws IOException
{
String URL_LOGIN = "http://localhost:9080/foo/auth.html";
Client client = Client.create();
String username = "me";
String password = "me";
final HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter(username, password);
client.addFilter(authFilter);
client.addFilter(new LoggingFilter());
WebResource webResource = client.resource(URL_LOGIN);
// I even tried:
// webResource.header("Authorization", "Basic " + "base64encoded_userid:password").type("application/xml");
String page = webResource.post(String.class);
System.out.println(page);
}
Please, note:
1) http://localhost:9080/foo/auth.html is the page I am supposed to be seeing upon successful auth.
2) I am actually seeing the output of http://localhost:9080/foo/login.html.
3) Obviously, through a browser, I can successfully login via the login.html page.
What do I seem to be missing out here?