My question is a duplicate of Custom annotation with spring security but it went unanswered and I believe there should be a simple solution to the problem.
Basically ins
You can create static annotations like this:
@ReadPermission
By moving @PreAuthorize
annotation to @ReadPermission
definition:
@Inherited @PreAuthorize("hasRole(T(fully.qualified.Permission).READ.roleName())") public @interface ReadPermission { }
Benefit of this is, that you can then change Spring SPEL expression in one place, instead of modifying it on every method. One more plus is, that you can use this annotation on Class level - every method then would be secured with this annotation. It's useful for AdminControllers etc..