liveBook · Manning

DelegatingPasswordEncoder

As explained in Spring Security in Action, Second Edition

DelegatingPasswordEncoder is a Spring Security PasswordEncoder implementation that selects another password encoder according to an identifier in the stored password representation.

DelegatingPasswordEncoder supports applications that must retain existing password hashes while adopting a different algorithm for newly registered users. It implements PasswordEncoder but delegates encoding and matching to another encoder selected from an identifier embedded in the stored representation. section 4.1.4

Its routing model is explicit:

  • Store a prefix such as {noop}, {bcrypt}, or {scrypt} before the encoded password. section 4.1.4
  • Map each identifier to a PasswordEncoder implementation. section 4.1.4

Spring configuration

Create a map containing NoOpPasswordEncoder, BCryptPasswordEncoder, and SCryptPasswordEncoder, then return new DelegatingPasswordEncoder("bcrypt", encoders). Spring also provides PasswordEncoderFactories.createDelegatingPasswordEncoder() for creating a delegating encoder.

How Spring Security in Action, Second Edition covers it

How deep it goes
Explains prefix-based delegation, encoder maps, and default selection, stopping short of encoder algorithm internals.
Examples
Uses noop, bcrypt, and scrypt prefixes alongside a Java configuration bean and a bcrypt-prefixed stored hash.
What it assumes
Assumes familiarity with Spring configuration and the PasswordEncoder contract.
What you can do after
Configure a Spring PasswordEncoder that routes matching and encoding operations to selected implementations.
How it connects
Connects PasswordEncoder with BCryptPasswordEncoder, SCryptPasswordEncoder, NoOpPasswordEncoder, and password hashing.

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.