Hello Andrew,

I send you a sample test code based on the code that you mentionned (
http://wiki.restlet.org/docs_2.1/112-restlet.html), except that it uses
directly a Server connector instead of a Component. It works for me using
the 2.1 snapshot.
public static void main(String[] args) throws Exception {
   Server server = new Server(Protocol.HTTP, 8182);
   // Guard the restlet with BASIC authentication.
   ChallengeAuthenticator guard = new ChallengeAuthenticator(null,
ChallengeScheme.HTTP_BASIC, "testRealm");
   // Instantiates a Verifier of identifier/secret couples based on a
simple Map.
   MapVerifier mapVerifier = new MapVerifier();
   // Load a single static login/secret pair.
   mapVerifier.getLocalSecrets().put("login", "secret".toCharArray());
   guard.setVerifier(mapVerifier);

   guard.setNext(new Restlet() {
       @Override
       public void handle(Request request, Response response) {
           response.setEntity("hello, world", MediaType.TEXT_PLAIN);
       }
   });
   server.setNext(guard);
   server.start();
}

I hope this will help you.

Best regards,
Thierry Boileau


Hello,
>
> This is a rather simple question about authentication from the server-side
> point of view.  It's been awhile since I've used Restlet, so it may be
> something that would have been obvious before.
>
> I've been reading through some info about it at
> http://wiki.restlet.org/docs_2.1/13-restlet/27-restlet/46-restlet/112-restlet.html.
>  For now, I'm just looking at basic HTTP auth.
>
> Seemed simple enough.  I copied the code snippets and through it into a
> test app.  Outside of what's on that web page, I created a Server object
> and passed in the Restlet object.  One thing  noticed was that Restlet
> doesn't have a getDefaultHost() method, so instead of creating a Restlet
> object, I created a Component object.  It derives from Restlet, so I didn't
> think there would be an issue.  Everything else is exactly the same.
>
> I fired up my test app and used FireFox as my "client".  I get the hello
> world response, but I'm not required to authenticate.
>
> What could I be missing?  It seems simple, but it's not working for me.
>  *scratches head*
>
> Thanks,
> Andrew
>
>

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2891318

Reply via email to