Mar 22nd, 2007, 12:04 PM
Getting Session in AOP beforeAdvice methodI
I need to develop a service which can authenticate user if he is already logged in before going to any other page. I am setting an attribute in session for this once the user is logged in.
My question is, is there any way I can get Session object in beforeAdvice method of Spring AOP, so that I can access attribute for authentication.
any reply much appreciated.
Mar 24th, 2007, 06:30 AM
I would implement this with a ServletFilter, this way you have access to all the stuff in the request and session. Use the DelegatingFilterProxy so that you can configure your Filter as a normal Spring bean.
If you really need to or want to implement it as an Aspect I would also suggest that you define a filter. That filter will put the desired parameter in a ThreadLocal, that way you can retrieve the proper value from inside the Aspect.