Redirect to login page not consistently redirecting

92 views
Skip to first unread message

dave

unread,
Apr 26, 2011, 1:01:54 PM4/26/11
to Lift
I'm trying to follow the examples for redirecting to the login page
when the user isn't logged in. Things are not going according to
plan.

Here's the code I have in my SiteMap:

def isLoggedIn = false // pretend this is the logic to detect
login

LiftRules.setSiteMap(new SiteMap(List({
case Full(Req(path, _, _)) if !isLoggedIn && path !=
List("login") =>
logger.debug("Redirecting to login")
Loc.EarlyResponse(() => Full(RedirectResponse("/login")))
}), entries: _*))

The first page I hit redirects to the login screen. But any other URL
I try does not redirect. That first page is stuck redirecting, even
after I've logged in. And it only prints "Redirecting to login" the
first time I hit the page.

If I use setSiteMapFunc instead of setSiteMap, and set my run.mode to
debug, then I get the behavior I expect. Now if only I can get it to
work in production :-)

I'm using Lift-2.3.

Thanks!
dave
<><

Mahmood Ali

unread,
Apr 26, 2011, 1:54:59 PM4/26/11
to lif...@googlegroups.com
Greetings,

It will help if you can present a sample runnable project that help us
debug the issue.

>      case Full(Req(path, _, _)) if !isLoggedIn && path !=
> List("login") =>

I suspect that you have a problem here. `path` is of type ParsePath
and is being compared to a `List`. The inequality check always result
true.

- Mahmood

Antonio Salazar Cardozo

unread,
Apr 26, 2011, 2:16:42 PM4/26/11
to lif...@googlegroups.com
Actually the unapply method for the Req companion object has a List[String] rather than a ParsePath (and typically an error like that will be caught by the compiler). Not sure what's *actually* happening, I'm afraid, but I highly doubt that's the problem :)
Thanks,
Antonio

dave

unread,
Apr 26, 2011, 3:04:41 PM4/26/11
to Lift
On Apr 26, 12:54 pm, Mahmood Ali <notn...@gmail.com> wrote:
> It will help if you can present a sample runnable project that help us
> debug the issue.

git clone git://github.com/leedm777/lift-sample-app.git -b login-
redirect

Patches welcome :-)

dave
<><

Mahmood Ali

unread,
Apr 26, 2011, 5:29:31 PM4/26/11
to lif...@googlegroups.com
Greetings,

Lift seems to cache the SiteMap.globalParamFuncs results in
Loc.allParams, so it gets invoked only once. However, it is better to
expression the conditional logic as the `If` LocParam rather than
doing the conditional in code.

To get it working, I changed the SiteMap initialization to:

LiftRules.setSiteMap(new SiteMap(List({ case r =>
If(() => r match {
case Full(Req(path, _, _)) if path == List("user_mgt",
"login") => true
case _ => isLoggedIn
}, RedirectResponse("/user_mgt/login"))
}), entries:_*))

Please test and report.

I suspect that this is not a bug, as SiteMap.globalParamFuncs should
partial functions generating LocParams which should encapsulate the
authentication test logic.

- Mahmod

> --
> You received this message because you are subscribed to the Google Groups "Lift" group.
> To post to this group, send email to lif...@googlegroups.com.
> To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
>
>

dave

unread,
Apr 26, 2011, 6:09:52 PM4/26/11
to Lift
On Apr 26, 4:29 pm, Mahmood Ali <notn...@gmail.com> wrote:
> Please test and report.

The result was basically the same. The only difference is that the
page you're redirected from disappears from the menu, and comes back
after login. But none of the other pages redirect to the login page.

> I suspect that this is not a bug, as SiteMap.globalParamFuncs should
> partial functions generating LocParams which should encapsulate the
> authentication test logic.

What I've got, I cribbed from a post DPP made in January (http://
groups.google.com/group/liftweb/msg/4a96e0d9dbb492cf).

Any other recommendations?

dave
<><

David Pollak

unread,
Apr 26, 2011, 6:33:10 PM4/26/11
to lif...@googlegroups.com
Yeah... it looks like Loc is being too eager about caching its params.  Please open a ticket (http://ticket.liftweb.net you must be a watcher of the LiftWeb space on Assembla) and reference this thread.


dave
<><

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.




--
Lift, the simply functional web framework http://liftweb.net

dave

unread,
Apr 26, 2011, 10:04:44 PM4/26/11
to Lift
On Apr 26, 5:33 pm, David Pollak <feeder.of.the.be...@gmail.com>
wrote:
> Yeah... it looks like Loc is being too eager about caching its params.
> Please open a ticket (http://ticket.liftweb.netyou must be a watcher of the
> LiftWeb space on Assembla) and reference this thread.

Done. Ticket #993

https://www.assembla.com/spaces/liftweb/tickets/993-sitemap-redirects-not-consistently-redirecting

Thanks!
dave
<><
Reply all
Reply to author
Forward
0 new messages