smeeb
smeeb

Reputation: 29477

Grails 2.4 filters don't seem to be working

I have a Grails 2.4.4 app. In it I have the following controllers:

myapp/
    grails-app/
        controllers/
            fizzbuzz/
                FizzController.groovy
                BuzzController.groovy
                ... many others, etc.

I want to create Grails Filters for some of these, so I create a grails-app/conf/WidgetFilters.groovy class:

class WidgetFilters {
    def filters = {
        fizzFilter(controller: 'fizz*', action: '*') {
            before = {
                println 'I intercepted a called to the Fizz Controller!'  
            }
        }  
        buzzFilter(controller: 'buzz*', action: '*') {
            before = {
                println 'I intercepted a called to the Buzz Controller!'  
            }
        }
    }
}

When I start my app up and go to any Fizz/Buzz actions, I do not see the println. I've also tried other logging statements (SLF4J) and put other code inside the before closure and am 100% convinced they are not executing. Have I done something obviously wrong?

Upvotes: 3

Views: 413

Answers (2)

Michal_Szulc
Michal_Szulc

Reputation: 4177

Did you tried to restart app + clean build?

I've copy-pasted your filters and mock controllers and they're working, here is a code.

Please check out also this properties:

  • apf.continueChainBefore SuccessfulAuthentication - whether to continue calling subsequent filters in the filter chain
  • fii.observeOncePerRequest - If false allow checks to happen multiple times, for example when JSP forwards are being used and filter security is desired on each included fragment of the HTTP request

Upvotes: 2

Burt Beckwith
Burt Beckwith

Reputation: 75671

Move the class into grails-app/conf.

Upvotes: 1

Related Questions