liveBook · Manning

NoOpPasswordEncoder

As explained in Spring Security in Action, Second Edition

NoOpPasswordEncoder is a Spring Security PasswordEncoder implementation that leaves passwords in cleartext instead of applying one-way encoding.

NoOpPasswordEncoder satisfies Spring Security’s PasswordEncoder contract by retaining passwords in cleartext rather than encoding them. It is suitable for learning examples and some proofs of concept, but not production applications. section 2.4 section 4.1.3

Its behavior is deliberately simple:

  • Leaves the supplied password unchanged instead of hashing or encrypting it. section 2.3.1
  • Matches credentials by comparing password strings with String.equals(Object). section 2.3.1
  • Exposes a singleton through NoOpPasswordEncoder.getInstance(); callers cannot invoke its constructor directly. section 4.1.3
  • Can provide the PasswordEncoder bean required after replacing Spring Security’s UserDetailsService. section 2.3.1

Minimal configuration

Register the singleton as a bean alongside an in-memory user whose password is 12345. Calling the endpoint with curl -u john:12345 then returns Hello!. section 2.3.1

PasswordEncoder p = NoOpPasswordEncoder.getInstance();

Shows the minimal PasswordEncoder declaration using the NoOpPasswordEncoder singleton. section 4.1.3

How Spring Security in Action, Second Edition covers it

How deep it goes
Defines cleartext matching and singleton retrieval, but stops short of hashing-algorithm treatment.
Examples
Uses a john user, password 12345, read authority, a PasswordEncoder bean, and a curl request returning Hello!.
What it assumes
Assumes basic Spring Security authentication components and teaches the required PasswordEncoder bean through a simple user configuration.
What you can do after
Apply it via Spring configuration to make a simple in-memory authentication example run.
How it connects
Connects PasswordEncoder with UserDetailsService, InMemoryUserDetailsManager, and authentication through AuthenticationProvider.

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.