5

I have a filter that i want to filter every action except ONE that brings me to login page.
If i filter all pages with some condition then even the LOGIN page too get filtered and so it stuck in infinte loop as condition not fulfilled (User not Logged IN). session.getAttribute("CurrentEmployeeIds") it tell whether user is logged in or not


My filter here:

class LoginFilters {

    def filters = {
        all(controller:'dashboard', action:'*') {
            before = {
                if (session.getAttribute("CurrentEmployeeIds")==null) {
                    redirect(controller:"site",action:"index")
                    return false
                }
            }
            after = { Map model ->

            }
            afterView = { Exception e ->

            }
        }
    }
}

I want to filter in such a way that it don't filter controller:"site",action:"index" this url and filter everything else.
thanks in advance.

dmahapatro
  • 49,365
  • 7
  • 88
  • 117
Sachin Verma
  • 3,712
  • 10
  • 41
  • 74
  • 1
    You can get the action and controller name by `actionName` and `controllerName`, just do a check on, simple `if` statement. you can return `true` for that specific action. – Alidad Sep 25 '13 at 13:25
  • 1
    How is this related to Struts 2? – Dave Newton Sep 25 '13 at 14:23

1 Answers1

12

You can invert filter rule, like:

def filters = {
    allExceptIndex(controller:"site",action:"index",invert:true) {
        before = {
        }
        after = { Map model ->
        }
        afterView = { Exception e ->
        }
    }
}

See docs http://grails.org/doc/latest/guide/theWebLayer.html#filters

harryovers
  • 3,087
  • 2
  • 34
  • 56
Igor Artamonov
  • 35,450
  • 10
  • 82
  • 113