The following Groovy code will print βI'm filtering!β:
class SecurityFilters { def filters = { myFilter(controller:'*', action:'*') {
In this example, filters are a closure that calls a method called myFilter and passes the map and closure. You can think of myFilter as:
myFilter([controller:'*', action:'*'], closure)
A map may contain keys, such as a controller, action, or uri. The wildcard character (*) is used when Grails tries to match a URI with an HTTP request, when it tries to determine which closure to call.
My understanding of how Grails handles filters is that it uses the delegate loader class. The loader class provides a methodMissing method and creates a FilterConfig for each method call inside filter closures. When the HTTP request is executed, Grails scans all FilterConfig objects and tries to find the appropriate area (looks on the map for the controller, action or uri and uses regular expressions to match wildcards). If it finds a match, it causes a closure that was passed to the method in the Filter class.
John wagenleitner
source share