我們已經從3.0.7 spring security遷移到3.1.2,並且我們的一個使用in-memory-config的測試在錯誤憑證上失敗。BadCredentialsException從Spring 3.0.x遷移到3.1.x時
我們不做任何特殊的事情,只需用純文本用戶名和密碼驗證其中一個用戶即可。一旦通過認證,我們就會填充我們的權限。
代碼:
public Authentication authenticate(UserDetails userDetails)
throws AuthenticationException {
try {
org.springframework.security.core.Authentication authenticate = authenticationManager.authenticate(createAuthenticationRequest(userDetails));
if (!authenticate.isAuthenticated()) {
throw new AuthenticationException("Authentication failed for user ["+userDetails.getUsername()+"]");
}
Collection<? extends GrantedAuthority> grantedAuthorities = authenticate.getAuthorities();
...
} catch(Exception exception) {
throw new AuthenticationException(exception);
}
代碼:
<bean id="daoAuthenticationProvider"
class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<property name="userDetailsService" ref="daoUserDetailsService" />
</bean>
<bean id="daoUserDetailsService" class="org.springframework.security.core.userdetails.memory.InMemoryDaoImpl">
<property name="userMap">
<value>
Edward = koala, READ_ONLY
</value>
</property>
</bean>
我們得到一個調用以下異常驗證:
Caused by: org.springframework.security.authentication.BadCre dentialsException: Bad credentials
at org.springframework.security.authentication.dao.Da oAuthenticationProvider.additionalAuthenticationCh ecks(DaoAuthenticationProvider.java:67)
at org.springframework.security.authentication.dao.Ab stractUserDetailsAuthenticationProvider.authentica te(AbstractUserDetailsAuthenticationProvider.java: 149)
at org.springframework.security.authentication.Provid erManager.authenticate(ProviderManager.java:156)
at org.openspaces.security.spring.SpringSecurityManag er.authenticate(SpringSecurityManager.java:117)
... 11 more
任何想法如何解決它或如果有補丁等待解決這個問題?
謝謝,但它似乎不是問題。 當按照建議進行調試時,我看到以下內容: AbstractUserDetailsAuthenticationProvider 126:UserDetails user = this.userCache.getUserFromCache(username); 返回一個UserDetails,其密碼設置爲空... – 2012-08-16 20:40:23
您是否使用名稱空間嘗試它?如果沒有,那麼這聽起來像你可能看到[這裏描述的問題](https://jira.springsource.org/browse/SEC-1952)。 – 2012-08-17 21:34:45
我嘗試過使用命名空間和類似的結果... – 2012-08-18 19:57:04