To follow-up, I tried following the example found in the tutorial and let the
standard Guard class handle the authentication
(http://www.restlet.org/documentation/1.1/tutorial#part09).
In my Application extension:
Guard guard = new Guard(getContext(),
ChallengeScheme.HTTP_BASIC, REALM);
guard.getSecrets().put("john",
"john".toCharArray());
guard.setNext(MyResource.class);
In my client, I set the credentials as before:
def credentials = new UsernamePasswordCredentials("john", "john")
And I get a 401. So with this simpler approach where Guard.authenticate() is
being invoked, the credentials from HttpClient do not seem to get noticed:
Credentials:
Username: harbor
Password: harbor
Response received.
Status: 401
Response Body:
<html>
<head>
<title>Status page</title>
</head>
<body>
<h3>The request requires user
authentication</h3><p>You can get technical details <a
href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.2">here</a>.<br>
Please continue your visit at our <a
href="/">home page</a>.
</p>
</body>
</html>
________________________________
From: John Prystash <[email protected]>
To: [email protected]
Sent: Sunday, January 25, 2009 5:40:06 PM
Subject: [restlet-user] Retrieving Credentials sent by HttpClient
Hi, I'm trying to retrieve the credentials set in by HttpClient in my Restlet
service.
I'm using Mule 2.0.2 with 1.1.3 of the Mule Restlet Transport (uses Restlet
1.1.1).
In my Guard class, request.getChallengeResponse() is return null.
My Guard extension:
public class MyGuard extends Guard {
@Override
public int authenticate(Request request) {
...
ChallengeResponse cr = request.getChallengeResponse(); // is null
here
...
}
}
My Application class:
public class MyApplication extends Application {
@Override
public Restlet createRoot() {
Guard guard = new MyGuard(getContext(), ChallengeScheme.HTTP_BASIC,
"someRealm");
guard.setNext(MyResource.class);
...
}
}
I'm using HttpClient 3.1 (with Groovy) as my users will be:
def client = new HttpClient()
def httpMethod = new GetMethod(uri)
def authScope = new AuthScope(null, -1, "someRealm")
def credentials = new UsernamePasswordCredentials(username, password)
client.getState().setCredentials(authScope, credentials);
// these lines print out what I expect
println "Username: " +
client.getState().getCredentials(authScope).getUserName()
println "Password: " +
client.getState().getCredentials(authScope).getPassword()
httpMethod.setDoAuthentication(true)
statusCode = client.executeMethod(httpMethod);
I found a similar posting here:
http://markmail.org/message/6n7hjc3pmbg7vcg5#query:restlet%20httpclient%20credentials+page:1+mid:5y3ldjbvcvwxaysp+state:results
Thanks for advance for any insight.
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1055067