小编Dan*_*l L的帖子

如何在Spring表达式语言中进行类型转换

我正在尝试使用@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)

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

谢谢,

丹尼尔

spring types expression casting

6
推荐指数
1
解决办法
3842
查看次数

标签 统计

casting ×1

expression ×1

spring ×1

types ×1