Skip to content

Commit

Permalink
Add support for the ForgeRock affinity control
Browse files Browse the repository at this point in the history
Added client-side support for the affinity request control as used
in the ForgeRock Directory Proxy Server, which allows explicitly
routing multiple related requests to the same backend server.
  • Loading branch information
dirmgr committed Jan 4, 2024
1 parent c21f2f8 commit 14f6731
Show file tree
Hide file tree
Showing 9 changed files with 465 additions and 5 deletions.
5 changes: 5 additions & 0 deletions docs/ldap-oid-reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -3870,6 +3870,11 @@ <h2>LDAP OID Reference</h2>
<td>Transaction ID Request Control</td>
<td>ForgeRock Directory Server</td>
</tr>
<tr>
<td>1.3.6.1.4.1.36733.2.1.5.2</td>
<td>Affinity Request Control</td>
<td>ForgeRock Directory Server</td>
</tr>
<tr>
<td>1.3.6.1.5.5.7.9.1</td>
<td><tt>dateOfBirth</tt> Attribute Type</td>
Expand Down
7 changes: 7 additions & 0 deletions docs/release-notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ <h3>Version 7.0.0</h3>
change sequence number (CSN) that the server has assigned to that operation.
<br><br>
</li>

<li>
Added client-side support for the affinity request control as used in the
ForgeRock Directory Proxy Server, which allows explicitly routing multiple
related requests to the same backend server.
<br><br>
</li>
</ul>

<p></p>
Expand Down
3 changes: 3 additions & 0 deletions messages/unboundid-ldapsdk-forgerock-controls.properties
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ INFO_CONTROL_NAME_CSN_REQUEST=Change Sequence Number Request Control
ERR_CSN_RESPONSE_NO_VALUE=The provided control cannot be decoded as a change \
sequence number response control because it does not have a value.
INFO_CONTROL_NAME_CSN_RESPONSE=Change Sequence Number Response Control
ERR_AFFINITY_REQUEST_MISSING_VALUE=The provided control cannot be decoded as \
an affinity request control because it does not have a value.
INFO_CONTROL_NAME_AFFINITY_REQUEST=Affinity Request Control
1 change: 1 addition & 0 deletions resource/oid-registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@
{ "oid":"1.3.6.1.4.1.30221.2.12.6", "name":"Exclude Groups from Get User Resource Limits", "type":"Feature", "origin":"Ping Identity Directory Server" }
{ "oid":"1.3.6.1.4.1.30221.2.12.7", "name":"Extended Matching Entry Count Response Data", "type":"Feature", "origin":"Ping Identity Directory Server" }
{ "oid":"1.3.6.1.4.1.36733.2.1.5.1", "name":"Transaction ID", "type":"Request Control", "origin":"ForgeRock Directory Server" }
{ "oid":"1.3.6.1.4.1.36733.2.1.5.2", "name":"Affinity", "type":"Request Control", "origin":"ForgeRock Directory Server" }
{ "oid":"1.3.6.1.5.5.7.9.1", "name":"dateOfBirth", "type":"Attribute Type", "origin":"RFC 2985", "url":"https://docs.ldap.com/specs/rfc2985.txt" }
{ "oid":"1.3.6.1.5.5.7.9.2", "name":"placeOfBirth", "type":"Attribute Type", "origin":"RFC 2985", "url":"https://docs.ldap.com/specs/rfc2985.txt" }
{ "oid":"1.3.6.1.5.5.7.9.3", "name":"gender", "type":"Attribute Type", "origin":"RFC 2985", "url":"https://docs.ldap.com/specs/rfc2985.txt" }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
/*
* Copyright 2024 Ping Identity Corporation
* All Rights Reserved.
*/
/*
* Copyright 2024 Ping Identity Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Copyright (C) 2024 Ping Identity Corporation
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (GPLv2 only)
* or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses>.
*/
package com.unboundid.ldap.sdk.forgerockds.controls;



import com.unboundid.asn1.ASN1OctetString;
import com.unboundid.ldap.sdk.Control;
import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.ResultCode;
import com.unboundid.util.NotMutable;
import com.unboundid.util.NotNull;
import com.unboundid.util.StaticUtils;
import com.unboundid.util.ThreadSafety;
import com.unboundid.util.ThreadSafetyLevel;

import static com.unboundid.ldap.sdk.forgerockds.controls.ControlMessages.*;



/**
* This class provides an implementation of a control that can be used to
* establish an affinity for one or more operations through a ForgeRock
* Directory Proxy Server. The server will attempt to route operations with
* the same affinity value to the same backend server.
* <BR>
* This request control has an OID of 1.3.6.1.4.1.36733.2.1.5.2, and its value
* is the desired affinity value (which may be an arbitrary string or set of
* bytes, and the LDAP SDK may automatically generate an affinity value if none
* is provided). The criticality may be either true or false.
*/
@NotMutable()
@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
public final class AffinityRequestControl
extends Control
{
/**
* The OID (1.3.6.1.4.1.36733.2.1.5.2) for the affinity request control.
*/
@NotNull public static final String AFFINITY_REQUEST_OID =
"1.3.6.1.4.1.36733.2.1.5.2";



/**
* The serial version UID for this serializable class.
*/
private static final long serialVersionUID = 7792760251213801179L;



// The affinity value to use for this control.
@NotNull private final ASN1OctetString affinityValue;



/**
* Creates a new affinity request control with the specified criticality and
* a randomly generated affinity value.
*
* @param isCritical Indicates whether the control should be marked
* critical.
*/
public AffinityRequestControl(final boolean isCritical)
{
this(isCritical, new ASN1OctetString(StaticUtils.randomBytes(5, true)));
}



/**
* Creates a new affinity request control with the specified criticality and
* the provided affinity value.
*
* @param isCritical Indicates whether the control should be marked
* critical.
* @param affinityValue The affinity value to use for the control. It must
* not be {@code null}.
*/
public AffinityRequestControl(final boolean isCritical,
@NotNull final String affinityValue)
{
this(isCritical, new ASN1OctetString(affinityValue));
}



/**
* Creates a new affinity request control with the specified criticality and
* the provided affinity value.
*
* @param isCritical Indicates whether the control should be marked
* critical.
* @param affinityValue The affinity value to use for the control. It must
* not be {@code null}.
*/
public AffinityRequestControl(final boolean isCritical,
@NotNull final byte[] affinityValue)
{
this(isCritical, new ASN1OctetString(affinityValue));
}



/**
* Creates a new affinity request control with the specified criticality and
* the provided affinity value.
*
* @param isCritical Indicates whether the control should be marked
* critical.
* @param affinityValue The affinity value to use for the control. It must
* not be {@code null}.
*/
public AffinityRequestControl(final boolean isCritical,
@NotNull final ASN1OctetString affinityValue)
{
super(AFFINITY_REQUEST_OID, isCritical, affinityValue);

this.affinityValue = affinityValue;
}



/**
* Creates a new affinity request control that is decoded from
* the provided generic control.
*
* @param control The generic control to be decoded as an affinity request
* control.
*
* @throws LDAPException If the provided control cannot be decoded as an
* affinity request control.
*/
public AffinityRequestControl(@NotNull final Control control)
throws LDAPException
{
super(control);

affinityValue = control.getValue();
if (affinityValue == null)
{
throw new LDAPException(ResultCode.DECODING_ERROR,
ERR_AFFINITY_REQUEST_MISSING_VALUE.get());
}
}



/**
* Retrieves the affinity value for this control.
*
* @return The affinity value for this control.
*/
@NotNull()
public ASN1OctetString getAffinityValue()
{
return affinityValue;
}



/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public String getControlName()
{
return INFO_CONTROL_NAME_AFFINITY_REQUEST.get();
}



/**
* {@inheritDoc}
*/
@Override()
public void toString(@NotNull final StringBuilder buffer)
{
buffer.append("AffinityRequestControl(");

final byte[] affinityValueBytes = affinityValue.getValue();
if (StaticUtils.isLikelyDisplayableUTF8String(affinityValueBytes))
{
buffer.append("affinityValueString='");
buffer.append(affinityValue.stringValue());
}
else
{
buffer.append("affinityValueBytes='");
StaticUtils.toHex(affinityValueBytes, buffer);
}

buffer.append("')");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@


/**
* This class provides an implementation of a control which may be used to
* This class provides an implementation of a control that may be used to
* process an add, delete, modify, or modify DN operation in the ForgeRock
* Directory Server which will not be replicated to other servers. This control
* Directory Server that will not be replicated to other servers. This control
* is primarily intended for use in manually resolving replication conflicts.
* <BR>
* This request control has an OID of 1.3.6.1.4.1.26027.1.5.2 and a criticality
Expand Down Expand Up @@ -115,7 +115,7 @@ public ReplicationRepairRequestControl(final boolean isCritical)


/**
* Creates a new replication repair request control which is decoded from
* Creates a new replication repair request control that is decoded from
* the provided generic control.
*
* @param control The generic control to be decoded as a replication repair
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ public final class TransactionIDRequestControl
extends Control
{
/**
* The OID (1.3.6.1.4.1.36733.2.1.5.1) for the replication repair request
* control.
* The OID (1.3.6.1.4.1.36733.2.1.5.1) for the transaction ID request control.
*/
@NotNull public static final String TRANSACTION_ID_REQUEST_OID =
"1.3.6.1.4.1.36733.2.1.5.1";
Expand Down
25 changes: 25 additions & 0 deletions src/com/unboundid/util/StaticUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,31 @@ public static boolean isLikelyDisplayableCharacter(final int codePoint)



/**
* Indicates whether the provided byte array represents a valid UTF-8 string
* that is comprised entirely of characters that are believed to be
* displayable (as determined by the {@link #isLikelyDisplayableCharacter}
* method).
*
* @param b The byte array for which to make the determination. It must not
* be {@code null}.
*
* @return {@code true} if the provided byte array represents a valid UTF-8
* string that is believed to be displayable, or {@code false} if
* not.
*/
public static boolean isLikelyDisplayableUTF8String(@NotNull final byte[] b)
{
if (! isValidUTF8(b))
{
return false;
}

return isLikelyDisplayableString(toUTF8String(b));
}



/**
*Indicates whether the provided string is comprised entirely of characters
* that are believed to be displayable (as determined by the
Expand Down
Loading

0 comments on commit 14f6731

Please sign in to comment.