解决方式:自定义加密方式,实现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"); }