I'm trying to understand Spring Security and I'm wondering about creating my own annotations with authorities I've created. I've got something like this:
@PreAuthorize("hasAuthority('STANDARD')")
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface StandardRole {
}
@PreAuthorize("hasAuthority('ADMIN')")
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface AdminRole {
}
and actually it looks like:
@AdminRole
@StandardRole
@GetMapping(path = "user", produces = "application/json")
public ResponseEntity<User> getUser(@RequestParam String login) {
...
}
but only first annotation works, second one is ommited. I want to do something like @AllowRoles()
annotation, for example @Allow({UserType.ADMIN, UserType.STANDARD})
or @Allow({UserType.ADMIN})
.
How can I do this? Thanks.