I do see an Authorization header:

DEBUG  - org.restlet.http.headers:[Accept: */*, Authorization: Basic 
aGFyYm9yOmhhcmJvcg==, Host: localhost:28080, User-Agent: 
Noelios-Restlet-Engine/1.1..1]





________________________________
From: John Prystash <[email protected]>
To: [email protected]
Sent: Monday, January 26, 2009 5:12:54 PM
Subject: Re: [restlet-user] Retrieving Credentials sent by HttpClient


To follow-up some more...
I tried using the Restlet Client code provided by the example in the tutorial 
(http://www.restlet.org/documentation/1.1/tutorial#part09) and went back to 
using my Guard extension.  In short, the ChallengeResponse() appears to always 
be null when coming through the Mule Restlet Transport (unless of course I'm 
missing something).

    @Override
    public int authenticate(Request request) {
        ChallengeResponse cr = request.getChallengeResponse();
        if (cr == null) {
            logger.debug("ChallengeResponse is NULL");
        }
        ...
    }

Iterating through getSecrets() above gives me the Secrets I set up in my 
Application class.  Also, getScheme() returns HTTP_BASIC.

Could I possibly be missing a step that invokes the ChallengeResponse from the 
client?  My relevant client code:

    Client client = new Client(Protocol.HTTP)
    Request request = new Request(Method.GET, uri)

    ChallengeScheme scheme = ChallengeScheme.HTTP_BASIC
    ChallengeResponse authentication = new ChallengeResponse(scheme, username, 
password)
    request.setChallengeResponse(authentication)

    Response response = client.handle(request)


Sorry to keep pinging here, but I'm running out of ideas :)


________________________________
From: John Prystash <[email protected]>
To: [email protected]
Sent: Monday, January 26, 2009 10:47:01 AM
Subject: Re: [restlet-user] Retrieving Credentials sent by HttpClient


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=1056266

Reply via email to