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:
java.io.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 anResultCode.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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ASSERTION_REQUEST_OID
The OID (1.3.6.1.1.12) for the assertion request control.
-
Constructor Summary
Constructors Constructor Description AssertionRequestControl(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(java.lang.String filter)
Creates a new assertion request control with the provided filter.AssertionRequestControl(java.lang.String filter, boolean isCritical)
Creates a new assertion request control with the provided filter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static AssertionRequestControl
generate(Entry sourceEntry, java.lang.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.java.lang.String
getControlName()
Retrieves the user-friendly name for this control, if available.Filter
getFilter()
Retrieves the filter for this assertion control.void
toString(java.lang.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, deregisterDecodeableControl, encode, encodeControls, equals, getOID, getValue, hashCode, hasValue, isCritical, readFrom, registerDecodeableControl, toString, writeTo
-
-
-
-
Field Detail
-
ASSERTION_REQUEST_OID
public static final java.lang.String ASSERTION_REQUEST_OID
The OID (1.3.6.1.1.12) for the assertion request control.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AssertionRequestControl
public AssertionRequestControl(java.lang.String filter) throws LDAPException
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
public AssertionRequestControl(Filter filter)
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
public AssertionRequestControl(java.lang.String filter, boolean isCritical) throws LDAPException
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
public AssertionRequestControl(Filter filter, boolean isCritical)
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
public AssertionRequestControl(Control control) throws LDAPException
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 Detail
-
generate
public static AssertionRequestControl generate(Entry sourceEntry, java.lang.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 benull
and 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
public Filter getFilter()
Retrieves the filter for this assertion control.- Returns:
- The filter for this assertion control.
-
getControlName
public java.lang.String 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:
getControlName
in classControl
- Returns:
- The user-friendly name for this control, or the OID if no user-friendly name is available.
-
-