我想實現下面的春季自動登錄,但我的身份驗證管理器實例拋出下面的異常,而不是自動裝配。我如何從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