liveBook · Manning

Chapter 11: Implementing authorization at the method level

What you will learn in chapter 11 of Spring Security in Action, Second Edition

Introduces method security as a way to apply authorization beyond HTTP endpoints in both web and non-web applications.

After this chapter you will be able to

What it builds on

Section by section

Introduction

Introduces method security as a way to apply authorization beyond HTTP endpoints in both web and non-web applications.

Key terms: method security, authorization, endpoint level, app layers

11.1 Enabling method security

This section explains why method-level authorization is useful, notes that method security must be enabled, and distinguishes call authorization from filtering.

Key terms: method security, endpoint level, call authorization, preauthorization, postauthorization, filtering, prefiltering, postfiltering

11.1.1 Understanding call authorization

This subsection explains how a Spring aspect enforces method-call authorization and contrasts checks made before execution with checks made after execution.

Key terms: call authorization, method security, Spring aspect, preauthorization, postauthorization, authenticated user, method parameters, AccessDeniedException, method return, @Transactional

11.1.2 Enabling method security in your project

This section shows how to enable method security and identifies the authorization approach used in the chapter’s examples.

Key terms: method security, @EnableMethodSecurity, pre-/postauthorization annotations, global method security, HTTP Basic authentication, OAuth 2

11.2 Applying preauthorization rules

Shows how to protect methods with preauthorization rules based on a user's authority or on a method parameter, and notes where method security can be applied.

Key terms: @PreAuthorize, Spring Expression Language (SpEL), hasAuthority(), write authority, preauthorization, #name, authentication.principal.username, getSecretNames(), method parameters, method security

11.3 Applying postauthorization rules

This section explains how to use postauthorization to check a method’s returned value before exposing it to the caller.

Key terms: postauthorization, returned value, @PostAuthorize, SpEL, returnObject, @PreAuthorize, Employee, reader, roles

11.4 Implementing permissions for methods

This section shows how to move complex method-authorization rules into a permission evaluator, apply them before or after a method call, and use simpler role-based annotations.

Key terms: SpEL, permission, authorization rules, PermissionEvaluator, hasPermission(), Authentication, SecurityContext, @PostAuthorize, returnObject, MethodSecurityExpressionHandler

11.5 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 10: Configuring CORS Chapter 12: Implementing filtering at the method level →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.