使用 Spring 表达式语言配置访问控制
基于角色标准投票机制的标准实现是使用 RoleVoter ,还有一种替代方法可用来定义语法复杂的投票规则即使用 Spring 表达式语言( SpEL )。要实现这一功能的直接方式是在 <http> 配置元素上添加 use-expressions 属性:
<http auto-config="true" use-expressions="true">
添加后将要修改用来进行拦截器规则声明的 access 属性,改为 SpEL 表达式。 SpEL 允许使用特定的访问控制规则表达式语言。与简单的字符串如 ROLE_USER 不同,配置文件可以指明表达式语言触发方法调用、引用系统属性、计算机值等等。
SpEL 的语法与其他的表达式语言很类似,如在 Tapestry 等框架中用到的 Object Graph Notation Language (OGNL) ,以及用于 JSP 和 JSF 的 Unified Expression Language 。它的语法面很广,已经超出了本书的覆盖范围,我们将会通过几个例子为你构建表达式提供一些确切的帮助。
需要注意的重要一点是,如果你通过使用 use-expressions 属性启用了 SpEL 表达式访问控制,将会使得自动配置的 RoleVoter 实效,后者能够使用角色的声明,正如在前面的例子所见到的那样:
<intercept-url pattern="/*" access="ROLE_USER"/>
这意味着如果你仅仅想通过角色来过滤请求的话,访问控制声明必要要进行修改。幸运的的是,这已经被充分考虑过了,一个 SpEL 绑定的方法 hasRole 能够检查角色。如果我们要使用表达式来重写例子的配置,它可能看起来如下所示:
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/*" access="hasRole('ROLE_USER')"/>
</http>
分享到:
相关推荐
The namespace for both Spring 3 and 4 versions of this dialect is http://www.thymeleaf.org/extras/spring-security. <html xmlns:sec="http://www.thymeleaf.org/extras/spring-security"> Getting ...
rubygem-cucumber-tag_expressionsrubygem-cucumber-tag_expressions
python - HowTo - Regular Expressions (2002).pdf
babel-plugin-transplace-expressions 用其他表达式替换JavaScript表达式。安装$ yarn add --dev babel-plugin-transform-replace-expressions例输入文件: const env = process . env . NODE_ENV ;typeof Hello ===...
编译时正则表达式v3 快速的编译时正则表达式,支持在编译时或运行时进行匹配/搜索/捕获。 您可以使用目录single-header的单头版本。 可以使用make single-header重新生成此make single-header 。...
高中英语 Module 5 Ethnic Culture-Section 3 Words and Expressions素材 外研版选修7.doc
此存储库已移至DOM Expressions Mono存储库。 此存储库不再被维护。 去这里: : Babel插件JSX DOM表达式 该软件包是为构建的JSX编译器,可为React式库提供一般的JSX到DOM转换,以进行精细的变化检测。 该软件包旨在...
If you don't use regular expressions yet, you will discover in this book a whole new world of mastery over your data. If you already use them, you'll appreciate this book's unprecedented detail and ...
基本正则表达式的学习,python入门,适合新手使用
3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................
davechild_regular-expressions davechild_regular-expressions davechild_regular-expressions davechild_regular-expressions davechild_regular-expressions
Mastering-Python-Regular-Expressions 精通Python正则表达式
3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................
sap press doc 解压密码:abap_developer
专题资料
java8流源码Java8-Functional-Interfaces-and-Lambda-Expressions 为什么使用 Lambda 启用函数式编程:我们可以将函数用作可以传递的实体。 可读且简洁的代码:强大的匿名内部类。 Lambda 使其可读且简洁。 更易于...
var expressions = require ( "angular-expressions" ) ; evaluate = expressions . compile ( "1 + 1" ) ; evaluate ( ) ; // returns 2 您还可以在给定scope设置和获取值: evaluate = expressions . compile ...
classes, lambda expressions, Spring Boot, and reactive programming. We share our insights and real-world experiences with enterprise application development, including remoting, transactions, the web ...
( 13-Java-8-Lambda-Expressions-Part-1.pdf ) java 8 lambda- expressions 学习资料,例子。练习 java example
regular-expressions-cheat-sheet-v2.pdf,正则表达式备忘单