springsecurity 退出登录
2020-06-06 本文已影响0人
simplerandom
@EnableWebSecurity
public class SercurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().
// test路径无需登陆也可以访问
antMatchers("/test").authenticated().
// /登录后需要yes权限才可以访问
antMatchers("/").hasRole("yes").
// test2路径需要登录后访问
antMatchers("/test2").hasRole("root");
// 需要登录授权的路径自动跳转登录界面
http.formLogin();
//访问/logout路径退出登录,退出成功跳转/login路径
http.logout().logoutSuccessUrl("/login");
}
// 自定义在内存中的用户,密码,角色
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().passwordEncoder(new BCryptPasswordEncoder()).withUser("lee").password(new BCryptPasswordEncoder().encode("123")).roles("root", "guest").
//下一个用户
and().
withUser("guest").password(new BCryptPasswordEncoder().encode("123")).roles("guest");
}
}