开发者

Spring Security: autowire ProviderManager

I am trying to programatically validate a user login/pass using Spring Security, so I need to have access to the ProviderManager. I would like it to be automatically injected into my @Controller.

My code looks like:

import org.springframework.security.authentication.ProviderManager;

// ...

@Controller
public class MyController {

    @Autowired
    private ProviderManager authenticationManager;

But when I try to run the application I get this error message:

No unique bean of type [org.springframework.security.authentication.ProviderManager] is defined: 
expected single matching bean but found 2: 
[org.springframework.security.authentication.ProviderManager#0, org.springframework.security.authenticationManager]

What could be the cause or how could I solve it?

I am using Spring Security 3.0.0-RC1 with Spring 3.0.1, and I've not defined any ProviderManager bean. I've successfully used:开发者_如何学Python

@Resource
private ProviderManager authenticationManager;

in other projects, but javax.annotation.Resource is not supported in GAE.


There are two AuthenticationManagers in the context:

  • org.springframework.security.authenticationManager is populated with authentication providers explicitly declared in <authentication-manager>
  • org.springframework.security.authentication.ProviderManager#0 is populated with implicitly declared providers (remember me, anonymous and so on) and delegates the authentication request to org.springframework.security.authenticationManager as a fallback.

So, I guess you need

@Autowired @Qualifier("org.springframework.security.authenticationManager")


The error message goes away including an alias for the authentication-manager:

<sec:authentication-manager alias="authenticationManager">

and upgrading to Spring Security 3.0.0 finale.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜