编辑:这个问题原来是用户错误,密码已更改,因此哈希永远不会匹配
我在 Spring 4.2.2 的工具包中使用了一个简单的身份验证,使用一个读取用户名、密码和权限的(Postgres)数据库表的 DAO
@EnableWebSecurity
@Configuration
class X extends WebSecurityConfigurerAdapter{
...
@Autowired
private SessionRegistry sessionRegistry;
@Autowired
private SessionAuthenticationStrategy sessionAuthenticationStrategy;
@Override
protected void configure(HttpSecurity http){
http.sessionManagement().sessionAuthenticationStrategy(sessionAuthenticationStrategy).maximumSessions(1).sessionRegistry(sessionRegistry).expiredUrl("/login.jsp");
//presumably unrelated additional code related to matchers, roles, https
}
@Bean
public SessionRegistry sessionRegistry(){
return new SessionRegistryImpl();
}
@Bean
public SessionAuthenticationStrategy sessionAuthenticationStrategy(){
return new ConcurrentSessionControlAuthenticationStrategy(sessionRegistry);
}
@Bean
public PasswordEncoder passwordEncoder(){
return new StandardPasswordEncoder();
}
...
}
最近我恢复了一个旧的数据库副本,旧的数据库来自 Redhat 6 服务器,新的是 CentOS 7,虽然实际上这都是数据库支持的,所以应该没关系。我们代码的身份验证部分根本没有改变,但是由于尽管输入了正确的凭据,我还是恢复了数据库
BadCredentialsException: Bad credentials at
org.springframework.security.authentication.dao.DaoAuthenticationProvider.additionalAuthenticationChecks(DaoAuthenticationProvider.java:98) at
org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.java:165) at org.springframework.security.authentication.ProvideManager.authenticate(ProviderManager.java:167) at
....
堆栈跟踪的其余部分都是堆栈跟踪的标准 spring/catalina/java 位,没有自定义。
它没有过期,我已经删除了 cookie,它没有被禁用....
这段代码在字面上没有改变,也没有支持数据库表或 Spring 库。调试我可以确认用户名检索到了正确的用户,因为它正在使用密码哈希和权限正确构造用户对象的身份验证。由于其中大部分是由 Spring 类的默认行为完成的,因此我无法在发生时单步执行大部分代码,因此很难确定实际的错误凭据发生在哪里以及到底发生了什么变化。
谷歌搜索,我发现很多用户都有问题,但几乎他们中的大多数人都在处理最初的错误配置。这不是一个问题,因为这段代码曾经可以工作。
是否有任何与我可能测试的 Spring 安全性相关的已知问题?
如果做不到这一点,我该如何进一步分类?