【问题标题】:Spring Security - Dynamic/Runtime change the password encoderSpring Security - 动态/运行时更改密码编码器
【发布时间】:2015-07-20 15:32:51
【问题描述】:

我已经创建了运行流畅的spring security应用程序,目前我使用的是SHA-1编码技术但我想支持MD5加密技术

<!-- This will override the settings of authentication manager bean. -->
<authentication-manager alias="authenticationManager">
    <authentication-provider user-service-ref="umsUserDetailsService">
        <password-encoder hash="sha"/> 
    </authentication-provider>
    <authentication-provider ref="rememberMeAuthenticationProvider" />
</authentication-manager>

以上是SHA-1加密的配置设置。现在我也想支持MD5算法,

我已将当前算法存储在数据库中,只想支持它,因此只要我们可以更改加密算法,它将运行时反映到该算法/支持该算法,它将是 MD5 或 SHA-1。

要支持这种类型的流程需要做哪些改变?

【问题讨论】:

  • 请不要使用 MD5,因为它是完全破坏了存储密码的方式。
  • 感谢回复将确保防止使用MD5

标签: spring spring-mvc web-applications spring-security spring-boot


【解决方案1】:

我找到了答案,我们可以通过实施以下解决方案来做到这一点。

public class MyPasswordEncoder implements PasswordEncoder{
     @Override
     public String encodePassword(String rawPass, Object salt)
        throws DataAccessException {
      // TODO Auto-generated method stub
    }
    @Override
    public boolean isPasswordValid(String encPass, String rawPass, Object salt)
        throws DataAccessException {
   }
}

并将这个 bean 添加到应用程序上下文文件中。

【讨论】:

    猜你喜欢
    • 2012-01-17
    • 2014-04-23
    • 2023-03-09
    • 2017-04-16
    • 2014-08-15
    • 1970-01-01
    • 1970-01-01
    • 2013-03-21
    • 2014-03-24
    相关资源
    最近更新 更多