开发者

Calling static methods from Spring Security Expressions?

开发者 https://www.devze.com 2023-04-08 03:33 出处:网络
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 fou

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.

Ho开发者_开发技巧w can I invoke a static method through Spring Expression methods?


By using the T(fully.qualified.name).methodName() syntax:

You can use the special T operator to specify an instance of java.lang.Class (the type). Static methods are invoked by using this operator as well. The StandardEvaluationContext uses a TypeLocator to find types, and the StandardTypeLocator (which can be replaced) is built with an understanding of the java.lang package. This means that T() references to types within java.lang do not need to be fully qualified, but all other type references must be.

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')
0

精彩评论

暂无评论...
验证码 换一张
取 消