'Spring: Create Custom Annotation that Transform its Arguments for Another Annotation

I have some predefined roles in an enum:

enum class Role { User, Admin, ... }

And I want to use them in annotation for security.
Spring's Secured annotation only accepts String, so I need a custom annotation like the below:

@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class AllowRole(vararg val roles: Role)

Here comes the question: How can I make it work like Secured?
Since annotations cannot be inherited, and annotation parameters must be a compile-time constant, so obviously the following approaches are not possible:

annotation class AllowRole(vararg val roles: Role, val secured: Secured = Secured(roles.map{ it.toString() })
@Secured(roles.map{ it.toString() })
annotation class AllowRole(vararg val roles: Role)

So, is there any other way to make it work?
Or if it proves impossible, how can I let Spring recognize my custom annotation and make it work like Secured?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source