Spring Boot: How to specify the PasswordEncoder?

前端 未结 15 959
醉梦人生
醉梦人生 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 07:07
    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception{    
        auth.inMemoryAuthentication().passwordEncoder(NoOpPasswordEncoder.getInstance())
                .withUser("test").password("test123").roles("USER").and()
                .withUser("test1").password("test123").roles("ADMIN");
    }
    
    0 讨论(0)
  • 2020-12-02 07:11

    You need to set the password encoder like this:

    @Bean
    public PasswordEncoder passwordEncoder() {
      return PasswordEncoderFactories.createDelegatingPasswordEncoder();
    }
    

    It's required to use the passwordEncoder for the users and also for the clients in Spring Boot 2

    Check out this repository https://github.com/dzinot/spring-boot-2-oauth2-authorization-jwt

    You can see how the passwordEncoder is set up and how to use it with users and clients in the database.

    0 讨论(0)
  • 2020-12-02 07:14

    I simply added

     @Bean
    public static NoOpPasswordEncoder passwordEncoder() {
     return (NoOpPasswordEncoder) NoOpPasswordEncoder.getInstance();
    }
    

    To the configuration class

    0 讨论(0)
提交回复
热议问题