liveBook · Manning

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

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

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

After this chapter you will be able to

What it builds on

Section by section

Introduction

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

Key terms: HTTP filters, filter chain, chain of responsibilities, custom filters, default configurations, HTTP Basic authentication

5.1 Implementing filters in the Spring Security architecture

This section explains how Spring Security filters process requests in an ordered chain, how configuration affects that chain, and where custom filters can be placed.

Key terms: Filter, jakarta.servlet, doFilter(), ServletRequest, ServletResponse, FilterChain, filter chain, httpBasic(), BasicAuthenticationFilter, CsrfFilter

5.2 Adding a filter before an existing one in the chain

Shows how to validate a required request header with a custom filter placed before authentication in Spring Security’s filter chain.

Key terms: RequestValidationFilter, Request-Id, doFilter(), HTTP 400 Bad Request, SecurityFilterChain, HttpSecurity, addFilterBefore(), BasicAuthenticationFilter

5.3 Adding a filter after an existing one in the chain

This section shows how to place a custom filter after an authentication filter to run post-authentication logic, using request logging as the example.

Key terms: filter chain, addFilterAfter(), HttpSecurity, authentication filter, successful authentication events, request ID, HTTP header, console

5.4 Adding a filter at the location of another in the chain

The section shows how to place a custom authentication filter at a known position in the Spring Security filter chain, using static-key authentication as an example.

Key terms: addFilterAt(), filter chain, BasicAuthenticationFilter, StaticKeyAuthenticationFilter, static key, Authorization header, 401 Unauthorized, HTTP Basic, symmetric keys, signature

5.5 Filter implementations provided by Spring Security

This section explains when to use Spring Security’s filter base classes, especially OncePerRequestFilter, instead of implementing Filter directly.

Key terms: OncePerRequestFilter, doFilterInternal(), filter chain, Filter, GenericFilterBean, web.xml, HttpServletRequest, HttpServletResponse, shouldNotFilter(HttpServletRequest), shouldNotFilterAsyncDispatch()

5.6 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 4: Managing passwords Chapter 6: Implementing authentications →

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.