liveBook · Manning

Authorization

As explained in Spring Security in Action, Second Edition

Authorization is the process of determining whether an authenticated entity has permission to perform an action or access a resource.

Authorization decides whether an authenticated entity may access a resource or perform an action. Spring Security evaluates the request after authentication, using the authenticated user’s authorities and configured rules. section 7.0 section 7.2

Configure access control at several application boundaries:

  • Define authorities as named permissible actions, such as READ, WRITE, or DELETE, and attach them to UserDetails. section 7.1
  • Restrict endpoints with hasAuthority(), hasAnyAuthority(), permitAll(), denyAll(), or custom access expressions. section 7.1.1 section 7.2
  • Select endpoint rules by path and HTTP method with requestMatchers(), using regular expressions when path expressions are insufficient. section 8.4
  • Protect service or other application-layer methods with @PreAuthorize or @PostAuthorize after enabling method security. section 11.5
  • Keep complex authorization logic in a separate PermissionEvaluator rather than making expressions difficult to read. section 11.5

Require WRITE authority

A SecurityFilterChain can require authentication and then restrict every endpoint to users with WRITE authority: http.authorizeHttpRequests(c -> c.anyRequest().hasAuthority("WRITE")). A user with WRITE receives the endpoint response; an authenticated user without it receives HTTP 403 Forbidden.

How Spring Security in Action, Second Edition covers it

How deep it goes
Traces authorization from the post-authentication filter through authorities, endpoint matchers, expressions, and method-security annotations.
Examples
Uses READ and WRITE users, HTTP Basic requests, endpoint restrictions, 403 responses, and a method protected by @PreAuthorize.
What it assumes
Assumes Java and basic Spring knowledge while teaching authentication, authorities, roles, endpoint rules, and method security progressively.
What you can do after
Apply it via Spring Security by configuring SecurityFilterChain rules and protecting methods with expression-based authorization.
How it connects
Connects authentication, authorities, roles, endpoint authorization, method security, Spring Expression Language, and PermissionEvaluator.

Also explained in

Compare how 28 books explain authorization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Security in Action, Second Edition. The section links point to the parts of the book it draws on.