I found an example of simple grails auth where a beforeInterceptor is used in a controller to redirect users out if they are not logged in. it looks like this:
def beforeInterceptor = [action:this.&checkUser,except:['login']]
def checkUser() {
if(!session.user) {
redirect(controller:'home')
return false
}
}
This is all well and good if you only have one controller that you must secure. what happens when you have more then one? I cant put the checkUser method into a service because a service cannot redirect, and probably doesnt have the session object. Please help
you would want to use a grails filters, http://grails.org/doc/latest/ref/Plug-ins/filters.html
but I would strongly suggest you look into Grails Spring Security instead
Grails Filters ought to do the trick. The linked page has an example of using a filter for authentication.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With