Search in sources :

Example 71 with LDAPMessage

use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.

the class InMemoryRequestHandler method processTransactionRequest.

/**
 * Determines whether the provided set of controls includes a transaction
 * specification request control.  If so, then it will verify that it
 * references a valid transaction for the client.  If the request is part of a
 * valid transaction, then the transaction specification request control will
 * be removed and the request will be stashed in the client connection state
 * so that it can be retrieved and processed when the transaction is
 * committed.
 *
 * @param  messageID  The message ID for the request to be processed.
 * @param  request    The protocol op for the request to be processed.
 * @param  controls   The set of controls for the request to be processed.
 *
 * @return  The transaction ID for the associated transaction, or {@code null}
 *          if the request is not part of any transaction.
 *
 * @throws  LDAPException  If the transaction specification request control is
 *                         present but does not refer to a valid transaction
 *                         for the associated client connection.
 */
@SuppressWarnings("unchecked")
@Nullable()
private ASN1OctetString processTransactionRequest(final int messageID, @NotNull final ProtocolOp request, @NotNull final Map<String, Control> controls) throws LDAPException {
    final TransactionSpecificationRequestControl txnControl = (TransactionSpecificationRequestControl) controls.remove(TransactionSpecificationRequestControl.TRANSACTION_SPECIFICATION_REQUEST_OID);
    if (txnControl == null) {
        return null;
    }
    // See if the client has an active transaction.  If not, then fail.
    final ASN1OctetString txnID = txnControl.getTransactionID();
    final ObjectPair<ASN1OctetString, List<LDAPMessage>> txnInfo = (ObjectPair<ASN1OctetString, List<LDAPMessage>>) connectionState.get(TransactionExtendedOperationHandler.STATE_VARIABLE_TXN_INFO);
    if (txnInfo == null) {
        throw new LDAPException(ResultCode.UNAVAILABLE_CRITICAL_EXTENSION, ERR_MEM_HANDLER_TXN_CONTROL_WITHOUT_TXN.get(txnID.stringValue()));
    }
    // Make sure that the active transaction has a transaction ID that matches
    // the transaction ID from the control.  If not, then abort the existing
    // transaction and fail.
    final ASN1OctetString existingTxnID = txnInfo.getFirst();
    if (!txnID.stringValue().equals(existingTxnID.stringValue())) {
        connectionState.remove(TransactionExtendedOperationHandler.STATE_VARIABLE_TXN_INFO);
        connection.sendUnsolicitedNotification(new AbortedTransactionExtendedResult(existingTxnID, ResultCode.CONSTRAINT_VIOLATION, ERR_MEM_HANDLER_TXN_ABORTED_BY_CONTROL_TXN_ID_MISMATCH.get(existingTxnID.stringValue(), txnID.stringValue()), null, null, null));
        throw new LDAPException(ResultCode.UNAVAILABLE_CRITICAL_EXTENSION, ERR_MEM_HANDLER_TXN_CONTROL_ID_MISMATCH.get(txnID.stringValue(), existingTxnID.stringValue()));
    }
    // Stash the request in the transaction state information so that it will
    // be processed when the transaction is committed.
    txnInfo.getSecond().add(new LDAPMessage(messageID, request, new ArrayList<>(controls.values())));
    return txnID;
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TransactionSpecificationRequestControl(com.unboundid.ldap.sdk.controls.TransactionSpecificationRequestControl) ObjectPair(com.unboundid.util.ObjectPair) AbortedTransactionExtendedResult(com.unboundid.ldap.sdk.extensions.AbortedTransactionExtendedResult) Nullable(com.unboundid.util.Nullable)

Example 72 with LDAPMessage

use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.

the class InMemoryRequestHandler method modify.

/**
 * Processes the provided modify request.
 * <BR><BR>
 * This method may be used regardless of whether the server is listening for
 * client connections, and regardless of whether modify operations are allowed
 * in the server.
 *
 * @param  modifyRequest  The modify request to be processed.  It must not be
 *                        {@code null}.
 *
 * @return  The result of processing the modify operation.
 *
 * @throws  LDAPException  If the server rejects the modify request, or if a
 *                         problem is encountered while sending the request or
 *                         reading the response.
 */
@NotNull()
public LDAPResult modify(@NotNull final ModifyRequest modifyRequest) throws LDAPException {
    final ArrayList<Control> requestControlList = new ArrayList<>(modifyRequest.getControlList());
    requestControlList.add(new Control(OID_INTERNAL_OPERATION_REQUEST_CONTROL, false));
    final LDAPMessage responseMessage = processModifyRequest(1, new ModifyRequestProtocolOp(modifyRequest.getDN(), modifyRequest.getModifications()), requestControlList);
    final ModifyResponseProtocolOp modifyResponse = responseMessage.getModifyResponseProtocolOp();
    final LDAPResult ldapResult = new LDAPResult(responseMessage.getMessageID(), ResultCode.valueOf(modifyResponse.getResultCode()), modifyResponse.getDiagnosticMessage(), modifyResponse.getMatchedDN(), modifyResponse.getReferralURLs(), responseMessage.getControls());
    switch(modifyResponse.getResultCode()) {
        case ResultCode.SUCCESS_INT_VALUE:
        case ResultCode.NO_OPERATION_INT_VALUE:
            return ldapResult;
        default:
            throw new LDAPException(ldapResult);
    }
}
Also used : ModifyRequestProtocolOp(com.unboundid.ldap.protocol.ModifyRequestProtocolOp) VirtualListViewRequestControl(com.unboundid.ldap.sdk.controls.VirtualListViewRequestControl) SubtreeDeleteRequestControl(com.unboundid.ldap.sdk.controls.SubtreeDeleteRequestControl) RFC3672SubentriesRequestControl(com.unboundid.ldap.sdk.controls.RFC3672SubentriesRequestControl) SimplePagedResultsControl(com.unboundid.ldap.sdk.controls.SimplePagedResultsControl) VirtualListViewResponseControl(com.unboundid.ldap.sdk.controls.VirtualListViewResponseControl) TransactionSpecificationRequestControl(com.unboundid.ldap.sdk.controls.TransactionSpecificationRequestControl) DraftZeilengaLDAPNoOp12RequestControl(com.unboundid.ldap.sdk.experimental.DraftZeilengaLDAPNoOp12RequestControl) PostReadRequestControl(com.unboundid.ldap.sdk.controls.PostReadRequestControl) ProxiedAuthorizationV1RequestControl(com.unboundid.ldap.sdk.controls.ProxiedAuthorizationV1RequestControl) ServerSideSortResponseControl(com.unboundid.ldap.sdk.controls.ServerSideSortResponseControl) PreReadResponseControl(com.unboundid.ldap.sdk.controls.PreReadResponseControl) AuthorizationIdentityResponseControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl) PermissiveModifyRequestControl(com.unboundid.ldap.sdk.controls.PermissiveModifyRequestControl) AuthorizationIdentityRequestControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl) Control(com.unboundid.ldap.sdk.Control) IgnoreNoUserModificationRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.IgnoreNoUserModificationRequestControl) ProxiedAuthorizationV2RequestControl(com.unboundid.ldap.sdk.controls.ProxiedAuthorizationV2RequestControl) ServerSideSortRequestControl(com.unboundid.ldap.sdk.controls.ServerSideSortRequestControl) PostReadResponseControl(com.unboundid.ldap.sdk.controls.PostReadResponseControl) DontUseCopyRequestControl(com.unboundid.ldap.sdk.controls.DontUseCopyRequestControl) AssertionRequestControl(com.unboundid.ldap.sdk.controls.AssertionRequestControl) ManageDsaITRequestControl(com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl) DraftLDUPSubentriesRequestControl(com.unboundid.ldap.sdk.controls.DraftLDUPSubentriesRequestControl) PreReadRequestControl(com.unboundid.ldap.sdk.controls.PreReadRequestControl) LDAPException(com.unboundid.ldap.sdk.LDAPException) ArrayList(java.util.ArrayList) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) ModifyResponseProtocolOp(com.unboundid.ldap.protocol.ModifyResponseProtocolOp) NotNull(com.unboundid.util.NotNull)

Example 73 with LDAPMessage

use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.

the class ProxyRequestHandler method processDeleteRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processDeleteRequest(final int messageID, @NotNull final DeleteRequestProtocolOp request, @NotNull final List<Control> controls) {
    final DeleteRequest deleteRequest = new DeleteRequest(request.getDN());
    if (!controls.isEmpty()) {
        deleteRequest.setControls(controls);
    }
    deleteRequest.setIntermediateResponseListener(this);
    LDAPResult deleteResult;
    try {
        deleteResult = ldapConnection.delete(deleteRequest);
    } catch (final LDAPException le) {
        Debug.debugException(le);
        deleteResult = le.toLDAPResult();
    }
    final DeleteResponseProtocolOp deleteResponseProtocolOp = new DeleteResponseProtocolOp(deleteResult.getResultCode().intValue(), deleteResult.getMatchedDN(), deleteResult.getDiagnosticMessage(), Arrays.asList(deleteResult.getReferralURLs()));
    return new LDAPMessage(messageID, deleteResponseProtocolOp, Arrays.asList(deleteResult.getResponseControls()));
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) DeleteResponseProtocolOp(com.unboundid.ldap.protocol.DeleteResponseProtocolOp) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) DeleteRequest(com.unboundid.ldap.sdk.DeleteRequest) NotNull(com.unboundid.util.NotNull)

Example 74 with LDAPMessage

use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.

the class ProxyRequestHandler method processAddRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processAddRequest(final int messageID, @NotNull final AddRequestProtocolOp request, @NotNull final List<Control> controls) {
    final AddRequest addRequest = new AddRequest(request.getDN(), request.getAttributes());
    if (!controls.isEmpty()) {
        addRequest.setControls(controls);
    }
    addRequest.setIntermediateResponseListener(this);
    LDAPResult addResult;
    try {
        addResult = ldapConnection.add(addRequest);
    } catch (final LDAPException le) {
        Debug.debugException(le);
        addResult = le.toLDAPResult();
    }
    final AddResponseProtocolOp addResponseProtocolOp = new AddResponseProtocolOp(addResult.getResultCode().intValue(), addResult.getMatchedDN(), addResult.getDiagnosticMessage(), Arrays.asList(addResult.getReferralURLs()));
    return new LDAPMessage(messageID, addResponseProtocolOp, Arrays.asList(addResult.getResponseControls()));
}
Also used : AddRequest(com.unboundid.ldap.sdk.AddRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) AddResponseProtocolOp(com.unboundid.ldap.protocol.AddResponseProtocolOp) NotNull(com.unboundid.util.NotNull)

Example 75 with LDAPMessage

use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.

the class ProxyRequestHandler method processBindRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processBindRequest(final int messageID, @NotNull final BindRequestProtocolOp request, @NotNull final List<Control> controls) {
    final Control[] controlArray;
    if ((controls == null) || (controls.isEmpty())) {
        controlArray = StaticUtils.NO_CONTROLS;
    } else {
        controlArray = new Control[controls.size()];
        controls.toArray(controlArray);
    }
    final BindRequest bindRequest;
    if (request.getCredentialsType() == BindRequestProtocolOp.CRED_TYPE_SIMPLE) {
        bindRequest = new SimpleBindRequest(request.getBindDN(), request.getSimplePassword().getValue(), controlArray);
    } else {
        bindRequest = new GenericSASLBindRequest(request.getBindDN(), request.getSASLMechanism(), request.getSASLCredentials(), controlArray);
    }
    bindRequest.setIntermediateResponseListener(this);
    LDAPResult bindResult;
    try {
        bindResult = ldapConnection.bind(bindRequest);
    } catch (final LDAPException le) {
        Debug.debugException(le);
        bindResult = le.toLDAPResult();
    }
    final BindResponseProtocolOp bindResponseProtocolOp = new BindResponseProtocolOp(bindResult.getResultCode().intValue(), bindResult.getMatchedDN(), bindResult.getDiagnosticMessage(), Arrays.asList(bindResult.getReferralURLs()), null);
    return new LDAPMessage(messageID, bindResponseProtocolOp, Arrays.asList(bindResult.getResponseControls()));
}
Also used : Control(com.unboundid.ldap.sdk.Control) SimpleBindRequest(com.unboundid.ldap.sdk.SimpleBindRequest) BindResponseProtocolOp(com.unboundid.ldap.protocol.BindResponseProtocolOp) LDAPException(com.unboundid.ldap.sdk.LDAPException) GenericSASLBindRequest(com.unboundid.ldap.sdk.GenericSASLBindRequest) BindRequest(com.unboundid.ldap.sdk.BindRequest) GenericSASLBindRequest(com.unboundid.ldap.sdk.GenericSASLBindRequest) SimpleBindRequest(com.unboundid.ldap.sdk.SimpleBindRequest) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) NotNull(com.unboundid.util.NotNull)

Aggregations

LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)92 NotNull (com.unboundid.util.NotNull)72 LDAPException (com.unboundid.ldap.sdk.LDAPException)42 Control (com.unboundid.ldap.sdk.Control)25 LogRecord (java.util.logging.LogRecord)24 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)23 ArrayList (java.util.ArrayList)19 TransactionSpecificationRequestControl (com.unboundid.ldap.sdk.controls.TransactionSpecificationRequestControl)14 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)13 AssertionRequestControl (com.unboundid.ldap.sdk.controls.AssertionRequestControl)13 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)13 AuthorizationIdentityResponseControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl)13 DontUseCopyRequestControl (com.unboundid.ldap.sdk.controls.DontUseCopyRequestControl)13 DraftLDUPSubentriesRequestControl (com.unboundid.ldap.sdk.controls.DraftLDUPSubentriesRequestControl)13 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)13 PermissiveModifyRequestControl (com.unboundid.ldap.sdk.controls.PermissiveModifyRequestControl)13 PostReadRequestControl (com.unboundid.ldap.sdk.controls.PostReadRequestControl)13 PostReadResponseControl (com.unboundid.ldap.sdk.controls.PostReadResponseControl)13 PreReadRequestControl (com.unboundid.ldap.sdk.controls.PreReadRequestControl)13 PreReadResponseControl (com.unboundid.ldap.sdk.controls.PreReadResponseControl)13