'Springboot LDAP close user session

I am trying to close a user session opened through LDAP class after 5 seconds but it's not working and cannot figure out why. I am editing my class this way:

@Bean
public LdapContextSource contextSource() {
    LdapContextSource contextSource = new LdapContextSource();
    contextSource.setUrl(env.getProperty("ldap.url"));
    contextSource.setBase(env.getProperty("ldap.userSearchBase"));
    contextSource.setUserDn(env.getProperty("ldap.managerDn"));
    contextSource.setPassword(env.getProperty("ldap.managerPassword"));     
    
    contextSource.setPooled(false);
    Map<String, Object> environment = new HashMap<>();
    environment.put("com.sun.jndi.ldap.connect.timeout", "5000");
    environment.put("com.sun.jndi.ldap.read.timeout", "5000");
    contextSource.setBaseEnvironmentProperties(environment);
    contextSource.afterPropertiesSet();
    
    return contextSource;
}

Any idea why this is not working? thanks!



Sources

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

Source: Stack Overflow

Solution Source