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