2
votes

I'm using a combination of spring-ldap and spring-boot-starter security. I have configured the basic setup but stuck at passing username and password to be authenticated. Its always trying to authenticate the default creds specified in the application.properties. Is there anyway to do this properly by passing the creds given in the login form.

@Override protected void configure(AuthenticationManagerBuilder auth) throws Exception {

if(Boolean.parseBoolean(ldapEnabled)) {
    auth
            .ldapAuthentication()
            .contextSource()
            .url(ldapUrls + ldapBaseDn)
            .managerDn(ldapSecurityPrincipal)
            .managerPassword(ldapPrincipalPassword)
            .and()
            .userDnPatterns(ldapUserDnPattern);
}

}

ldap.urls= ldap://localhost:10389/
ldap.base.dn= ou=users,dc=example,dc=com
ldap.username= cn=test, ou=users,dc=example,dc=com
ldap.user.dn.pattern = cn={0}


ldap.partitionSuffix=dc=example,dc=com
ldap.partition=example
ldap.principal=uid=admin,ou=system
ldap.password=secret
ldap.port=10389
ldap.url=ldap://localhost:10389/
1

1 Answers

0
votes

I was able to fix this by using creating a bean that returns the user details context mapper as below.

@Bean
public UserDetailsContextMapper userDetailsContextMapper() {
    return new LdapUserDetailsMapper() {
        @Override
        public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<? extends GrantedAuthority> authorities) {
            UserDetails details = super.mapUserFromContext(ctx, username, authorities);
            return details;
        }
    };
}