我正在使用 Spring-ldap 连接池和 contextSource 的自定义实现,以使用 Oracle Internet Directory API 进行连接。这在 Eclipse 上独立测试时有效。但是,当部署在 tomcat 上时,它会因“不是 DirContext 的实例”而失败。如果我使用 Spring 中的 LdapContextSource,它工作正常 [但我的一些操作失败并使用 OID API 的上下文] 感谢任何帮助。下面是配置和代码
<!-- LDAP Connection pool configuration -->
<bean id="contextSource"
class="org.springframework.ldap.pool.factory.PoolingContextSource">
<property name="contextSource" ref="contextSourceTarget" />
<property name="dirContextValidator" ref="dirContextValidator" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="testWhileIdle" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="900000" />
<property name="minEvictableIdleTimeMillis" value="1800000" />
<property name="maxActive" value="8" />
<property name="minIdle" value="3" />
<property name="maxIdle" value="8" />
<property name="maxWait" value="30000" />
<property name="maxTotal" value="-1" />
<property name="whenExhaustedAction" value="0" />
</bean>
<bean id="dirContextValidator"
class="org.springframework.ldap.pool.validation.DefaultDirContextValidator" />
<bean id="contextSourceTarget" class="com.ticketmaster.platform.identity.core.dao.ldap.CustomLdapContextSource">
<property name="url" value="${ldap.url}" />
<property name="userDn" value="${ldap.username}" />
<property name="password" value="${ldap.password}" />
<property name="dirObjectFactory"
value="org.springframework.ldap.core.support.DefaultDirObjectFactory" />
<property name="pooled" value="false" />
</bean>
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" /> <!-- connection pool reference -->
</bean>
public class CustomLdapContextSource extends LdapContextSource {
@Override
protected DirContext getDirContextInstance(Hashtable environment) throws NamingException {
String url = (String) environment.get("java.naming.provider.url");
URL aURL = null;
InitialLdapContext ctx = null;
StringTokenizer st = new StringTokenizer(url, "://");
String protocol = st.nextToken();
String host = st.nextToken();
String port = st.nextToken();
ctx = ConnectionUtil.getDefaultDirCtx(host, port, userDn, password);
return ctx;
}