Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot Spring引导安全性错误:编码的密码看起来不像BCrypt,正在从内存身份验证转换为数据库身份验证_Spring Boot_Spring Security - Fatal编程技术网

Spring boot Spring引导安全性错误:编码的密码看起来不像BCrypt,正在从内存身份验证转换为数据库身份验证

Spring boot Spring引导安全性错误:编码的密码看起来不像BCrypt,正在从内存身份验证转换为数据库身份验证,spring-boot,spring-security,Spring Boot,Spring Security,我得到一个错误:编码的密码看起来不像BCrypt 这是我的配置类: @EnableWebSecurity @Configuration public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter { @Autowired DataSource dataSource; @Override protected void configure(final HttpSecurity http) throws E

我得到一个错误:编码的密码看起来不像BCrypt

这是我的配置类:

@EnableWebSecurity
@Configuration
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {


@Autowired
DataSource dataSource;

@Override
protected void configure(final HttpSecurity http) throws Exception {
    http
            .csrf()
            .disable()
            .authorizeRequests()
            .antMatchers("/h2-console/**", "/createUser")
            .permitAll()
            .anyRequest().authenticated()
            .and()
            .formLogin()
            .permitAll()
            .and()
            .logout()
            .permitAll();

    http.csrf()
            .ignoringAntMatchers("/h2-console/**");
    http.headers()
            .frameOptions()
            .sameOrigin();
}

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {

    String userbyUsernameQuery = "select username, password, '1' as enabled from auth_user where username=?;";
    String rolebyUsernameQuery = "SELECT auth_user.username, auth_role.role_name as authority from auth_user\n" +
            "INNER JOIN auth_user_role ON auth_user.auth_user_id = auth_user_role.auth_user_id\n" +
            "INNER JOIN auth_role ON auth_role.auth_role_id = auth_user_role.auth_role_id\n" +
            "WHERE auth_user.username =?";

    auth.jdbcAuthentication()
            .dataSource(dataSource)
            .passwordEncoder(passwordEncoder())
            .usersByUsernameQuery(userbyUsernameQuery)
    .authoritiesByUsernameQuery(rolebyUsernameQuery);

}
@Bean
public PasswordEncoder passwordEncoder() {
    return PasswordEncoderFactories.createDelegatingPasswordEncoder();
}
}
如果有必要,我可以发布我的数据库,尽管我认为这与数据库无关

INSERT INTO auth_user (auth_user_id, first_name, last_name, username, password, enabled)
VALUES (1, 'John', 'Test', 'username', 'password', 'yes');

INSERT INTO auth_role (auth_role_id, role_name, role_desc)
VALUES (1, 'ADMIN', 'Admin role'),
(2, 'USER', 'User role');

INSERT INTO auth_user_role (auth_user_id, auth_role_id)
VALUES (1, 1);
我将其提交到数据库,并在我的spring boot应用程序中输入用户名和密码作为用户名和密码,但是它给了我这个错误,我无法找出错误,因为我看到的“修复”实际上就是我在这里看到的

需要一些关于从这里走到哪里或者什么是特别错误的指针


谢谢。

您应该使用相同的
密码编码器
将密码编码到数据库中,下面是一个示例


我已经找到了我的问题的答案,那就是加上这个

    @Bean
public static NoOpPasswordEncoder passwordEncoder() {
    return (NoOpPasswordEncoder) NoOpPasswordEncoder.getInstance();
}
因为我的密码存储为默认字符串,所以我需要使用它。 我更改了AuthenticationManagerBuilder配置方法以包含此项

       auth.jdbcAuthentication()
            .dataSource(dataSource)
            .usersByUsernameQuery(userbyUsernameQuery)
    .authoritiesByUsernameQuery(rolebyUsernameQuery)
    .passwordEncoder(passwordEncoder());

如何将密码存储在数据库中?我刚才将其存储为默认字符串是的,用于内存中的身份验证。我将如何使用数据库来实现这一点。
       auth.jdbcAuthentication()
            .dataSource(dataSource)
            .usersByUsernameQuery(userbyUsernameQuery)
    .authoritiesByUsernameQuery(rolebyUsernameQuery)
    .passwordEncoder(passwordEncoder());