H2 Spring安全数据转换错误转换密码

时间:2018-11-24 18:56:32

标签: java spring spring-boot spring-security h2

我有一个带有H2数据库的Spring Boot项目。尝试在登录时对用户进行身份验证时遇到问题。

我在data.sql中插入了以下用户:

INSERT INTO USERS (`USER_ID`, `NAME`, `CITY`, `AGE`, `PASSWORD`)
VALUES (1, 'Test', 'TestCity', 25, 
'$2a$10$EblZqNptyYvcLm/VwDCVAuBjzZOI7khzdyGPBr08PpIi0na624b8.');

当我尝试登录时,我得到:

org.springframework.security.authentication.InternalAuthenticationServiceException:
PreparedStatementCallback; SQL [select user_id, name, password from USERS 
where name=? 
Data conversion error converting 
"$2a$10$EblZqNptyYvcLm/VwDCVAuBjzZOI7khzdyGPBr08PpIi0na624b8." [22018-197]

密码是BCryptPasswordEncoder进行加密的“ 123456”密码,但是我尝试使用不同的密码(甚至是纯文本)来获得相同的结果。

我的SecurityConfig.java

@Autowired
private BCryptPasswordEncoder bCryptPasswordEncoder;

@Autowired
private DataSource dataSource;

@Value("${spring.queries.users-query}")
private String usersQuery;

@Value("${spring.queries.roles-query}")
private String rolesQuery;

@Override
protected void configure(AuthenticationManagerBuilder auth)
        throws Exception {
    auth.
            jdbcAuthentication()
            .usersByUsernameQuery(usersQuery)
            .authoritiesByUsernameQuery(rolesQuery)
            .dataSource(dataSource)
            .passwordEncoder(bCryptPasswordEncoder);
}

application.properties查询:

spring.queries.users-query=select user_id, name, password from USERS where name=?

我不知道如何解决此问题,我将不胜感激。

0 个答案:

没有答案