栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Spring Security配置

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring Security配置

WebSecurity

ignoring()
方法的常规用法 省略了Spring Security, 并且Spring
Security的功能均不可用。WebSecurity基于HttpSecurity。

@Overridepublic void configure(WebSecurity web) throws Exception {    web        .ignoring()        .antMatchers("/resources/**")        .antMatchers("/publics/**");}@Overrideprotected void configure(HttpSecurity http) throws Exception {    http        .authorizeRequests()        .antMatchers("/admin/**").hasRole("ADMIN")        .antMatchers("/publics/**").hasRole("USER") // no effect        .anyRequest().authenticated();}

上面的示例中的WebSecurity让Spring忽略

/resources/**
/publics/**
。因此
.antMatchers("/publics/**").hasRole("USER")
,不
考虑 HttpSecurity中的。

这将完全省略来自安全过滤器链的请求模式。请注意,与此路径匹配的所有内容都将不应用身份验证或授权服务,并且可以自由访问。

configure(HttpSecurity)
允许根据选择匹配在 资源级别 配置基于Web的安全性-
例如,以下示例将以URL开头的URL限制为
/admin/
具有 ADMIN角色的 用户,并声明需要 成功进行身份验证的 所有其他URL

configure(WebSecurity)
用于 影响全局安全性的
配置设置(忽略资源,设置调试模式,通过实现自定义防火墙定义拒绝请求)。例如,以下方法将导致 以身份验证为 开头的所有请求
/resources/
都被
忽略



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/369732.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号