我想实现下面的春季自动登录,但我的身份验证管理器实例抛出下面的异常,而不是自动装配。我如何从Spring手动获取它的实例?我没有使用弹簧控制器,我使用JSF请求作用域bean。在容器尝试自动装载authenticationManager时,我在运行时遇到以下异常。 requestCache正常。我应该在UserDetailsService实现(userManager)上使用方法吗?我没有看到由UserDetailsService公开的采用UsernamePasswordAuthenticationToken objet的适当方法。有任何想法吗? 配置:春季自动登录问题
<http access-denied-page="/auth/denied.html">
<intercept-url
pattern="/**/*.xhtml"
access="ROLE_NONE_GETS_ACCESS" />
<intercept-url
pattern="/auth/**"
access="ROLE_ANONYMOUS,ROLE_USER" />
<intercept-url
pattern="/auth/*"
access="ROLE_ANONYMOUS" />
<intercept-url
pattern="/registered/*"
access="ROLE_USER" />
<intercept-url
pattern="/*"
access="ROLE_ANONYMOUS" />
<form-login
login-processing-url="/j_spring_security_check.html"
login-page="/auth/login.html"
default-target-url="/registered/home.html"
authentication-failure-url="/auth/login.html" />
<logout invalidate-session="true"
logout-success-url="/"
logout-url="/auth/logout.html"/>
<anonymous username="guest" granted-authority="ROLE_ANONYMOUS"/>
<remember-me user-service-ref="userManager" key="e37f4b31-0c45-11dd-bd0b-0800200c9a66"/>
</http>
<!-- Configure the authentication provider -->
<authentication-manager alias="am">
<authentication-provider user-service-ref="userManager">
<password-encoder ref="passwordEncoder" />
</authentication-provider>
</authentication-manager>
异常 注射自动装配依赖的失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装入字段:protected org.springframework.security.authentication.AuthenticationManager com.dc.web.actions.SignUpDetail.authenticationManager;嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有定义[org.springframework.security.authentication.AuthenticationManager]类型的唯一bean:期望单个匹配的bean,但找到2:[org.springframework.security.authentication.ProviderManager #0,org.springframework.security.authenticationManager] javax.faces.webapp.FacesServlet.service(FacesServlet.java:325)
@Named
@Scope( “请求”) 公共类注册 {
@Inject
RequestCache requestCache;
@Inject
protected AuthenticationManager authenticationManager;
public String login(){
authenticateUserAndSetSession(utilities.getLoggedInUser(), (HttpServletRequest) FacesUtils.getExternalContext().getRequest());
return "/home.html";
}
private void authenticateUserAndSetSession(Users user,
HttpServletRequest request)
{
UserDetails details = userManager.loadUserByUsername(user.getUsername());
UsernamePasswordAuthenticationToken usernameAndPassword =
new UsernamePasswordAuthenticationToken(
user.getUsername(), "pwd", details.getAuthorities());
// Authenticate, just to be sure
Authentication auth = authenticationManager.authenticate(usernameAndPassword);
// Place the new Authentication object in the security context.
SecurityContextHolder.getContext().setAuthentication(auth);
}
根据例外情况,您有两个身份验证管理器。你需要告诉Autowire你想使用哪一个 – Anon 2011-03-24 11:40:50