diff --git a/src/main/groovy/gldapo/GldapoDirectory.groovy b/src/main/groovy/gldapo/GldapoDirectory.groovy index 60a9aec..d1ea044 100644 --- a/src/main/groovy/gldapo/GldapoDirectory.groovy +++ b/src/main/groovy/gldapo/GldapoDirectory.groovy @@ -31,6 +31,8 @@ import org.springframework.ldap.NamingException import javax.naming.directory.ModificationItem import javax.naming.directory.Attributes import org.springframework.ldap.core.DistinguishedName +import org.springframework.ldap.pool.factory.PoolingContextSource +import org.springframework.ldap.pool.validation.DefaultDirContextValidator class GldapoDirectory implements SearchProvider { @@ -54,6 +56,7 @@ class GldapoDirectory implements SearchProvider { * */ static final CONTEXT_SOURCE_PROPS = ["url", "urls", "base", "userDn", "password"] + static final POOLING_SOURCE_PROPS = ["maxActive", "maxIdle", "minIdle", "maxTotal", "timeBetweenEvictionRunsMillis", "minEvictableIdleTimeMillis", "whenExhaustedAction", "testWhileIdle", "testOnReturn"] /** * @@ -100,6 +103,23 @@ class GldapoDirectory implements SearchProvider { contextSource.baseEnvironmentProperties = config.env } contextSource.afterPropertiesSet() + + if(config.containsKey("pooling")) { + def realSource = contextSource + realSource.pooled = false + contextSource = new PoolingContextSource() + contextSource.contextSource = realSource + if (config.pooling.validate) { + def validator = new DefaultDirContextValidator() + contextSource.dirContextValidator = validator + contextSource.testOnBorrow = true + } + POOLING_SOURCE_PROPS.each { + if(config.pooling.containsKey(it)) { + contextSource."$it" = config.pooling."$it" + } + } + } this.template = new LdapTemplate(contextSource: contextSource) this.template.afterPropertiesSet() @@ -114,7 +134,11 @@ class GldapoDirectory implements SearchProvider { * Returns the base DN for operations for this directory */ DistinguishedName getBase() { - template?.contextSource?.base + def contextSource = template?.contextSource + if (contextSource?.class == PoolingContextSource.class) { + return contextSource?.contextSource?.base + } + return contextSource?.base } /**