|
1 | 1 | /*
|
2 |
| - * Copyright 2005-2020 the original author or authors. |
| 2 | + * Copyright 2005-2021 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -123,6 +123,14 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
123 | 123 |
|
124 | 124 | private DirContextAuthenticationStrategy authenticationStrategy = new SimpleDirContextAuthenticationStrategy();
|
125 | 125 |
|
| 126 | + public AbstractContextSource() { |
| 127 | + try { |
| 128 | + contextFactory = Class.forName(DEFAULT_CONTEXT_FACTORY); |
| 129 | + } catch (ClassNotFoundException e) { |
| 130 | + LOG.trace("The default for contextFactory cannot be resolved", e); |
| 131 | + } |
| 132 | + } |
| 133 | + |
126 | 134 | public DirContext getContext(String principal, String credentials) {
|
127 | 135 | // This method is typically called for authentication purposes, which means that we
|
128 | 136 | // should explicitly disable pooling in case passwords are changed (LDAP-183).
|
@@ -407,7 +415,9 @@ public void afterPropertiesSet() {
|
407 | 415 | if (ObjectUtils.isEmpty(urls)) {
|
408 | 416 | throw new IllegalArgumentException("At least one server url must be set");
|
409 | 417 | }
|
410 |
| - |
| 418 | + if (contextFactory == null) { |
| 419 | + throw new IllegalArgumentException("contextFactory must be set"); |
| 420 | + } |
411 | 421 | if (authenticationSource == null) {
|
412 | 422 | LOG.debug("AuthenticationSource not set - " + "using default implementation");
|
413 | 423 | if (!StringUtils.hasText(userDn)) {
|
@@ -438,7 +448,7 @@ private Hashtable<String, Object> setupAnonymousEnv() {
|
438 | 448 |
|
439 | 449 | Hashtable<String, Object> env = new Hashtable<String, Object>(baseEnv);
|
440 | 450 |
|
441 |
| - env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory != null ? contextFactory.getName() : DEFAULT_CONTEXT_FACTORY); |
| 451 | + env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory.getName()); |
442 | 452 | env.put(Context.PROVIDER_URL, assembleProviderUrlString(urls));
|
443 | 453 |
|
444 | 454 | if (dirObjectFactory != null) {
|
|
0 commit comments