Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grails: reusable authentication interceptor

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

like image 629
mkoryak Avatar asked May 27 '26 01:05

mkoryak


2 Answers

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

like image 65
Aaron Saunders Avatar answered May 28 '26 14:05

Aaron Saunders


Grails Filters ought to do the trick. The linked page has an example of using a filter for authentication.

like image 41
ig0774 Avatar answered May 28 '26 15:05

ig0774



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!