hasAnyRole() restricts an endpoint to users holding at least one role from a specified set. It provides a coarse-grained alternative to authority-based checks. section 7.1.2
Use role checks as follows:
- Pass the permitted role names to hasAnyRole(); a request succeeds when the user has one of them. section 7.1.2
- Declare roles with the ROLE_ prefix, but use the role name without that prefix in the authorization method. section 7.1.2
- Prefer hasAnyRole() or hasRole() before falling back to access() with an AuthorizationManager. section 7.1.2
Role-based endpoint access
Configure an endpoint with hasAnyRole("ADMIN", "MANAGER") when either role should be allowed. Users with neither role receive HTTP 403 Forbidden. User builders can create these roles with roles("ADMIN") and roles("MANAGER"), which adds ROLE_ automatically. section 7.1.2
