diff --git a/core/src/main/java/org/springframework/ldap/core/support/AbstractContextSource.java b/core/src/main/java/org/springframework/ldap/core/support/AbstractContextSource.java index 552fdf82e..2a2909e97 100644 --- a/core/src/main/java/org/springframework/ldap/core/support/AbstractContextSource.java +++ b/core/src/main/java/org/springframework/ldap/core/support/AbstractContextSource.java @@ -119,10 +119,16 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource public static final String SUN_LDAP_POOLING_FLAG = "com.sun.jndi.ldap.connect.pool"; - private static final String JDK_142 = "1.4.2"; - private DirContextAuthenticationStrategy authenticationStrategy = new SimpleDirContextAuthenticationStrategy(); + public AbstractContextSource() { + try { + this.contextFactory = Class.forName(DEFAULT_CONTEXT_FACTORY); + } catch (ClassNotFoundException e) { + LOG.trace("The default for contextFactory cannot be resolved", e); + } + } + public DirContext getContext(String principal, String credentials) { // This method is typically called for authentication purposes, which means that we // should explicitly disable pooling in case passwords are changed (LDAP-183). @@ -407,7 +413,9 @@ public void afterPropertiesSet() { if (ObjectUtils.isEmpty(urls)) { throw new IllegalArgumentException("At least one server url must be set"); } - + if (contextFactory == null) { + throw new IllegalArgumentException("contextFactory must be set"); + } if (authenticationSource == null) { LOG.debug("AuthenticationSource not set - " + "using default implementation"); if (!StringUtils.hasText(userDn)) { @@ -438,7 +446,7 @@ private Hashtable setupAnonymousEnv() { Hashtable env = new Hashtable(baseEnv); - env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory != null ? contextFactory.getName() : DEFAULT_CONTEXT_FACTORY); + env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory.getName()); env.put(Context.PROVIDER_URL, assembleProviderUrlString(urls)); if (dirObjectFactory != null) {