What's new? | Help | Directory | Sign in
Google
                
Search
for
Updated Jan 04, 2007 by thr4sh
AerieFilters  
Aerie Filters

UserGuide

Aerie Filters live in aerie-webapp/src/filters and their respective tests live in aerie-webapp/test/filters.

Filters must implement the aerie.filter.Filter interface.

aerie-webapp/src/filters/Authentication.groovy :

import aerie.filter.Filter

class Authentication implements Filter {

  void applyTo(controller) {
    if ( controller.action == "login" && controller.name == "Welcome" ) return
    if ( controller.session.userId == null ) controller.redirect("/welcome/login")
  }
}

The Controller is available to the Filter in its pre-execution state. Any changes applied to the Controller by any Filters will be present when the Controller executes. A Filter has full access to the public Controller API.

Of course, we should be really Test Driving our filter.

Context wide Filters

A Filter can be applied to all the Controllers under a Context.

aerie-webapp/src/contexts/SomeContext.groovy :

import aerie.context.AerieContext

class SomeContext extends AerieContext {

  def SomeContext() {
    filters = ["Authentication"]
  }

}

Controller wide Filters

A Filter can be applied to all the Actions of a Controller.

aerie-webapp/src/controllers/SomeController.groovy :

import aerie.controller.Controller

class SomeController extends Controller {

  def SomeController() {
    filterWith("Authentication")
  }

}

Sign in to add a comment