I implemented LDAP authentication with Spring boot and Spring Security. The configuration is pretty straightforward.
@Configuration
protected static class AuthenticationConfiguration extends
GlobalAuthenticationConfigurerAdapter {
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(url);
contextSource.setUserDn(userDn);
contextSource.setPassword(userPass);
contextSource.setReferral("follow");
contextSource.afterPropertiesSet();
LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder> ldapAuthenticationProviderConfigurer = auth.ldapAuthentication();
ldapAuthenticationProviderConfigurer
.userDnPatterns("cn={0},ou=institution,ou=people")
.userSearchBase("")
.contextSource(contextSource);
}
}
Now I want to create a token based authentication, so that after first successful login, the server can simply validate requests by verifing the request header with the token created on server.
Since LDAP authentication is done with ldapAuthentiationProvider behind the scene, I am not sure how to obtain the user credentials from first login and how to send the token as a response to login. Should I inject a custom authentication success handler in the form login filter to create token based on user credentials? If so, how exactly can it be done?