7

我正在尝试使用 @PreAuthorize 注释进行访问控制。我需要检查身份验证对象详细信息中的一些自定义字段。我有一个 CustomWebAuthenticationDetails 类,它是 WebAuthenticationDetails 的子类,包含自定义字段。通常,我会使用以下内容访问 CustomWebAuthenticationDetails 中的自定义字段:

((CustomWebAuthenticationDetails)authentication.getDetails()).getCustomField()

但是,当我尝试在 @PreAuthorize 表达式中使用上述语句(甚至包括 CustomWebAuthenticationDetails 的完全限定路径)时,我收到以下错误:

java.lang.IllegalArgumentException: Failed to parse expression ...

我应该如何处理这里的类型转换?

谢谢,

丹尼尔

4

1 回答 1

10

AFAIK,鉴于 EL 的动态和解释性质,您不需要任何演员表。如果运行时对象的属性存在,它将找到它,而不关心其声明的类型:

authentication.details.customField
于 2012-06-09T06:59:55.630 回答