从Spring Security Expressions调用静态方法? [英] Calling static methods from Spring Security Expressions?

查看:99
本文介绍了从Spring Security Expressions调用静态方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种扩展Spring Security Expressions以支持现有安全基础结构的方法.我知道您可以按照引用以通过Spring表达式语言(Spring EL或SpEL)直接调用静态方法.不幸的是,关于Spring Expression方法的官方页面并没有不能直接描述如何做到这一点.

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?

推荐答案

通过使用

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 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.

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 Security Expressions调用静态方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆