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
