Class ProxiedAuthorizationV2RequestControl

  • All Implemented Interfaces:
    java.io.Serializable

    @NotMutable
    @ThreadSafety(level=COMPLETELY_THREADSAFE)
    public final class ProxiedAuthorizationV2RequestControl
    extends Control
    This class provides an implementation of the proxied authorization V2 request control, as defined in RFC 4370. It may be used to request that the associated operation be performed as if it has been requested by some other user.

    The target authorization identity for this control is specified as an "authzId" value as described in section 5.2.1.8 of RFC 4513. That is, it should be either "dn:" followed by the distinguished name of the target user, or "u:" followed by the username. If the "u:" form is used, then the mechanism used to resolve the provided username to an entry may vary from server to server.

    This control may be used in conjunction with add, delete, compare, delete, extended, modify, modify DN, and search requests. In that case, the associated operation will be processed under the authority of the specified authorization identity rather than the identity associated with the client connection (i.e., the user as whom that connection is bound). Note that because of the inherent security risks associated with the use of the proxied authorization control, most directory servers which support its use enforce strict restrictions on the users that are allowed to request this control. If a user attempts to use the proxied authorization V2 request control and does not have sufficient permission to do so, then the server will return a failure response with the ResultCode.AUTHORIZATION_DENIED result code.

    There is no corresponding response control for this request control.

    Example

    The following example demonstrates the use of the proxied authorization V2 control to delete an entry under the authority of the user with username "alternate.user":
     // Create a delete request to delete an entry.  Include the proxied
     // authorization v2 request control in the delete request so that the
     // delete will be processed as the user with username "alternate.user"
     // instead of the user that's actually authenticated on the connection.
     DeleteRequest deleteRequest =
          new DeleteRequest("uid=test.user,ou=People,dc=example,dc=com");
     deleteRequest.addControl(new ProxiedAuthorizationV2RequestControl(
          "u:alternate.user"));
    
     LDAPResult deleteResult;
     try
     {
       deleteResult = connection.delete(deleteRequest);
       // If we got here, then the delete was successful.
     }
     catch (LDAPException le)
     {
       // The delete failed for some reason.  In addition to all of the normal
       // reasons a delete could fail (e.g., the entry doesn't exist, or has one
       // or more subordinates), proxied-authorization specific failures may
       // include that the authenticated user doesn't have permission to use the
       // proxied authorization control to impersonate the alternate user, that
       // the alternate user doesn't exist, or that the alternate user doesn't
       // have permission to perform the requested operation.
       deleteResult = le.toLDAPResult();
       ResultCode resultCode = le.getResultCode();
       String errorMessageFromServer = le.getDiagnosticMessage();
     }
     
    See Also:
    Serialized Form
    • Constructor Detail

      • ProxiedAuthorizationV2RequestControl

        public ProxiedAuthorizationV2RequestControl​(@NotNull
                                                    java.lang.String authorizationID)
        Creates a new proxied authorization V2 request control that will proxy as the specified user.
        Parameters:
        authorizationID - The authorization ID string that will be used to identify the user under whose authorization the associated operation should be performed. It may take one of three forms: it can be an empty string (to indicate that the operation should use anonymous authorization), a string that begins with "dn:" and is followed by the DN of the target user, or a string that begins with "u:" and is followed by the username for the target user (where the process of mapping the provided username to the corresponding entry will depend on the server configuration). It must not be null.
      • ProxiedAuthorizationV2RequestControl

        public ProxiedAuthorizationV2RequestControl​(@NotNull
                                                    Control control)
                                             throws LDAPException
        Creates a new proxied authorization v2 request control which is decoded from the provided generic control.
        Parameters:
        control - The generic control to be decoded as a proxied authorization v2 request control.
        Throws:
        LDAPException - If the provided control cannot be decoded as a proxied authorization v2 request control.
    • Method Detail

      • getAuthorizationID

        @NotNull
        public java.lang.String getAuthorizationID()
        Retrieves the authorization ID string that will be used to identify the user under whose authorization the associated operation should be performed.
        Returns:
        The authorization ID string that will be used to identify the user under whose authorization the associated operation should be performed.
      • getControlName

        @NotNull
        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.
      • toJSONControl

        @NotNull
        public JSONObject toJSONControl()
        Retrieves a representation of this proxied authorization v2 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 proxied authorization v2 request control, the OID is "2.16.840.1.113730.3.4.18".
        • 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 proxied authorization v2 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 proxied authorization v2 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:
          • authorization-id -- A mandatory string field whose value is an authorization ID that identifies the user as whom the request should be authorized.
        Overrides:
        toJSONControl in class Control
        Returns:
        A JSON object that contains a representation of this control.
      • decodeJSONControl

        @NotNull
        public static ProxiedAuthorizationV2RequestControl decodeJSONControl​(@NotNull
                                                                             JSONObject controlObject,
                                                                             boolean strict)
                                                                      throws LDAPException
        Attempts to decode the provided object as a JSON representation of a proxied authorization v2 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 proxied authorization v2 request control that was decoded from the provided JSON object.
        Throws:
        LDAPException - If the provided JSON object cannot be parsed as a valid proxied authorization v2 request control.
      • toString

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