views:

20

answers:

1

Say a logged in user hits the url:

www.example.com/forum/234

Before the spring mvc action fires, I want to load the User Object, the user's permission, the Forum object.

Now I want to share these objects accross this request. So other classes can look to see, in the current request, for a User, Permission and Forum object.

Potentially it would be cool if a custom freemarker module could also reference these objects if they are available.

is this possible?

+1  A: 

First, consider using spring-security, whose filters do everything you need.

If you want to do all by hand, then you have at least two options: - use servlet filters - use spring handler interceptor (http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-handlermapping-interceptor).

In both cases store this data in request attributes. Remember about cleaning them up after request processing!

Another option is to create bean with request scope which will store your data.

As for Freemarker, you must provide own subclass of FreemarkerViewResolver, which will return subclass of FreeMarkerView in requiredViewClass() method. Add your objects in exposeHelpers() method in this FreeMarkerView subclass.

Bartek Jablonski