为了账号安全,请及时绑定邮箱和手机立即绑定

数据库恢复后 Spring 身份验证失败

数据库恢复后 Spring 身份验证失败

慕田峪9158850 2022-12-28 10:00:31
编辑:这个问题原来是用户错误,密码已更改,因此哈希永远不会匹配我在 Spring 4.2.2 的工具包中使用简单的身份验证,使用 DAO 读取 (Postgres) 数据库表以获取用户名、密码和权限@EnableWebSecurity@Configurationclass 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) atorg.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 安全相关的已知问题?如果做不到这一点,我该如何进一步分类?
查看完整描述

1 回答

?
不负相思意

TA贡献1777条经验 获得超10个赞

还有一些事情要尝试:

  1. 验证数据库排序规则和字符集在新旧环境中是否匹配

  2. 你有没有办法在你的应用程序中(或者你能写一些简单的代码来)重置密码然后尝试使用新重置的密码登录(或者只是写一些快速代码来生成一个你知道正确的新密码然后直接针对数据库设置)?如果可行,请查看新密码与数据库中其他密码的格式。

  3. 连接您自己的自定义DaoAuthenticationProvider,使您能够设置断点(或仅记录到控制台/文件)生成的与数据库密码哈希

  4. 实现您自己的自定义StandardPasswordEncoder(从这里),但再次添加更多日志记录/断点


查看完整回答
反对 回复 2022-12-28
  • 1 回答
  • 0 关注
  • 195 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号