liveBook · Manning

Chapter 2: Hello, Spring Security

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

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

After this chapter you will be able to

Section by section

Introduction

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

Key terms: Spring Boot, convention-over-configuration, autoconfiguration, monolithic architecture, service-oriented software architectures, boilerplate code

2.1 Starting your first project

Builds a minimal REST application to show Spring Security’s default protection and how to call its endpoint with HTTP Basic credentials.

Key terms: spring-boot-starter-web, spring-boot-starter-security, default configuration, user, HelloController, @RestController, @GetMapping, /hello, HTTP 401 Unauthorized, HTTP 403 Forbidden

2.2 The big picture of Spring Security class design

This section maps the main Spring Security authentication components, explains the defaults used in the first project, and relates HTTP Basic authentication to HTTPS.

Key terms: authentication filter, authentication manager, authentication provider, UserDetailsService, PasswordEncoder, security context, authentication data, thread-per-request, default credentials, in-memory

2.3 Overriding default configurations

This section explains why Spring Security offers multiple ways to override defaults and why consistent configuration style matters.

Key terms: beans in the Spring context, override various methods, maintainability, UserDetailsService, PasswordEncoder, authentication

2.3.1 Customizing user details management

This section shows how to replace Spring Boot’s default user-details service with an in-memory one and supply the user and password encoder needed for authentication.

Key terms: UserDetailsService, InMemoryUserDetailsManager, @Configuration, @Bean, Spring context, UserDetails, User, authority, PasswordEncoder, NoOpPasswordEncoder

2.3.2 Applying authorization at the endpoint level

This section shows how a SecurityFilterChain bean can override default endpoint security, then explains the configuration methods and Customizer objects used in the example.

Key terms: SecurityFilterChain, permitAll(), anyRequest(), httpBasic(), authorizeHttpRequests(), HTTP Basic, authentication, authorization, Customizer, functional interface

2.3.3 Configuring in different ways

This section shows an alternative way to configure user details and password handling, and explains when registering beans in the Spring context is more useful.

Key terms: SecurityFilterChain, UserDetailsService, PasswordEncoder, HttpSecurity, userDetailsService(), Spring context, beans, inject

2.3.4 Defining custom authentication logic

This section shows how to replace Spring Security’s default authentication logic with a custom AuthenticationProvider while keeping authentication responsibilities separate where practical.

Key terms: AuthenticationProvider, UserDetailsService, PasswordEncoder, authenticate(Authentication authentication), HttpSecurity, authenticationProvider(), loosely coupled, fine-grained responsibilities

2.3.5 Using multiple configuration classes

This section shows how to keep a growing security configuration readable by separating user management from web authorization into two configuration classes.

Key terms: UserManagementConfig, WebAuthorizationConfig, UserDetailsService, PasswordEncoder, SecurityFilterChain

2.4 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 1: Security today Chapter 3: Managing users →

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.