views:

53

answers:

1

Hi all, in my Grails app I have a couple of simple security filters (please note it's just a prototype, not a commercial app:

securityCheckFilter(controller:'overview', invert:true) {
            before = {
                if(!session?.gaSession?.gaUser) {
                    flash.message = "You are not authorised to see this page. Please login."
                    redirect(controller:'overview',action:'login')
                    return false
                }
                return true
            }
        }

Which means that, apart from the controller 'overview' that handles the login/registration, all the other controllers require authentication. The problem is that I'd like to implement this typical flow:

(1) user tries protected url (2) redirection to login (3) successful login (4) redirection to url

In my code it works until point 3, but I'm missing 4.

Any hints?

A: 

It's actually quite easy. Just

  • submit the target URI (from point 1 in your question) as a parameter to the login action/view
  • make sure your login form forwards this parameter to the authentication action (eg. via a hidden field)
  • in the authentication action, if the login was successful, just redirect to this URI

To get the target URI (in your filter), just remove the context path from the forward URI:

def targetURI = request.forwardURI - request.contextPath
Daniel Rinser
thanks a million!
Mulone