項目中配置了Spring Security,經過自定義的UserDetailsService實現loadUserByName方法可以查出用戶的信息,在繼續運行至DaoAuthorityXXX時,在UsernamePasswordToken時,報出Bad Principal異常,檢查以後是由於 在security 配置中spring
配置了數據庫
<s:authentication-manager alias="authenticationManager">ide
<s:authentication-provider user-service-ref="userDetailsService">加密
<s:password-encoder hash="md5" />spa
</s:authentication-provider>code
</s:authentication-manager>ip
數據庫中的密碼沒有加密,因此springsecurity在比較用戶輸入的用戶名,密碼時,密碼不一致拋出 Bad Principal Exceptionmd5
解決方法:ci
更改:<s:password-encoder hash="md5" /> 爲 <s:password-encoder hash="plaintext" />,即沒有加密處理。hash