美文网首页
springsecurity 退出登录

springsecurity 退出登录

作者: simplerandom | 来源:发表于2020-06-06 17:04 被阅读0次
@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");
    }
}

相关文章

网友评论

      本文标题:springsecurity 退出登录

      本文链接:https://www.haomeiwen.com/subject/qzaxtktx.html