hasAnyAuthority() restricts an endpoint to authenticated users possessing at least one authority from a specified set. It keeps authorization rules readable when several privileges grant access. section 7.1.1
Allow READ or WRITE
Configure the security filter chain with c -> c.anyRequest().hasAnyAuthority("WRITE", "READ"). Users holding either authority can call the endpoint; users holding neither receive 403 Forbidden.
Use the simplest rule matching the privilege model:
- Prefer hasAnyAuthority() over access() when an endpoint needs an uncomplicated OR rule; reserve access() for custom or complex authorization expressions. section 7.1.1
