Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/main/groovy/gldapo/GldapoDirectory.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -54,6 +56,7 @@ class GldapoDirectory implements SearchProvider {
* </ul>
*/
static final CONTEXT_SOURCE_PROPS = ["url", "urls", "base", "userDn", "password"]
static final POOLING_SOURCE_PROPS = ["maxActive", "maxIdle", "minIdle", "maxTotal", "timeBetweenEvictionRunsMillis", "minEvictableIdleTimeMillis", "whenExhaustedAction", "testWhileIdle", "testOnReturn"]

/**
*
Expand Down Expand Up @@ -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()
Expand All @@ -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
}

/**
Expand Down