我正在尝试使用 @PreAuthorize 注释进行访问控制。我需要检查身份验证对象详细信息中的一些自定义字段。我有一个 CustomWebAuthenticationDetails 类,它是 WebAuthenticationDetails 的子类,包含自定义字段。通常,我会使用以下内容访问 CustomWebAuthenticationDetails 中的自定义字段:
((CustomWebAuthenticationDetails)authentication.getDetails()).getCustomField()
但是,当我尝试在 @PreAuthorize 表达式中使用上述语句(甚至包括 CustomWebAuthenticationDetails 的完全限定路径)时,我收到以下错误:
java.lang.IllegalArgumentException: Failed to parse expression ...
我应该如何处理这里的类型转换?
谢谢,
丹尼尔