liveBook · Manning

Customizer

As explained in Spring Security in Action, Second Edition

Customizer is a Spring configuration functional interface whose callback applies customization to a framework configuration object.

Customizer is a Spring Security functional interface whose callback applies configuration to a framework configuration object. HttpSecurity accepts it for authentication, authorization, CSRF, CORS, and other protection mechanisms. section 2.3.2

Because Customizer is functional, Java lambda expressions can implement it. Customizer.withDefaults() returns an implementation whose callback does nothing, preserving the selected feature’s defaults. section 2.3.2

Use a Customizer to configure a specific Spring Security feature:

  • Configure HTTP Basic authentication with httpBasic(Customizer.withDefaults()) or customize its realm name and authentication entry point. section 6.3.1
  • Configure endpoint authorization with authorizeHttpRequests(), selecting rules such as authenticated() or permitAll(). section 2.3.2
  • Configure CSRF protection with csrf(), including ignored paths, RequestMatcher objects, token repositories, and request handlers. section 9.3

Customizing HTTP Basic

A SecurityFilterChain can set a different HTTP Basic realm and replace the authentication failure handler: http.httpBasic(c -> { c.realmName("OTHER"); c.authenticationEntryPoint(new CustomEntryPoint()); }); The entry point can add a response header and return HTTP 401. section 6.3.1

@FunctionalInterface
public interface Customizer<T> {
 void customize(T t);

 static <T> Customizer<T> withDefaults() {
   return (t) -> {
   };
 }
}

Inspect the interface definition and its no-op withDefaults() implementation. section 2.3.2

Compared with older chaining syntax, Customizer callbacks make growing configurations easier to move into separate classes, improving maintainability and testability. section 2.3.2

How Spring Security in Action, Second Edition covers it

How deep it goes
Defines the functional contract, lambda usage, defaults, migration rationale, and practical HTTP Basic and CSRF customizations.
Examples
Uses withDefaults(), permitAll(), a custom HTTP Basic realm, AuthenticationEntryPoint, and CSRF path exclusions as concrete configurations.
What it assumes
Assumes basic Spring and Java configuration knowledge while teaching the functional interface, lambda callback, and framework-default relationship.
What you can do after
Apply it via Spring Security HttpSecurity methods to preserve defaults or configure authentication failures, authorization rules, and CSRF behavior.
How it connects
Connects HttpSecurity with HTTP Basic, endpoint authorization, CSRF protection, CORS, RequestMatcher, and AuthenticationEntryPoint.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Security in Action, Second Edition. The section links point to the parts of the book it draws on.