0

编辑:这个问题原来是用户错误,密码已更改,因此哈希永远不会匹配

我在 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 安全性相关的已知问题?

如果做不到这一点,我该如何进一步分类?

4

1 回答 1

1

还有一些事情要尝试:

  1. 验证数据库排序规则和字符集在新旧环境中是否匹配
  2. 您在应用程序中是否有办法(或者您可以编写一些简单的代码)重置密码,然后尝试使用新重置的密码登录(或者只是编写一些快速代码来生成一个您知道正确的新密码,然后直接针对数据库设置)?如果可行,请对照数据库中的其他密码查看新密码的格式。
  3. 以您自己的自定义DaoAuthenticationProvider连接,使您能够设置断点(或仅记录到控制台/文件)生成的与数据库密码哈希
  4. 实现您自己的自定义StandardPasswordEncoder(从此处),但再次添加更多日志记录/断点
于 2019-05-30T23:55:02.403 回答