数据库还原后,Spring身份验证失败

时间:2019-05-30 22:50:31

标签: java spring

我在Spring 4.2.2的工具包中使用了简单的身份验证,使用的DAO读取了(Postgres)数据库表中的用户名,密码和权限

@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安全相关​​的已知陷阱吗?

如果失败,如何进一步分类?

1 个答案:

答案 0 :(得分:0)

还有更多尝试的方法:

  1. 验证新旧环境中的数据库排序规则和字符集是否匹配
  2. 您在应用程序中是否有办法(或者您可以编写一些简单的代码)来重置密码,然后尝试使用新重置的密码登录(或者只是编写一些快速代码以生成您知道的新密码)正确,然后直接针对数据库进行设置)?如果可以,请对照数据库中的其他密码查看新密码的格式。
  3. 使用您自己的自定义DaoAuthenticationProvider连线,使您可以设置断点(或仅记录到控制台/文件)生成的vs.数据库密码哈希值
相关问题