There is no PasswordEncoder mapped for the id "null"'錯誤的解決方式


解決方式:自定義加密方式,實現PasswordEncoder接口

 

修改前:

 @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .withUser("yrc").password("111").roles("USER")
                .and()
                .withUser("tx").password("222").roles("USER");
    }
   

 

修改后:此處使用明文,其實就是不加密

  (1)加密類

import org.springframework.security.crypto.password.PasswordEncoder;

/*
設置用戶信息明文傳輸
 */
public class MyPasswordEncoder implements PasswordEncoder {
    @Override
    public String encode(CharSequence charSequence) {
        return charSequence.toString();
    }

    @Override
    public boolean matches(CharSequence charSequence, String s) {
        return s.equals(charSequence.toString());
    }
}

  (2)

 @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .passwordEncoder(new MyPasswordEncoder())
                .withUser("yrc").password("111").roles("USER")
                .and()
                .withUser("tx").password("222").roles("USER");
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM