Grails Filters vs Interceptor

grails

Solution

Use one or both interceptors in a controller when the interception logic only applies to that controller.

Use a filter when the logic applies to multiple (or all) controllers, or when you need to do something after the view is rendered (there's no interceptor equivalent of afterView), or if you just want to keep everything centralized in one place instead of spread across separate controller files.

Problem

I have been studying Grails for quite a while now. And scanned a little bit about Filters and Interceptors. Both have almost the same functionality of tracking the sessions or redirecting unauthorized users in a particular controller. But I'm confused when and why should I use Filter than Interceptor and vice versa. Given that the Inceptors have two controller methods `beforeInterceptor` and `afterInterceptor` and for the Filters a three common closures `before`, `after` and `afterView`. My questions is what are the pros and cons of using Filter against Interceptor or vise versa. In this manner we, developers, can decide when, where, and why we should use either Filter or Interceptor in a particular Controller to do some tracking, redirect, etc.

Original source