41.4 Method Security方法安全性
41.4.1 <global-method-security>
这个元素是为Spring Security beans上的安全方法添加支持的主要手段。可以通过使用注释(在接口或类级别定义)或者通过使用AspectJ语法将一组切入点定义为子元素来保护方法。
<global-method-security> Attributes
- access-decision-manager-ref 方法安全性使用与web安全性相同的AccessDecisionManager配置,但这可以使用此属性覆盖。默认情况下,基于确认AffirmativeBased 的实现用于角色投票者RoleVoter 和授权投票者AuthenticatedVoter。
- authentication-manager-ref 应该用于方法安全性的身份验证管理器的引用。
- jsr250-annotations指定是否要使用JSR-250样式属性(例如“角色化”)。这将需要类路径上的javax.annotation.security类。将此设置为true还会将一个Jsr 250选民添加到访问决策管理器中,因此如果您使用自定义实现并希望使用这些注释,您需要确保这样做。
- metadata-source-ref 可以提供一个外部MethodSecurityMetadataSource实例,该实例将优先于其他源(如默认注释)。
- mode 该属性可以设置为“aspectj”,以指定应该使用AspectJ而不是默认的Spring AOP。安全方法必须与spring-security-aspects模块中的注释安全属性相结合。
值得注意的是,AspectJ遵循Java的规则,即接口上的注释是不可继承的。这意味着在接口上定义安全注释的方法将不会受到保护。相反,在使用AspectJ时,必须将安全性注释放在类上。
- order 允许为方法安全拦截器设置建议“顺序”。
- pre-post-annotations 指定是否应该为此应用程序上下文启用Spring Security的调用前和调用后注释(@ PreFilter,@PreAuthorize,@PostFilter,@PostAuthorize)。默认为“禁用”。
- proxy-target-class 如果为真,将使用基于类的代理,而不是基于接口的代理。
- run-as-manager-ref 对可选运行管理器实现的引用,该实现将由已配置的MethodSecurityInterceptor使用
- secured-annotations 指定是否应该为此应用程序上下文启用Spring Security的@Secured注释。默认为“disabled”。
Child Elements of <global-method-security>
41.4.2 <after-invocation-provider>
此元素可用于修饰由<global-method-security>命名空间维护的安全性拦截器使用的AfterInvocationProvider。您可以在global-method-security元素中定义零个或多个这样的元素,每个元素都有一个引用属性指向您的应用程序上下文中的一个AfterInvocationProvider bean实例。
<after-invocation-provider> Attributes
- ref 定义对实现AfterInvocationProvider的Spring bean的引用。
41.4.3 <pre-post-annotation-handling>
允许完全替换用于处理Spring Security的调用前和调用后注释的默认基于表达式的机制(@ PreFilter、@PreAuthorize、@PostFilter、@PostAuthorize)。仅在启用这些注释时适用。
Child Elements of <pre-post-annotation-handling>
41.4.4 <invocation-attribute-factory>
定义前置调用属性工厂实例,该实例用于从带注释的方法生成调用前和调用后元数据。
<invocation-attribute-factory> Attributes
- ref 定义对spring bean标识的引用
41.4.5 <post-invocation-advice>
使用引用作为<pre-post-annotation-handling>元素的位置授权PostInvocationAuthorizationAdvice 建议来自定义位置授权提供程序PostInvocationAdviceProvider 。
<post-invocation-advice> Attributes
- ref 定义对spring bean标识的引用
41.4.6 <pre-invocation-advice>
使用引用作为<pre-post-annotation-handling>元素的前置位置授权建议投票者PreInvocationAuthorizationAdviceVoter ,自定义前置位置授权建议投票者PreInvocationAuthorizationAdviceVoter 。
<pre-invocation-advice> Attributes
- ref 定义对spring bean标识的引用
41.4.7 Securing Methods using
您可以使用<protect-pointcut>元素跨服务层中的整套方法和接口定义交叉安全约束,而不是使用@Secured注释在单个方法或类的基础上定义安全属性。您可以在名称空间介绍中找到一个示例。
<protect-pointcut> Attributes
- access 访问适用于所有匹配切入点的方法的配置属性列表,例如“角色甲,角色乙”
- expression AspectJ表达式,包括“执行”关键字。例如,“执行(int com . foo . TargetObject . CountLength(String))”(不带引号)。
41.4.8 <intercept-methods>
可以在bean定义中使用,向bean添加安全拦截器,并为bean的方法设置访问配置属性
<intercept-methods> Attributes
- access-decision-manager-ref 创建的方法安全拦截器使用的可选访问决策管理器AccessDecisionManager bean标识。
Child Elements of <intercept-methods>
41.4.9 <method-security-metadata-source>
创建MethodSecurityMetadataSource 实例
<method-security-metadata-source> Attributes
- id 一个bean标识符,用于引用上下文中其他地方的bean。
- use-expressions 允许在<intercept-url >元素的“access”属性中使用表达式,而不是传统的配置属性列表。默认为“false”。如果启用,每个属性应该包含一个布尔表达式。如果表达式计算结果为“true”,将授予访问权限。
Child Elements of <method-security-metadata-source>
41.4.10 <protect>
定义受保护的方法和应用于该方法的访问控制配置属性。我们强烈建议您不要将“保护”声明与任何提供“global-method-security”的服务混在一起。
<protect> Attributes
- access 访问适用于该方法的访问配置属性列表,例如“角色A,角色B”。
- method 方法名
41.4 Method Security方法安全性的更多相关文章
- Spring Security方法级别授权使用介绍
1.简介 简而言之,Spring Security支持方法级别的授权语义. 通常,我们可以通过限制哪些角色能够执行特定方法来保护我们的服务层 - 并使用专用的方法级安全测试支持对其进行测试. 在本文中 ...
- Factory Method 工厂方法模式
Factory method工厂方法模式是一种实现了“工厂”概念的面向对象设计模式.就像其他创建型模式一样,它也是处理在不指定对象具体类型的情况下创建对象的问题.工厂方法模式的实质是“定义一个创建对象 ...
- (转)Java.lang.reflect.Method invoke方法 实例
背景:今天在项目中用到Method 的invoke方法,但是并不理解,查完才知道,原来如此! import java.lang.reflect.Method; /** * Java.lang.refl ...
- Spring Security 4 Method security using @PreAuthorize,@PostAuthorize, @Secured, EL--转
原文地址:http://websystique.com/spring-security/spring-security-4-method-security-using-preauthorize-pos ...
- java.lang.reflect.Method.getAnnotation()方法示例【通过反射获取到方法对象再获取方法对象上的注解信息】
转: java.lang.reflect.Method.getAnnotation()方法示例 java.lang.reflect.Method.getAnnotation(Class <T&g ...
- java.lang.reflect.Method.getAnnotation()方法示例
转: java.lang.reflect.Method.getAnnotation()方法示例 作者: 初生不惑 Java技术QQ群:227270512 / Linux QQ群:479429477 ...
- 错误:Attempt to resolve method: [XXX方法] on undefined variable or class name: [XXX类]的解决(IDEA打包jar问题)
问题: 使用JMeter调用jar包的时候,报错误信息Typed variable declaration : Attempt to resolve method:[XXX方法] on undefin ...
- Spring Security(二十二):6.4 Method Security
From version 2.0 onwards Spring Security has improved support substantially for adding security to y ...
- Spring Security(十七):5.8 Method Security
From version 2.0 onwards Spring Security has improved support substantially for adding security to y ...
随机推荐
- Oracle创建自动增长列
前言: Oracle中不像SQL Server在创建表的时候使用identity(1001,1)来创建自动增长列,而是需要结合序列(Sequences)和触发器(Triggers)来实现 创建测试表 ...
- 解决android studio Gradle无法同步问题
打开根目录build.gradle buildscript { repositories { // 添加阿里云 maven 地址 maven { url 'http://maven.aliyun.co ...
- springcloud ribbon的 @LoadBalanced注解
在使用springcloud ribbon客户端负载均衡的时候,可以给RestTemplate bean 加一个@LoadBalanced注解,就能让这个RestTemplate在请求时拥有客户端负载 ...
- 一个文本框的各项说明,包括类似html的table
https://www.cnblogs.com/zhqiux/archive/2013/09/03/3298654.html
- MySQL Front远程连接数据库
连接前需要先配置一下服务器端的数据库 进入mysql数据库,选择mysql mysql> use mysql; 选择 host 表 mysql> select host from user ...
- SpringBoot整合Mail发送邮件&发送模板邮件
整合mail发送邮件,其实就是通过代码来操作发送邮件的步骤,编辑收件人.邮件内容.邮件附件等等.通过邮件可以拓展出短信验证码.消息通知等业务. 一.pom文件引入依赖 <dependency&g ...
- Day15_用户注册
学于黑马和传智播客联合做的教学项目 感谢 黑马官网 传智播客官网 微信搜索"艺术行者",关注并回复关键词"乐优商城"获取视频和教程资料! b站在线视频 0.学习 ...
- Python三角函数
Python三角函数: 函数: ''' math.sin(x) 返回的x弧度的正弦值. math.asin(x) 返回x的反正弦弧度值. math.cos(x) 返回x的弧度的余弦值. math.ac ...
- Python列表函数和方法
Python列表函数和方法: 函数: len(列表名): 返回列表长度 # len(列表名): # 返回列表长度 lst = [1,2,3,'a','b','c'] print("lst 列 ...
- PHP jdmonthname() 函数
------------恢复内容开始------------ 实例 返回 1998 年 1 月 13 日这天的格利高里历法的月份简写字符串: <?php$jd=gregoriantojd(1,1 ...