Source:
private DirContext createDirContext(String securityPrincipal, char[] securityCredential, ReferralMode mode) throws NamingException { Hashtable<String, String> env = new Hashtable<>(); env.put(InitialDirContext.INITIAL_CONTEXT_FACTORY, initialContextFactory); env.put(InitialDirContext.PROVIDER_URL, providerUrl); env.put(InitialDirContext.SECURITY_AUTHENTICATION, securityAuthentication); env.put(InitialDirContext.SECURITY_PRINCIPAL, securityPrincipal); env.put(InitialDirContext.SECURITY_CREDENTIALS, String.valueOf(securityCredential)); env.put(InitialDirContext.REFERRAL, mode == null ? ReferralMode.IGNORE.getValue() : mode.getValue()); if (socketFactory != null) env.put(SOCKET_FACTORY, ElytronSSLSocketFactory.class.getName()); env.put(CONNECT_TIMEOUT, Integer.toString(connectTimeout)); env.put(READ_TIMEOUT, Integer.toString(readTimeout)); if (connectionProperties != null) { for (Object key : connectionProperties.keySet()) { Object value = connectionProperties.get(key.toString()); if (value != null) { env.put(key.toString(), value.toString()); } } } if (log.isDebugEnabled()) { log.debugf("Creating [" + InitialDirContext.class + "] with environment:"); env.forEach((key, value) -> { log.debugf(" Property [%s] with Value [%s]", key, value); }); } InitialLdapContext initialContext; try { if (socketFactory != null) ElytronSSLSocketFactory.set(socketFactory); initialContext = new InitialLdapContext(env, null); } catch (NamingException ne) { log.debugf(ne, "Could not create [%s]. Failed to connect to LDAP server.", InitialLdapContext.class); throw ne; } finally { if (socketFactory != null) ElytronSSLSocketFactory.unset(); } log.debugf("[%s] successfully created. Connection established to LDAP server.", initialContext); return new DelegatingLdapContext(initialContext, this, (dirContext, controls) -> { if (socketFactory != null) ElytronSSLSocketFactory.set(socketFactory); try { log.debugf("Reconnecting"); dirContext.reconnect(controls); } finally { if (socketFactory != null) ElytronSSLSocketFactory.unset(); } }); }

Target:
private DirContext createDirContext(String securityPrincipal, char[] securityCredential, ReferralMode mode) throws NamingException { Hashtable<String, String> env = new Hashtable<>(); env.put(InitialDirContext.INITIAL_CONTEXT_FACTORY, initialContextFactory); env.put(InitialDirContext.PROVIDER_URL, providerUrl); env.put(InitialDirContext.SECURITY_AUTHENTICATION, securityAuthentication); env.put(InitialDirContext.SECURITY_PRINCIPAL, securityPrincipal); env.put(InitialDirContext.SECURITY_CREDENTIALS, String.valueOf(securityCredential)); env.put(InitialDirContext.REFERRAL, mode == null ? ReferralMode.IGNORE.getValue() : mode.getValue()); if (socketFactory != null) env.put(SOCKET_FACTORY, ThreadLocalSSLSocketFactory.class.getName()); env.put(CONNECT_TIMEOUT, Integer.toString(connectTimeout)); env.put(READ_TIMEOUT, Integer.toString(readTimeout)); if (connectionProperties != null) { for (Object key : connectionProperties.keySet()) { Object value = connectionProperties.get(key.toString()); if (value != null) { env.put(key.toString(), value.toString()); } } } if (log.isDebugEnabled()) { log.debugf("Creating [" + InitialDirContext.class + "] with environment:"); env.forEach((key, value) -> { log.debugf(" Property [%s] with Value [%s]", key, value); }); } InitialLdapContext initialContext; try { if (socketFactory != null) ThreadLocalSSLSocketFactory.set(socketFactory); initialContext = new InitialLdapContext(env, null); } catch (NamingException ne) { log.debugf(ne, "Could not create [%s]. Failed to connect to LDAP server.", InitialLdapContext.class); throw ne; } finally { if (socketFactory != null) ThreadLocalSSLSocketFactory.unset(); } log.debugf("[%s] successfully created. Connection established to LDAP server.", initialContext); return new DelegatingLdapContext(initialContext, this::returnContext, (ldapContext, controls) -> { if (socketFactory != null) ThreadLocalSSLSocketFactory.set(socketFactory); try { log.debugf("Reconnecting"); ldapContext.reconnect(controls); } finally { if (socketFactory != null) ThreadLocalSSLSocketFactory.unset(); } }); }