Hi all,
Finally I got it work. As I guessed, it is very simple to setup. The restlet
is a great framework which is always easy to setup. We don't need to do
anything for loginPath. It will be automatically taken care by
CookieAuthenticator. I stuck to setup, because of a small
usability/understanding issue. The LoginFormPath also trying for
authentication. It should be skip by default. Because of this my browser
became unresponsive because of infinite loop.
I suggest, the default implementation of beforeHandle() method of
CookieAuthenticator might be as below,
protected int beforeHandle(Request request, Response response) {
* if
(request.getResourceRef().getRemainingPart().equals(getLoginFormPath())) {
return CONTINUE;
}else {*
if (isLoggingIn(request, response)) {
login(request, response);
} else if (isLoggingOut(request, response)) {
return logout(request, response);
}
return super.beforeHandle(request, response);
}
*}*
Below are the working code of my application:
1. PTCookieAuthenticator.java
public class PTCookieAuthenticator extends CookieAuthenticator {
public PTCookieAuthenticator(Context context) {
super(context, "realm-text", "my_16_bytes_text".getBytes());
}
@Override
protected int beforeHandle(Request request, Response response) {
if
(request.getResourceRef().getRemainingPart().startsWith("/loginForm"))
{
return CONTINUE;
} else {
return super.beforeHandle(request, response);
}
}
}
2. RestletService.java
public class RestletService extends Application {
...
public Restlet createInboundRoot() {
....
router.attach("/loginForm", LoginForm.class);
PTCookieAuthenticator cookieAuth=new
PTCookieAuthenticator(getContext());
cookieAuth.setLoginFormPath("/loginForm");
....
}
The Pieter Martin suggested every thing, but changing the
loginPath("/rest/special/loginPost") made me confusion. I thought I should
do something in the post method.
Thanks,
Ramesh
--
View this message in context:
http://restlet-discuss.1400322.n2.nabble.com/How-to-use-CookieAuthenticator-tp7578835p7579062.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3072942