views:

31

answers:

2

Hello,

I have a Spring 3 application with Spring Security. I need to do some proccessing in almost all the urls of my application. The proccesing is different depending on the user which is logged-in. I had though of doing it by using a Spring filter but I cannot access

SecurityContextHolder.getContext().getAuthentication().getPrincipal()

in the filter because SecurityContextHolder is still null.

What is the best way to do this?

thanks.

+1  A: 

To access the security context, your filter should be behind the Spring Security filter, i.e. its <filter-mapping> should be placed after the Spring Security's one.

axtavt
+1  A: 

If you are using spring, you can do it inside "interceptor". It spring's alternative to filters, and it have access to security context.

splix