spring boot 安全控制

spring boot 登陆控制类 HttpSecurity http

例子:

protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/", "/home").permitAll()
                .anyRequest().authenticated()
                .and()
            .formLogin()
                .loginPage("/login")
                .permitAll()
                .and()
            .logout()
                .permitAll();
    }

antMatchers表示ant风格通配符

regexmatchers表示正则通配符

相对ant风格,我想正则更适合我

http.authorizeRequests().antMatchers("/","home");

http.authorizeRequests().regexMatchers("");

authenticated()和permitAll()来定义该如何保护路径。authenticated()要求在执行该请求时,必须已经登录了应用。如果用户没有认证,Spring Security的Filter将会捕获该请求,并将用户重定向到应用的登录界面。同时permitAll()方法允许请求没有任何的安全限制。除了authenticated()和permitAll()以外,authorizeRequests()方法返回的对象还有更多的方法用于细粒度地保护请求。如下所示:

https://i-blog.csdnimg.cn/blog_migrate/b2838f896e620cd7db3b320ae56a46f9.png

 

 

 

转载于:https://my.oschina.net/u/856051/blog/3004894

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值