Package com.unboundid.ldap.sdk.controls
Class AssertionRequestControl
java.lang.Object
com.unboundid.ldap.sdk.Control
com.unboundid.ldap.sdk.controls.AssertionRequestControl
- All Implemented Interfaces:
Serializable
@NotMutable
@ThreadSafety(level=COMPLETELY_THREADSAFE)
public final class AssertionRequestControl
extends Control
This class provides an implementation of the LDAP assertion request control
as defined in RFC 4528. It
may be used in conjunction with an add, compare, delete, modify, modify DN,
or search operation. The assertion control includes a search filter, and the
associated operation should only be allowed to continue if the target entry
matches the provided filter. If the filter does not match the target entry,
then the operation should fail with an
The behavior of the assertion request control makes it ideal for atomic "check and set" types of operations, particularly when modifying an entry. For example, it can be used to ensure that when changing the value of an attribute, the current value has not been modified since it was last retrieved.
ResultCode.ASSERTION_FAILED result.
The behavior of the assertion request control makes it ideal for atomic "check and set" types of operations, particularly when modifying an entry. For example, it can be used to ensure that when changing the value of an attribute, the current value has not been modified since it was last retrieved.
Example
The following example demonstrates the use of the assertion request control. It shows an attempt to modify an entry's "accountBalance" attribute to set the value to "543.21" only if the current value is "1234.56":
Modification mod = new Modification(ModificationType.REPLACE,
"accountBalance", "543.21");
ModifyRequest modifyRequest =
new ModifyRequest("uid=john.doe,ou=People,dc=example,dc=com", mod);
modifyRequest.addControl(
new AssertionRequestControl("(accountBalance=1234.56)"));
LDAPResult modifyResult;
try
{
modifyResult = connection.modify(modifyRequest);
// If we've gotten here, then the modification was successful.
}
catch (LDAPException le)
{
modifyResult = le.toLDAPResult();
ResultCode resultCode = le.getResultCode();
String errorMessageFromServer = le.getDiagnosticMessage();
if (resultCode == ResultCode.ASSERTION_FAILED)
{
// The modification failed because the account balance value wasn't
// what we thought it was.
}
else
{
// The modification failed for some other reason.
}
}
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe OID (1.3.6.1.1.12) for the assertion request control. -
Constructor Summary
ConstructorsConstructorDescriptionAssertionRequestControl(Control control) Creates a new assertion request control which is decoded from the provided generic control.AssertionRequestControl(Filter filter) Creates a new assertion request control with the provided filter.AssertionRequestControl(Filter filter, boolean isCritical) Creates a new assertion request control with the provided filter.AssertionRequestControl(String filter) Creates a new assertion request control with the provided filter.AssertionRequestControl(String filter, boolean isCritical) Creates a new assertion request control with the provided filter. -
Method Summary
Modifier and TypeMethodDescriptionstatic AssertionRequestControldecodeJSONControl(JSONObject controlObject, boolean strict) Attempts to decode the provided object as a JSON representation of an assertion request control.static AssertionRequestControlGenerates an assertion request control that may be used to help ensure that some or all of the attributes in the specified entry have not changed since it was read from the server.Retrieves the user-friendly name for this control, if available.Retrieves the filter for this assertion control.Retrieves a representation of this assertion request control as a JSON object.voidtoString(StringBuilder buffer) Appends a string representation of this LDAP control to the provided buffer.Methods inherited from class com.unboundid.ldap.sdk.Control
decode, decode, decodeControls, decodeJSONControl, deregisterDecodeableControl, encode, encodeControls, equals, getOID, getValue, hashCode, hasValue, isCritical, readFrom, registerDecodeableControl, registerDecodeableControl, toString, writeTo
-
Field Details
-
ASSERTION_REQUEST_OID
The OID (1.3.6.1.1.12) for the assertion request control.- See Also:
-
-
Constructor Details
-
AssertionRequestControl
Creates a new assertion request control with the provided filter. It will be marked as critical.- Parameters:
filter- The string representation of the filter for this assertion control. It must not benull.- Throws:
LDAPException- If the provided filter string cannot be decoded as a search filter.
-
AssertionRequestControl
Creates a new assertion request control with the provided filter. It will be marked as critical.- Parameters:
filter- The filter for this assertion control. It must not benull.
-
AssertionRequestControl
Creates a new assertion request control with the provided filter. It will be marked as critical.- Parameters:
filter- The string representation of the filter for this assertion control. It must not benull.isCritical- Indicates whether this control should be marked critical.- Throws:
LDAPException- If the provided filter string cannot be decoded as a search filter.
-
AssertionRequestControl
Creates a new assertion request control with the provided filter. It will be marked as critical.- Parameters:
filter- The filter for this assertion control. It must not benull.isCritical- Indicates whether this control should be marked critical.
-
AssertionRequestControl
Creates a new assertion request control which is decoded from the provided generic control.- Parameters:
control- The generic control to be decoded as an assertion request control.- Throws:
LDAPException- If the provided control cannot be decoded as an assertion request control.
-
-
Method Details
-
generate
@NotNull public static AssertionRequestControl generate(@NotNull Entry sourceEntry, @Nullable String... attributes) Generates an assertion request control that may be used to help ensure that some or all of the attributes in the specified entry have not changed since it was read from the server.- Parameters:
sourceEntry- The entry from which to take the attributes to include in the assertion request control. It must not benulland should have at least one attribute to be included in the generated filter.attributes- The names of the attributes to include in the assertion request control. If this is empty ornull, then all attributes in the provided entry will be used.- Returns:
- The generated assertion request control.
-
getFilter
Retrieves the filter for this assertion control.- Returns:
- The filter for this assertion control.
-
getControlName
Retrieves the user-friendly name for this control, if available. If no user-friendly name has been defined, then the OID will be returned.- Overrides:
getControlNamein classControl- Returns:
- The user-friendly name for this control, or the OID if no user-friendly name is available.
-
toJSONControl
Retrieves a representation of this assertion request control as a JSON object. The JSON object uses the following fields:-
oid-- A mandatory string field whose value is the object identifier for this control. For the assertion request control, the OID is "1.3.6.1.1.12". -
control-name-- An optional string field whose value is a human-readable name for this control. This field is only intended for descriptive purposes, and when decoding a control, theoidfield should be used to identify the type of control. -
criticality-- A mandatory Boolean field used to indicate whether this control is considered critical. -
value-base64-- An optional string field whose value is a base64-encoded representation of the raw value for this assertion request control. Exactly one of thevalue-base64andvalue-jsonfields must be present. -
value-json-- An optional JSON object field whose value is a user-friendly representation of the value for this assertion request control. Exactly one of thevalue-base64andvalue-jsonfields must be present, and if thevalue-jsonfield is used, then it will use the following fields:-
filter-- A mandatory string field whose value is a string representation of the assertion filter.
-
- Overrides:
toJSONControlin classControl- Returns:
- A JSON object that contains a representation of this control.
-
-
decodeJSONControl
@NotNull public static AssertionRequestControl decodeJSONControl(@NotNull JSONObject controlObject, boolean strict) throws LDAPException Attempts to decode the provided object as a JSON representation of an assertion request control.- Parameters:
controlObject- The JSON object to be decoded. It must not benull.strict- Indicates whether to use strict mode when decoding the provided JSON object. If this istrue, then this method will throw an exception if the provided JSON object contains any unrecognized fields. If this isfalse, then unrecognized fields will be ignored.- Returns:
- The assertion request control that was decoded from the provided JSON object.
- Throws:
LDAPException- If the provided JSON object cannot be parsed as a valid assertion request control.
-
toString
Appends a string representation of this LDAP control to the provided buffer.
-