liveBook · Manning

Chapter 3: Managing users

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

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

After this chapter you will be able to

What it builds on

Section by section

Introduction

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

Key terms: contracts, interfaces, implementations, abstractions, UserDetails, GrantedAuthority, UserDetailsService, UserDetailsManager

3.1 Implementing authentication in Spring Security

This section locates user management in Spring Security’s authentication architecture and introduces the contracts for retrieving, managing, and representing users.

Key terms: authentication flow, user management part, UserDetailsService, PasswordEncoder, UserDetailsManager, interface segregation principle, UserDetails, GrantedAuthority, authorities, privileges

3.2 Describing the user

The section explains why an application’s user class must implement UserDetails for Spring Security to understand its users.

Key terms: UserDetails contract, user

3.2.1 Describing users with the UserDetails contract

This section explains how the UserDetails contract represents a user’s credentials, authorities, and account restrictions.

Key terms: UserDetails, getUsername(), getPassword(), authentication, authorization, authority, privilege, getAuthorities(), isAccountNonExpired(), isAccountNonLocked()

3.2.2 Detailing on the GrantedAuthority contract

Explains how Spring Security represents a user's privileges as authorities and how to create named GrantedAuthority instances.

Key terms: authorities, GrantedAuthority, getAuthority(), SimpleGrantedAuthority, lambda expression

3.2.3 Writing a minimal implementation of UserDetails

This section uses a fixed-value DummyUser to show what a UserDetails implementation supplies, then explains why a practical implementation needs to represent different users.

Key terms: DummyUser, UserDetails, getUsername(), getPassword(), getAuthorities(), GrantedAuthority, instances, username, password, attributes

3.2.4 Using a builder to create instances of the UserDetails type

This section shows how Spring Security’s User builder creates simple, immutable UserDetails instances without a custom implementation.

Key terms: User, UserDetails, User builder class, immutable, User.withUsername(String username), UserBuilder, build(), Function<String, String>, PasswordEncoder

3.2.5 Combining multiple responsibilities related to the user

The section shows how to keep database persistence and Spring Security user details separate by wrapping a JPA User entity in a SecurityUser adapter.

Key terms: JPA entity, UserDetails, responsibilities, SecurityUser, User

3.3 Instructing Spring Security on how to manage users

This introduction distinguishes describing a user from the component Spring Security delegates to for user management during authentication.

Key terms: UserDetails, UserDetailsService, authentication process, user management

3.3.1 Understanding the UserDetailsService contract

This subsection defines how UserDetailsService supplies user details during authentication and what happens when a username is not found.

Key terms: UserDetailsService, loadUserByUsername(String username), UserDetails, UsernameNotFoundException, AuthenticationException, RuntimeException, throws clause

3.3.2 Implementing the UserDetailsService contract

This section implements an in-memory UserDetailsService, registers it with Spring Security, and checks it through an endpoint.

Key terms: UserDetailsService, loadUserByUsername(String username), UserDetails, UsernameNotFoundException, bean, configuration class, cURL, HTTP 200 OK, 401 Unauthorized

3.3.3 Implementing the UserDetailsManager contract

This section explains how UserDetailsManager extends user lookup with user-management operations and shows how to use JDBC or LDAP implementations for authentication.

Key terms: UserDetailsManager, UserDetailsService, InMemoryUserDetailsManager, JdbcUserDetailsManager, JDBC, DataSource, users, authorities, enabled, queries

3.4 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 2: Hello, Spring Security Chapter 4: Managing passwords →

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.