1.使用Bcrypt加密类需要导入包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
注:springboot在导入该包后会自动对所有页面进行权限控制,开启spring-security权限控制。
2.放行所有页面
添加配置类即可:
@Configuration //告诉项目这是个配置文件早点加载
@EnableWebSecurity //以实现Web安全性
public class WebSecurityConfig extends WebSecurityConfigurerAdapter{//基类是个牛逼的类包含了很多涉及安全要使用的方法比如下面个重写的方法!
//下面这个方法简单的可以理解放开所有拦截!详细自己查!
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/**").permitAll()
.anyRequest().authenticated()
.and().csrf().disable();
}
}
3.Application启动类中添加一个加密工具类BcryptPasswordEncoder使用加密功能。
@Bean
prublic BcryptPasswordEncoder encoder(){
return new BcryptPasswordEncoder();
}
@Autowired
private BcryptPasswordEncode encoder;
String newpassword = encoder.encoder(password);