【发布时间】:2020-07-19 19:02:27
【问题描述】:
使用 Spring Boot 2+ 我有一个包含以下内容的 application.properties 文件:
这是我application.properties的一部分:
spring.datasource.password={bcrypt}xxxxxxx
如果没有 bcrypt,应用程序可以完美运行,但是使用它,我的代码在 DB JPA 登录中返回错误。
我已将此添加到我的安全类中:
@Autowired
private DataSource dataSource;
@Autowired
public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(dataSource).passwordEncoder(passwordEncoder());
}
@Bean
public BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
但这并不能解决我的问题。 仍然无法登录数据库。
有人可以帮忙吗? 在此先感谢各位。
【问题讨论】:
-
去掉
{bcrypt},它只在你使用DelegatingPasswordEncoder时使用。请参阅此答案以了解更多stackoverflow.com/questions/62701158/… -
如果仍然失败,在
BCryptPasswordEncoder.matches方法中下一个断点,它将比较你发送的密码和你在application.properties中设置的密码 -
嗨,@KavithakaranKanapathippillai 感谢您的回答。我迷路了,因为您的答案与 DB 中的 Bcrypt 密码有关。我的重点是哈希我的数据库密码连接.. 为什么这么难?
-
您的密码也来自 db。在您的配置中查看
jdbcAuthentication() -
你有 github 仓库吗?
标签: java spring spring-boot spring-data-jpa jpa-2.0