How to cast in Spring expression language

I am trying to use the @PreAuthorize annotation for access control. I need to check some custom fields in the details of the authentication object. I have a CustomWebAuthenticationDetails class that is a subclass of WebAuthenticationDetails and contains custom fields. I usually use the following to navigate to my custom fields in CustomWebAuthenticationDetails:

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

However, when I try to use the above statement (even including the full path to CustomWebAuthenticationDetails) in the @PreAuthorize expression, I get the following error:

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

How do I do this with a type?

Thanks,

Daniel

+4
source share
1 answer

AFAIK, given the dynamic and interpretable nature of EL, you do not need any throw. If a property exists for a run-time object, it will find it without worrying about its declared type:

 authentication.details.customField 
+7
source

All Articles