views:

114

answers:

1

Does anyone know why when I try to create an advice around the "doAuthentication" method of the Spring Security (v3.0) ProviderManager my application throws an exception on startup?

I am autowiring an instance of my spring authentication-manager bean into a controller and when the autowire is attempted my app fails to deploy.

Here is what my security context xml looks like...

...<authentication-manager alias="authenticationManager"> ...

Here is the pertinent part of my controller...

@Autowired
private ProviderManager authenticationManager;

and here is my advice declaration:

@After("execution(* org.springframework.security.authentication.ProviderManager.doAuthentication(..)) && args(authentication)")

Any help will be greatly appreciated!

+1  A: 

I'm not sure from the available information, but I'm guessing that you're using Spring AOP, which uses JDK dynamic proxies by default, so you are coming across the usual problem that the proxy does not retain the type of the original class (ProviderManager). The proxy will implement the interface AuthenticationManager, however. Try autowiring using this type and see if it works. Either that or you can enable class proxying which uses cglib instead of dynamic proxies. If you're using the Spring AOP namespace, you can set the proxy-target-class attribute to true.

Munkymisheen
Thanks, I think I missed that part in the spring docs. I appreciate your help.
El Guapo