I'm trying to understand why some code is written the way it is.
Here is some code from my AuthenticationProvider:
So, every time an authentication attempt is made, a check is made to see if the userDao is an AopProxy, and if not it loads it again from the the application context.Code:private boolean isProxy; private UserDao userDao; ... public Authentication authenticate(final Authentication authentication) { if (!this.isProxy) { this.updateUserDao() } ...normal authenticate() code... } private final synchronized void updateUserDao() { if (!AopUtils.isAopProxy(this.userDao)) { this.userDao = (UserDao) this.applicationContext.getBean("userDao"); this.isProxy = AopUtils.isAopProxy(this.userDao); } else { this.isProxy = true; } }
When I set break points in the code, initially this.userDao is not an Aop proxy, but after the call to this.applicationContext.getBean("userDao"), it is.
I'm using some version of Spring 2 (most likely 2.5.6). Can anyone tell me why code like this might be needed? This is the only place in the entire code base which does something like this.
Also, isn't there a better method/place to do this? (I'm sure the authentication provider was chosen because it's guaranteed to be called soon after the app starts up.)


Reply With Quote
