Understanding how Spring LDAP authentication works
We saw that we were able to log in using a user-defined in the LDAP directory. But what exactly happens when a user issues a login request for a user in LDAP? There are the following three basic steps to the LDAP authentication process:
- Authenticate the credentials supplied by the user against the LDAP directory.
- Determine the
GrantedAuthority
object that the user has, based on their information in LDAP. - Pre-load information from the LDAP entry for the user into a custom
UserDetails
object for further use by the application.
Authenticating user credentials
For the first step, authentication against the LDAP directory, a custom authentication provider is wired into AuthenticationManager
. The o.s.s.ldap.authentication.LdapAuthenticationProvider
interface takes the user’s provided credentials and verifies them against the LDAP directory, as illustrated in the following diagram: