'How can PoolingContextSource be used with ldap BindAuthenticator for connection pooling

How can PoolingContextSource be used with ldap BindAuthenticator for connection pooling

@Bean
public AuthenticationProvider ldapAuthenticationProvider() throws Exception {
    DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(ldapUrl);
    contextSource.setUserDn(ldapSecurityPrincipal);
    contextSource.setPassword(ldapPrincipalPassword);
    contextSource.setReferral("follow");
    contextSource.afterPropertiesSet();
    
     PoolingContextSource poolingContextSource = new PoolingContextSource();
        poolingContextSource.setDirContextValidator(new DefaultDirContextValidator());
        poolingContextSource.setContextSource(contextSource);
        poolingContextSource.setTestOnBorrow(true);
        poolingContextSource.setTestWhileIdle(true);
        
    BindAuthenticator bindAuthenticator = new BindAuthenticator((BaseLdapPathContextSource) poolingContextSource);
    FilterBasedLdapUserSearch ldapUserSearch = new FilterBasedLdapUserSearch(searchBase, searchAttribute,
            contextSource);
    bindAuthenticator.setUserSearch(ldapUserSearch);
    LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(bindAuthenticator);
    return ldapAuthenticationProvider;
}

doesnt work. Springboot app itself doesnt start. Can someone help with right configuration?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source