Class 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 an 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:
    Serialized Form
    • 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 be null.
        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 be null.
      • 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 be null.
        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 be null.
        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 be null 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 or null, 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 class Control
        Returns:
        The user-friendly name for this control, or the OID if no user-friendly name is available.
      • toString

        public void toString​(java.lang.StringBuilder buffer)
        Appends a string representation of this LDAP control to the provided buffer.
        Overrides:
        toString in class Control
        Parameters:
        buffer - The buffer to which to append the string representation of this buffer.