25
25
import javax .naming .ldap .InitialLdapContext ;
26
26
import javax .naming .ldap .LdapContext ;
27
27
28
+ import org .apache .commons .lang3 .StringUtils ;
28
29
import org .apache .log4j .Logger ;
29
30
30
31
public class LdapContextFactory {
@@ -40,12 +41,10 @@ public LdapContextFactory(final LdapConfiguration ldapConfiguration) {
40
41
_ldapConfiguration = ldapConfiguration ;
41
42
}
42
43
43
- // TODO add optional domain (optional only for backwards compatibility)
44
44
public LdapContext createBindContext (Long domainId ) throws NamingException , IOException {
45
45
return createBindContext (null , domainId );
46
46
}
47
47
48
- // TODO add optional domain (optional only for backwards compatibility)
49
48
public LdapContext createBindContext (final String providerUrl , Long domainId ) throws NamingException , IOException {
50
49
final String bindPrincipal = _ldapConfiguration .getBindPrincipal (domainId );
51
50
final String bindPassword = _ldapConfiguration .getBindPassword (domainId );
@@ -80,9 +79,13 @@ private void enableSSL(final Hashtable<String, String> environment) {
80
79
81
80
private Hashtable <String , String > getEnvironment (final String principal , final String password , final String providerUrl , final boolean isSystemContext , Long domainId ) {
82
81
final String factory = _ldapConfiguration .getFactory ();
83
- final String url = providerUrl == null ? _ldapConfiguration .getProviderUrl (domainId ) : providerUrl ;
82
+ String url = providerUrl == null ? _ldapConfiguration .getProviderUrl (domainId ) : providerUrl ;
83
+ if (StringUtils .isEmpty (url ) && domainId != null ) {
84
+ //try a default ldap implementation
85
+ url = _ldapConfiguration .getProviderUrl (null );
86
+ }
84
87
85
- final Hashtable <String , String > environment = new Hashtable <String , String >();
88
+ final Hashtable <String , String > environment = new Hashtable <>();
86
89
87
90
environment .put (Context .INITIAL_CONTEXT_FACTORY , factory );
88
91
environment .put (Context .PROVIDER_URL , url );
0 commit comments