Class PostReadRequestControl

java.lang.Object
com.unboundid.ldap.sdk.Control
com.unboundid.ldap.sdk.controls.PostReadRequestControl
All Implemented Interfaces:
Serializable

This class provides an implementation of the LDAP post-read request control as defined in RFC 4527. It may be used to request that the server retrieve a copy of the target entry as it appeared immediately after processing an add, modify, or modify DN operation.

If this control is included in an add, modify, or modify DN request, then the corresponding response may include a PostReadResponseControl containing a version of the entry as it appeared after applying that change. Note that this response control will only be included if the operation was successful, so it will not be provided if the operation failed for some reason (e.g., if the change would have violated the server schema, or if the requester did not have sufficient permission to perform that operation).

The value of this control should contain a set of requested attributes to include in the entry that is returned. The server should treat this set of requested attributes exactly as it treats the requested attributes from a SearchRequest. As is the case with a search request, if no attributes are specified, then all user attributes will be included.

Example

The following example demonstrates the use of the pre-read and post-read controls. It will modify an entry to increment the value of the test-counter attribute by one, and will use the pre-read and post-read controls to determine what the previous and updated values are:
 // Create a modify request that we can use to increment the value of a
 // custom attribute named "test-counter".
 ModifyRequest modifyRequest = new ModifyRequest(
      "uid=test.user,ou=People,dc=example,dc=com",
      new Modification(ModificationType.INCREMENT,
           "test-counter", // The attribute to increment.
           "1")); // The amount by which to increment the value.

 // Update the modify request to add both pre-read and post-read request
 // controls to see what the entry value was before and after the change.
 // We only care about getting the test-counter attribute.
 modifyRequest.setControls(
      new PreReadRequestControl("test-counter"),
      new PostReadRequestControl("test-counter"));

 // Process the modify operation in the server.
 LDAPResult modifyResult;
 try
 {
   modifyResult = connection.modify(modifyRequest);
   // If we got here, then the modification should have been successful.
 }
 catch (LDAPException le)
 {
   // This indicates that the operation did not complete successfully.
   modifyResult = le.toLDAPResult();
   ResultCode resultCode = le.getResultCode();
   String errorMessageFromServer = le.getDiagnosticMessage();
 }
 LDAPTestUtils.assertResultCodeEquals(modifyResult, ResultCode.SUCCESS);

 // Get the pre-read and post-read response controls from the server and
 // retrieve the before and after values for the test-counter attribute.
 LDAPTestUtils.assertHasControl(modifyResult,
      PreReadResponseControl.PRE_READ_RESPONSE_OID);
 PreReadResponseControl preReadResponse =
      PreReadResponseControl.get(modifyResult);
 Integer beforeValue =
      preReadResponse.getEntry().getAttributeValueAsInteger("test-counter");

 LDAPTestUtils.assertHasControl(modifyResult,
      PostReadResponseControl.POST_READ_RESPONSE_OID);
 PostReadResponseControl postReadResponse =
      PostReadResponseControl.get(modifyResult);
 Integer afterValue =
      postReadResponse.getEntry().getAttributeValueAsInteger("test-counter");
 
See Also:
  • Field Details

  • Constructor Details

    • PostReadRequestControl

      public PostReadRequestControl(@Nullable String... attributes)
      Creates a new post-read request control that will retrieve the specified set of attributes from the target entry. It will be marked critical.
      Parameters:
      attributes - The set of attributes to retrieve from the target entry. It behaves in the same way as the set of requested attributes for a search operation. If this is empty or null, then all user attributes will be returned.
    • PostReadRequestControl

      public PostReadRequestControl(boolean isCritical, @Nullable String... attributes)
      Creates a new post-read request control that will retrieve the specified set of attributes from the target entry.
      Parameters:
      isCritical - Indicates whether this control should be marked critical.
      attributes - The set of attributes to retrieve from the target entry. It behaves in the same way as the set of requested attributes for a search operation. If this is empty or null, then all user attributes will be returned.
    • PostReadRequestControl

      Creates a new post-read request control which is decoded from the provided generic control.
      Parameters:
      control - The generic control to be decoded as a post-read request control.
      Throws:
      LDAPException - If the provided control cannot be decoded as a post-read request control.
  • Method Details

    • getAttributes

      Retrieves the set of attributes that will be requested for inclusion in the entry returned in the response control.
      Returns:
      The set of attributes that will be requested for inclusion in the entry returned in the response control, or an empty array if all user attributes should be returned.
    • 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.
    • toJSONControl

      Retrieves a representation of this post-read 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 post-read request control, the OID is "1.3.6.1.1.13.2".
      • 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, the oid field 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 post-read request control. Exactly one of the value-base64 and value-json fields must be present.
      • value-json -- An optional JSON object field whose value is a user-friendly representation of the value for this post-read request control. Exactly one of the value-base64 and value-json fields must be present, and if the value-json field is used, then it will use the following fields:
        • attributes -- An optional array field whose values are strings that represent the names of the attributes to include in the entry returned in the response control.
      Overrides:
      toJSONControl in class Control
      Returns:
      A JSON object that contains a representation of this control.
    • decodeJSONControl

      @NotNull public static PostReadRequestControl decodeJSONControl(@NotNull JSONObject controlObject, boolean strict) throws LDAPException
      Attempts to decode the provided object as a JSON representation of a post-read request control.
      Parameters:
      controlObject - The JSON object to be decoded. It must not be null.
      strict - Indicates whether to use strict mode when decoding the provided JSON object. If this is true, then this method will throw an exception if the provided JSON object contains any unrecognized fields. If this is false, then unrecognized fields will be ignored.
      Returns:
      The post-read request control that was decoded from the provided JSON object.
      Throws:
      LDAPException - If the provided JSON object cannot be parsed as a valid post-read request control.
    • toString

      public void toString(@NotNull 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.