Spring Boot: How to specify the PasswordEncoder?

前端 未结 15 1210
醉梦人生
醉梦人生 2020-12-02 06:27

Currently I got the main class:

package com.recweb.springboot;

import org.springframework.boot.SpringApplication;
im         


        
15条回答
  •  广开言路
    2020-12-02 06:51

    Try this in SecurityConfig extends WebSecurityConfigurerAdapter :

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
    @Override
    protected void configure(final AuthenticationManagerBuilder auth) throws Exception{        
        auth
            .inMemoryAuthentication()
                .withUser("user")
                .password(passwordEncoder().encode("password"))
                .roles("USER")
            .and()
                .withUser("admin")
                .password(passwordEncoder().encode("admin"))
                .roles("USER", "ADMIN");
    }
    

    Work for me

提交回复
热议问题