You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Felix Meschberger <fm...@gmail.com> on 2010/09/09 15:41:58 UTC
[DISCUSS] Handling of expired form authentication cookies
Hi all,
When a request is posted with an expired cookie for the form
authentication handler, there are basically two options to continue with
: (1) continue with the request as if no cookie was provided or (2) fail
authentication and request username/password again. Default is the first
behaviour which may be changed by configuration.
This all works fine in a plain browser-based environment. As soon as
applications send requests with the cookie or AJAX frameworks send XHR
requests with the cookie, this does not really work properly:
Continuning as anonymous might cause unexpected reactions while handling
the request and sending the login form (or redirecting to the login
form) may also not be desired.
Since most (if not all) Ajax frameworks (at least JQuery and ExtJS do)
send an "X-Requested-With" set to "XMLHttpRequest" we could make use of
this as follows:
if (cookie is expired) {
if ("XMLHttpRequest".equals(
request.getHeader("X-Requested-With"))) {
// signal to AJAX the request is forbidden
send(403/FORBIDDEN)
return DOING_AUTH;
} else if (doForm) {
// config requested to be logged in again
return FAIL_AUTH;
} else {
// default, check next auth handler (or anon)
return null;
}
}
WDYT ?
Regards
Felix
Re: [DISCUSS] Handling of expired form authentication cookies
Posted by Felix Meschberger <fm...@gmail.com>.
Hi,
On 09.09.2010 20:49, Justin Edelson wrote:
> On 9/9/10 10:59 AM, Felix Meschberger wrote:
>> Hi,
>>
>> On 09.09.2010 15:41, Felix Meschberger wrote:
>>> Since most (if not all) Ajax frameworks (at least JQuery and ExtJS do)
>>> send an "X-Requested-With" set to "XMLHttpRequest" we could make use of
>>> this as follows:
>>>
>>> if (cookie is expired) {
>>> if ("XMLHttpRequest".equals(
>>> request.getHeader("X-Requested-With"))) {
>>> // signal to AJAX the request is forbidden
>>> send(403/FORBIDDEN)
>>> return DOING_AUTH;
>>
>> Hmm, 408/REQUEST TIMEOUT might be better ...
>>
>> Regards
>> Felix
>
> How about 412/PRECONDITION FAILED? 408 doesn't seem like a good semantic
> fit (the cookie has timed out, not the request). 412 isn't quite right
> either (the client is the one who is supposed to establish the
> preconditions), but it's closer IMHO.
>
> Alternatively, 403 with a X-Reason header containing "timeout" or
> "expired" or something like that.
Sounds like the best option, we could infact provide the string value of
the appropriate FormReason enum.
>
> Or we could use my favorite response code, 402 :)
Oh yeah ! Good idea ;-)
Regards
Felix
>
> Justin
>
Re: [DISCUSS] Handling of expired form authentication cookies
Posted by Justin Edelson <ju...@gmail.com>.
On 9/9/10 10:59 AM, Felix Meschberger wrote:
> Hi,
>
> On 09.09.2010 15:41, Felix Meschberger wrote:
>> Since most (if not all) Ajax frameworks (at least JQuery and ExtJS do)
>> send an "X-Requested-With" set to "XMLHttpRequest" we could make use of
>> this as follows:
>>
>> if (cookie is expired) {
>> if ("XMLHttpRequest".equals(
>> request.getHeader("X-Requested-With"))) {
>> // signal to AJAX the request is forbidden
>> send(403/FORBIDDEN)
>> return DOING_AUTH;
>
> Hmm, 408/REQUEST TIMEOUT might be better ...
>
> Regards
> Felix
How about 412/PRECONDITION FAILED? 408 doesn't seem like a good semantic
fit (the cookie has timed out, not the request). 412 isn't quite right
either (the client is the one who is supposed to establish the
preconditions), but it's closer IMHO.
Alternatively, 403 with a X-Reason header containing "timeout" or
"expired" or something like that.
Or we could use my favorite response code, 402 :)
Justin
Re: [DISCUSS] Handling of expired form authentication cookies
Posted by Felix Meschberger <fm...@gmail.com>.
Hi,
On 09.09.2010 15:41, Felix Meschberger wrote:
> Since most (if not all) Ajax frameworks (at least JQuery and ExtJS do)
> send an "X-Requested-With" set to "XMLHttpRequest" we could make use of
> this as follows:
>
> if (cookie is expired) {
> if ("XMLHttpRequest".equals(
> request.getHeader("X-Requested-With"))) {
> // signal to AJAX the request is forbidden
> send(403/FORBIDDEN)
> return DOING_AUTH;
Hmm, 408/REQUEST TIMEOUT might be better ...
Regards
Felix