# 第一种
*****
~~~ java
import org.maicaii.common.util.PasswordUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
//设置用户名
//密码
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String password = passwordEncoder.encode("admin");
auth.inMemoryAuthentication()//放在内存
.withUser("admin")//用户名
.password(password)//密码 加密过 对应下面 @Bean
.roles("admin");//权限
}
@Bean //加密方式
public PasswordEncoder password(){
return new BCryptPasswordEncoder();
}
}
~~~