项目中配置了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