Assuming a grails (v2.3.x) custom class created and setup in a way that mimics the java way outlined by @JamesWatkins in this post, it is simple to annotate a method with a static string:
@Secured(["@mySecurityService.hasPermission('special')"])
public void doSpecialStuff() { ... }
But in an attempt to prevent hard-coding values, is it possible to replace 'special'
by embedding a custom Enum (or similar) in the SpEL expression?
I have tried this:
@Secured(["@mySecurityService.hasPermission('{ T(com.example.MyConfig$MyEnum.SPECIAL) }')"])
public void doSpecialStuff() { ... }
but I keep getting an exception about the string not being a constant:
Expected '@mySecurityService.hasPermission('{ T(com.example.MyConfig$MyEnum.SPECIAL) }')' to be an inline constant of type java.lang.String