To create a filter create a class that ends with the convention Filters in the grails-app/conf directory. Within this class define a code block called filters that contains the filter definitions:

class ExampleFilters {
   def filters = {
        // your filters here
   }
}

Each filter you define within the filters block has a name and a scope. The name is the method name and the scope is defined using named arguments. For example if you need to define a filter that applies to all controllers and all actions you can use wildcards:

sampleFilter(controller:'*', action:'*') {
  // interceptor definitions
}

The scope of the filter can be one of the following things:

Filter rule attributes:

Some examples of filters include:

all(controller:'*', action:'*') {

}

justBook(controller:'book', action:'*') {

}

notBook(controller:'book', invert:true) {

}

saveInActionName(action:'save', find:true) {

}

someURIs(uri:'/book/**') {

}

allURIs(uri:'/**') {

}

In addition, the order in which you define the filters dictates the order in which they are executed.