Spring Security provides multiple PasswordEncoder
implementations with BCRYPT
as the recommended implementation.
However, the use-case of sharing an authentication database with an external
application, Dovecot, is examined in this article.
Dovecot uses an MD5-CRYPT
algorithm.
Complete javadoc is provided.
Reference
The actual encryption algorithm is captured in the Dovecot source file
password-scheme-md5crypt.c
.
Implementation
The implementation extends
DelegatingPasswordEncoder
to provide
decryption services for the other Spring Security supported password types.
Two inner classes, each subclasses of PasswordEncoder
,
provide MD5-CRYPT
and PLAIN
implementations.
The
MD5Crypt
inner class implementation is straightforward:
The
NoCrypt
implementation provides the methods for calculating salt and itoa64
conversion.
Spring Boot Application Integration
The PasswordEncoder
may be integrated with the
following @Configuration
:
and must be integrated with a UserDetailsService
in
a WebSecurityConfigurer
: