10
A simple solution is to extend a base controller for all of your controllers and have the @Before in the base controller.
The other option (and the better solution, as it is more flexible) is to use the @With annotation. The example on the play documentation is
Example:
public class Secure extends Controller {
@Before
static void checkAuthenticated() {
if(!session.containsKey("user")) {
unAuthorized();
}
}
}
And on another Controller:
@With(Secure.class)
public class Admin extends Application {
...
}
This means the Admin controller will process all the interceptors (@Before, @After, @Finally) contained within the Secure controller.