liveBook · Manning

What you will learn in Spring Security in Action, Second Edition

by Laurentiu Spilca

Chapter by chapter

Chapter 1: Security today

The introduction places security among software qualities that may be hard to see in a working application but need attention from the start of development.

1.1 Discovering Spring Security · 1.2 What is software security? · 1.3 Why is security important? · 1.4 What will you learn in this book? · 1.5 Summary

What you learn in chapter 1 →

Chapter 2: Hello, Spring Security

The introduction explains why Spring Boot’s preconfigured defaults make Spring Security projects easier to start and customize.

2.1 Starting your first project · 2.2 The big picture of Spring Security class design · 2.3 Overriding default configurations · 2.3.1 Customizing user details management · 2.3.2 Applying authorization at the endpoint level · 2.3.3 Configuring in different ways · 2.3.4 Defining custom authentication logic · 2.3.5 Using multiple configuration classes · 2.4 Summary

What you learn in chapter 2 →

Chapter 3: Managing users

The chapter introduction explains why Spring Security uses interface contracts to manage users and identifies the user-related contracts the chapter will develop.

3.1 Implementing authentication in Spring Security · 3.2 Describing the user · 3.2.1 Describing users with the UserDetails contract · 3.2.2 Detailing on the GrantedAuthority contract · 3.2.3 Writing a minimal implementation of UserDetails · 3.2.4 Using a builder to create instances of the UserDetails type · 3.2.5 Combining multiple responsibilities related to the user · 3.3 Instructing Spring Security on how to manage users · 3.3.1 Understanding the UserDetailsService contract · 3.3.2 Implementing the UserDetailsService contract · 3.3.3 Implementing the UserDetailsManager contract · 3.4 Summary

What you learn in chapter 3 →

Chapter 4: Managing passwords

The introduction connects the previous chapter’s user management to passwords as an essential part of authentication, then previews the chapter’s topics.

4.1 Using password encoders · 4.1.1 The PasswordEncoder contract · 4.1.2 Implementing your PasswordEncoder · 4.1.3 Choosing from the provided PasswordEncoder implementations · 4.1.4 Multiple encoding strategies with DelegatingPasswordEncoder · 4.2 Taking advantage of the Spring Security Crypto module · 4.2.1 Using key generators · 4.2.2 Encrypting and decrypting secrets using encryptors · 4.3 Summary

What you learn in chapter 4 →

Chapter 5: A web app’s security begins with filters

This chapter introduction explains how Spring Security’s HTTP filters form a chain and why applications may need to customize it.

5.1 Implementing filters in the Spring Security architecture · 5.2 Adding a filter before an existing one in the chain · 5.3 Adding a filter after an existing one in the chain · 5.4 Adding a filter at the location of another in the chain · 5.5 Filter implementations provided by Spring Security · 5.6 Summary

What you learn in chapter 5 →

Chapter 6: Implementing authentications

Introduces where authentication decisions happen in Spring Security and what follows when a request is accepted or rejected.

6.1 Understanding the AuthenticationProvider · 6.1.1 Representing the request during authentication · 6.1.2 Implementing custom authentication logic · 6.1.3 Applying custom authentication logic · 6.2 Using the SecurityContext · 6.2.1 Using a holding strategy for the security context · 6.2.2 Using a holding strategy for asynchronous calls · 6.2.3 Using a holding strategy for standalone applications · 6.2.4 Forwarding the security context with DelegatingSecurityContextRunnable · 6.2.5 Forwarding the security context with DelegatingSecurityContextExecutorService · 6.3 Understanding HTTP Basic and form-based login authentications · 6.3.1 Using and configuring HTTP Basic · 6.3.2 Implementing authentication with form-based login · 6.4 Summary

What you learn in chapter 6 →

Chapter 7: Configuring endpoint-level authorization: Restricting access

This introduction distinguishes authorization from authentication and explains where an authorization filter acts on a request.

7.1 Restricting access based on authorities and roles · 7.1.1 Restricting access for all endpoints based on user authorities · 7.1.2 Restricting access for all endpoints based on user roles · 7.1.3 Restricting access to all endpoints · 7.2 Summary

What you learn in chapter 7 →

Chapter 8: Configuring endpoint-level authorization: Applying restrictions

This introduction explains why applications need authorization rules for different requests and identifies the basic purpose of two matcher methods.

8.1 Using the requestMatchers() method to select endpoints · 8.2 Selecting requests to apply authorization restrictions · 8.3 Using regular expressions with request matchers · 8.4 Summary

What you learn in chapter 8 →

Chapter 9: Configuring CSRF protection

Introduces the risk of CSRF attacks and explains why Spring Security’s default CSRF protection affected earlier HTTP POST examples.

9.1 How CSRF protection works in Spring Security · 9.2 Using CSRF protection in practical scenarios · 9.3 Customizing CSRF protection · 9.4 Summary

What you learn in chapter 9 →

Chapter 10: Configuring CORS

Introduces why browsers restrict cross-origin requests and why web applications may need CORS to permit them.

10.1 How does CORS work? · 10.2 Applying CORS policies with the @CrossOrigin annotation · 10.3 Applying CORS using a CorsConfigurer · 10.4 Summary

What you learn in chapter 10 →

Chapter 11: Implementing authorization at the method level

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

11.1 Enabling method security · 11.1.1 Understanding call authorization · 11.1.2 Enabling method security in your project · 11.2 Applying preauthorization rules · 11.3 Applying postauthorization rules · 11.4 Implementing permissions for methods · 11.5 Summary

What you learn in chapter 11 →

Chapter 12: Implementing filtering at the method level

The introduction explains how method-level filtering differs from call authorization, when prefiltering and postfiltering occur, and which parameter and return types they can filter.

12.1 Applying prefiltering for method authorization · 12.2 Applying postfiltering for method authorization · 12.3 Using filtering in Spring Data repositories · 12.4 Summary

What you learn in chapter 12 →

Chapter 13: What are OAuth 2 and OpenID Connect?

The introduction explains why applications may separate authentication from their own responsibilities and let users reuse credentials across apps.

13.1 The big picture of OAuth 2 and OpenID Connect · 13.2 Using various token implementations · 13.2.1 Using opaque tokens · 13.2.2 Using non-opaque tokens · 13.3 Obtaining tokens through various grant types · 13.3.1 Getting a token using the authorization code grant type · 13.3.2 Applying PKCE protection to the authorization code grant type · 13.3.3 Getting a token with the client credentials grant type · 13.3.4 Using refresh tokens to get new access tokens · 13.4 What OpenID Connect brings to OAuth 2 · 13.5 The sins of OAuth 2 · 13.6 Summary

What you learn in chapter 13 →

Chapter 14: Implementing an OAuth 2 authorization server

Introduces the authorization server’s role in OAuth 2 and identifies Spring Security’s current approach to implementing one.

14.1 Implementing basic authentication using JSON web tokens · 14.2 Running the authorization code grant type · 14.3 Running the client credentials grant type · 14.4 Using opaque tokens and introspection · 14.5 Revoking tokens · 14.6 Summary

What you learn in chapter 14 →

Chapter 15: Implementing an OAuth 2 resource server

The introduction identifies the OAuth 2 resource server as the backend that uses tokens from an authorization server and explains why its security must be implemented even when the authorization server is provided by a third party.

15.1 Configuring JWT validation · 15.2 Using customized JWTs · 15.3 Configuring token validation through introspection · 15.4 Implementing multitenant systems · 15.5 Summary

What you learn in chapter 15 →

Chapter 16: Implementing an OAuth 2 client

The introduction explains why a backend application may act as an OAuth 2 client when communicating with another backend application.

16.1 Implementing OAuth 2 login · 16.1.1 Implementing authentication with a common provider · 16.1.2 Giving the user more possibilities · 16.1.3 Using a custom authorization server · 16.1.4 Adding flexibility to your configurations · 16.1.5 Managing authorization for an OAuth 2 login · 16.2 Implementing an OAuth 2 client · 16.3 Summary

What you learn in chapter 16 →

Chapter 17: Implementing security in reactive applications

The introduction explains why reactive programming can help with divisible tasks and why securing reactive applications requires a different Spring Security approach.

17.1 What are reactive apps? · 17.2 User management in reactive apps · 17.3 Configuring authorization rules in reactive apps · 17.3.1 Applying authorization at the endpoint layer in reactive apps · 17.3.2 Using method security in reactive apps · 17.4 Creating a reactive OAuth 2 resource server · 17.5 Summary

What you learn in chapter 17 →

Chapter 18: Testing security configurations

The chapter introduction explains why regression tests and Spring Security integration tests are necessary when code or dependencies change.

18.1 Using mock users for tests · 18.2 Testing with users from a UserDetailsService · 18.3 Using custom Authentication objects for testing · 18.4 Testing method security · 18.5 Testing authentication · 18.6 Testing CSRF configurations · 18.7 Testing CORS configurations · 18.8 Testing reactive Spring Security implementations · 18.9 Summary

What you learn in chapter 18 →

Concepts explained in this book

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.