从 Spring Security 3.1.4.RELEASE 开始,旧的 org.springframework.security.authentication.encoding.PasswordEncoder
has been deprecated支持 org.springframework.security.crypto.password.PasswordEncoder
。由于我的应用程序尚未向公众发布,我决定迁移到新的、未弃用的 API。
到目前为止,我有一个 ReflectionSaltSource
自动使用用户的注册日期作为每个用户的密码盐。
String encodedPassword = passwordEncoder.encodePassword(rawPassword, saltSource.getSalt(user));
在登录过程中,Spring还使用我的bean来适本地验证用户是否可以登录。我无法在新的密码编码器中实现这一点,因为SHA-1的默认实现 - StandardPasswordEncoder
只能在编码器创建期间添加全局 secret 盐。
是否有任何合理的方法可以使用未弃用的 API 进行设置?
最佳答案
如果您实际上还没有使用现有格式注册任何用户,那么您最好切换到使用 BCrypt password encoder而是。
麻烦少了很多,因为您根本不必担心盐分 - 细节完全封装在编码器中。使用 BCrypt 比使用普通哈希算法更强大,它也是一个兼容使用其他语言的应用程序的标准。
真的没有理由为新应用程序选择任何其他选项。
关于java - 如何使用 Spring Security 的新 PasswordEncoder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17444258/