AuthorizationManager is a Spring Security contract for deciding whether an authenticated principal may access an object or request. The access() method uses it to support custom authorization rules, including Spring Security’s WebExpressionAuthorizationManager for SpEL expressions. section 7.1.1
Use the simplest authorization mechanism that expresses the endpoint policy:
- Use hasAuthority() when one configured authority is required. section 7.1.1
- Use hasAnyAuthority() when any one of several authorities is sufficient. section 7.1.1
- Use access() with an AuthorizationManager or expression when simpler methods cannot represent the rule; complex expressions can reduce readability. section 7.1.1
Authority-based endpoint authorization
A SecurityFilterChain can require WRITE authority for every request with c.anyRequest().hasAuthority("WRITE"). Jane, assigned WRITE, receives Hello!, while John, assigned READ, receives HTTP 403 Forbidden.
