从 Spring 安全表达式调用静态方法? [英] Calling static methods from Spring Security Expressions?
问题描述
我正在寻找一种方法来扩展 Spring Security Expressions 以支持现有的安全基础设施.我知道您可以按照 这里,但我也发现了参考 直接通过 Spring 表达式语言(Spring EL 或 SpEL)调用静态方法.不幸的是,关于 Spring 表达式方法的官方页面没有不直接描述如何做到这一点.
I'm looking for a way to extend Spring Security Expressions to support an existing security infrastructure. I'm aware you can extend the MethodSecurityExpressionRoot as described here, but I also found reference to directly calling static methods through Spring Expression Language (Spring EL or SpEL). Unfortunately the official page on Spring Expression methods doesn't directly describe how to do this.
如何通过 Spring Expression 方法调用静态方法?
How can I invoke a static method through Spring Expression methods?
推荐答案
通过使用 T(fully.qualified.name).methodName()
语法:
By using the T(fully.qualified.name).methodName()
syntax:
您可以使用特殊的 T
运算符来指定 java.lang.Class
(类型)的实例.静态方法也通过使用此运算符调用.StandardEvaluationContext
使用TypeLocator
来查找类型,StandardTypeLocator
(可以替换)是在理解java.lang
包.这意味着 T()
对 java.lang
中类型的引用不需要是完全限定的,但所有其他类型的引用都必须是.
You can use the special
T
operator to specify an instance ofjava.lang.Class
(the type). Static methods are invoked by using this operator as well. TheStandardEvaluationContext
uses aTypeLocator
to find types, and theStandardTypeLocator
(which can be replaced) is built with an understanding of thejava.lang
package. This means thatT()
references to types withinjava.lang
do not need to be fully qualified, but all other type references must be.
T
元素返回对类型而不是实例的引用.例如,Collections.singleton("Hello")
的等价物是
The T
element returns a reference to the type instead of an instance. For example, the equivalent of Collections.singleton("Hello")
is
T(java.util.Collections).singleton('Hello')
这篇关于从 Spring 安全表达式调用静态方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!