Skip to content

Commit

Permalink
Add a pooled referral connector
Browse files Browse the repository at this point in the history
Added a new ReusableRefeerralConnector interface that can be used to
provide a way of following referrals using a mechanism that doesn't
automatically close connections after they are used.  This allows
for the possibility that connections created for the purpose of
following referrals could be used for multiple referrals, rather
than always closing them after their first use as was previously the
case.  Also, added a new PooledReferralConnector implementation that
uses connection pools to maintain connections for following
referrals.
  • Loading branch information
dirmgr committed Aug 2, 2023
1 parent eb9b87f commit 1093ed7
Show file tree
Hide file tree
Showing 83 changed files with 7,472 additions and 769 deletions.
11 changes: 11 additions & 0 deletions docs/release-notes.html
Expand Up @@ -13,6 +13,17 @@ <h3>Version 6.0.10</h3>
</p>

<ul>
<li>
Added a new ReusableRefeerralConnector interface that can be used to provide a
way of following referrals using a mechanism that doesn't automatically close
connections after they are used. This allows for the possibility that
connections created for the purpose of following referrals could be used for
multiple referrals, rather than always closing them after their first use as was
previously the case. Also, added a new PooledReferralConnector implementation
that uses connection pools to maintain connections for following referrals.
<br><br>
</li>

<li>
Updated the PLAINBindRequest class to add an encodeCredentials method that can be
used to retrieve a properly encoded representation of the SASL credentials for a
Expand Down
12 changes: 12 additions & 0 deletions messages/unboundid-ldapsdk-ldap.properties
Expand Up @@ -919,4 +919,16 @@ ERR_JSON_CONTROL_VALUE_NOT_VALID_BASE64=Unable to decode JSON object {0} as \
base64-encoded data.
ERR_JSON_CONTROL_UNEXPECTED_FIELD=Unable to decode JSON object {0} as a valid \
control because it contains unexpected field ''{1}''.
ERR_REFERRAL_LIMIT_EXCEEDED=The referral hop limit was exceeded while \
attempting to process the request.
ERR_POOLED_REFERRAL_CONNECTOR_CLOSED=Unable to attempt to follow referral \
URL {0} because the associated pooled referral connector has already been \
closed.
ERR_REFERRAL_POOL_UNSUPPORTED_BIND_TYPE=Unable to use the pooled referral \
connector to follow referrals for connections that are authenticated with \
the {0} mechanism unless the referral connector is explicitly configured \
with a predefined bind request.
ERR_REFERRAL_POOL_CANNOT_CREATE_SSL_SOCKET_FACTORY=An error occurred while \
attempting to create an SSL socket factory to use when performing TLS \
negotiation: {0}

6 changes: 6 additions & 0 deletions src/com/unboundid/ldap/sdk/ANONYMOUSBindRequest.java
Expand Up @@ -207,6 +207,8 @@ protected BindResult process(@NotNull final LDAPConnection connection,
final int depth)
throws LDAPException
{
setReferralDepth(depth);

ASN1OctetString credentials = null;
if ((traceString != null) && (! traceString.isEmpty()))
{
Expand Down Expand Up @@ -254,6 +256,10 @@ public ANONYMOUSBindRequest duplicate(@Nullable final Control[] controls)
final ANONYMOUSBindRequest bindRequest =
new ANONYMOUSBindRequest(traceString, controls);
bindRequest.setResponseTimeoutMillis(getResponseTimeoutMillis(null));
bindRequest.setIntermediateResponseListener(
getIntermediateResponseListener());
bindRequest.setReferralDepth(getReferralDepth());
bindRequest.setReferralConnector(getReferralConnectorInternal());
return bindRequest;
}

Expand Down
79 changes: 6 additions & 73 deletions src/com/unboundid/ldap/sdk/AddRequest.java
Expand Up @@ -1055,6 +1055,8 @@ protected LDAPResult process(@NotNull final LDAPConnection connection,
final int depth)
throws LDAPException
{
setReferralDepth(depth);

if (connection.synchronousMode())
{
@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -1381,7 +1383,7 @@ private LDAPResult handleResponse(@NotNull final LDAPConnection connection,
result.getResponseControls());
}

return followReferral(result, connection, depth);
return ReferralHelper.handleReferral(this, result, connection);
}
else
{
Expand Down Expand Up @@ -1442,78 +1444,6 @@ private LDAPResult reconnectAndRetry(@NotNull final LDAPConnection connection,



/**
* Attempts to follow a referral to perform an add operation in the target
* server.
*
* @param referralResult The LDAP result object containing information about
* the referral to follow.
* @param connection The connection on which the referral was received.
* @param depth The number of referrals followed in the course of
* processing this request.
*
* @return The result of attempting to process the add operation by following
* the referral.
*
* @throws LDAPException If a problem occurs while attempting to establish
* the referral connection, sending the request, or
* reading the result.
*/
@NotNull()
private LDAPResult followReferral(@NotNull final LDAPResult referralResult,
@NotNull final LDAPConnection connection,
final int depth)
throws LDAPException
{
for (final String urlString : referralResult.getReferralURLs())
{
try
{
final LDAPURL referralURL = new LDAPURL(urlString);
final String host = referralURL.getHost();

if (host == null)
{
// We can't handle a referral in which there is no host.
continue;
}

final AddRequest addRequest;
if (referralURL.baseDNProvided())
{
addRequest = new AddRequest(referralURL.getBaseDN(), attributes,
getControls());
}
else
{
addRequest = this;
}

final LDAPConnection referralConn = getReferralConnector(connection).
getReferralConnection(referralURL, connection);
try
{
return addRequest.process(referralConn, (depth+1));
}
finally
{
referralConn.setDisconnectInfo(DisconnectType.REFERRAL, null, null);
referralConn.close();
}
}
catch (final LDAPException le)
{
Debug.debugException(le);
}
}

// If we've gotten here, then we could not follow any of the referral URLs,
// so we'll just return the original referral result.
return referralResult;
}



/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -1570,6 +1500,9 @@ public AddRequest duplicate(@Nullable final Control[] controls)
}

r.setResponseTimeoutMillis(getResponseTimeoutMillis(null));
r.setIntermediateResponseListener(getIntermediateResponseListener());
r.setReferralDepth(getReferralDepth());
r.setReferralConnector(getReferralConnectorInternal());

return r;
}
Expand Down
6 changes: 6 additions & 0 deletions src/com/unboundid/ldap/sdk/CRAMMD5BindRequest.java
Expand Up @@ -336,6 +336,8 @@ protected BindResult process(@NotNull final LDAPConnection connection,
final int depth)
throws LDAPException
{
setReferralDepth(depth);

unhandledCallbackMessages.clear();

final SaslClient saslClient;
Expand Down Expand Up @@ -456,6 +458,10 @@ public CRAMMD5BindRequest duplicate(@Nullable final Control[] controls)
final CRAMMD5BindRequest bindRequest =
new CRAMMD5BindRequest(authenticationID, password, controls);
bindRequest.setResponseTimeoutMillis(getResponseTimeoutMillis(null));
bindRequest.setIntermediateResponseListener(
getIntermediateResponseListener());
bindRequest.setReferralDepth(getReferralDepth());
bindRequest.setReferralConnector(getReferralConnectorInternal());
return bindRequest;
}

Expand Down
81 changes: 6 additions & 75 deletions src/com/unboundid/ldap/sdk/CompareRequest.java
Expand Up @@ -619,6 +619,8 @@ protected CompareResult process(@NotNull final LDAPConnection connection,
final int depth)
throws LDAPException
{
setReferralDepth(depth);

if (connection.synchronousMode())
{
@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -954,7 +956,7 @@ private CompareResult handleResponse(@NotNull final LDAPConnection connection,
result.getResponseControls());
}

return followReferral(result, connection, depth);
return ReferralHelper.handleReferral(this, result, connection);
}
else
{
Expand Down Expand Up @@ -1016,80 +1018,6 @@ private CompareResult reconnectAndRetry(



/**
* Attempts to follow a referral to perform a compare operation in the target
* server.
*
* @param referralResult The LDAP result object containing information about
* the referral to follow.
* @param connection The connection on which the referral was received.
* @param depth The number of referrals followed in the course of
* processing this request.
*
* @return The result of attempting to process the compare operation by
* following the referral.
*
* @throws LDAPException If a problem occurs while attempting to establish
* the referral connection, sending the request, or
* reading the result.
*/
@NotNull()
private CompareResult followReferral(
@NotNull final CompareResult referralResult,
@NotNull final LDAPConnection connection,
final int depth)
throws LDAPException
{
for (final String urlString : referralResult.getReferralURLs())
{
try
{
final LDAPURL referralURL = new LDAPURL(urlString);
final String host = referralURL.getHost();

if (host == null)
{
// We can't handle a referral in which there is no host.
continue;
}

final CompareRequest compareRequest;
if (referralURL.baseDNProvided())
{
compareRequest = new CompareRequest(referralURL.getBaseDN(),
attributeName, assertionValue,
getControls());
}
else
{
compareRequest = this;
}

final LDAPConnection referralConn = getReferralConnector(connection).
getReferralConnection(referralURL, connection);
try
{
return compareRequest.process(referralConn, depth+1);
}
finally
{
referralConn.setDisconnectInfo(DisconnectType.REFERRAL, null, null);
referralConn.close();
}
}
catch (final LDAPException le)
{
Debug.debugException(le);
}
}

// If we've gotten here, then we could not follow any of the referral URLs,
// so we'll just return the original referral result.
return referralResult;
}



/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -1176,6 +1104,9 @@ public CompareRequest duplicate(@Nullable final Control[] controls)
}

r.setResponseTimeoutMillis(getResponseTimeoutMillis(null));
r.setIntermediateResponseListener(getIntermediateResponseListener());
r.setReferralDepth(getReferralDepth());
r.setReferralConnector(getReferralConnectorInternal());

return r;
}
Expand Down
5 changes: 5 additions & 0 deletions src/com/unboundid/ldap/sdk/DIGESTMD5BindRequest.java
Expand Up @@ -462,6 +462,7 @@ protected BindResult process(@NotNull final LDAPConnection connection,
final int depth)
throws LDAPException
{
setReferralDepth(depth);
unhandledCallbackMessages.clear();


Expand Down Expand Up @@ -646,6 +647,10 @@ public DIGESTMD5BindRequest duplicate(@Nullable final Control[] controls)
final DIGESTMD5BindRequest bindRequest =
new DIGESTMD5BindRequest(properties, controls);
bindRequest.setResponseTimeoutMillis(getResponseTimeoutMillis(null));
bindRequest.setIntermediateResponseListener(
getIntermediateResponseListener());
bindRequest.setReferralDepth(getReferralDepth());
bindRequest.setReferralConnector(getReferralConnectorInternal());
return bindRequest;
}

Expand Down

0 comments on commit 1093ed7

Please sign in to comment.