Search in sources :

Example 6 with BindRequestProtocolOp

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

the class InMemoryOperationInterceptorRequestHandler method processBindRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processBindRequest(final int messageID, @NotNull final BindRequestProtocolOp request, @NotNull final List<Control> controls) {
    if (request.getCredentialsType() == BindRequestProtocolOp.CRED_TYPE_SIMPLE) {
        final InterceptedSimpleBindOperation op = new InterceptedSimpleBindOperation(connection, messageID, request, toArray(controls));
        activeOperations.put(messageID, op);
        try {
            for (final InMemoryOperationInterceptor i : interceptors) {
                try {
                    i.processSimpleBindRequest(op);
                } catch (final LDAPException le) {
                    Debug.debugException(le);
                    return new LDAPMessage(messageID, new BindResponseProtocolOp(le.toLDAPResult()), le.getResponseControls());
                } catch (final Exception e) {
                    Debug.debugException(e);
                    return new LDAPMessage(messageID, new BindResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_DS_INTERCEPTOR_REQUEST_ERROR.get(String.valueOf(op), i.getClass().getName(), StaticUtils.getExceptionMessage(e)), null, null));
                }
            }
            final LDAPMessage resultMessage = wrappedHandler.processBindRequest(messageID, new BindRequestProtocolOp(op.getRequest()), op.getRequest().getControlList());
            op.setResult(resultMessage.getBindResponseProtocolOp().toBindResult(toArray(resultMessage.getControls())));
            for (final InMemoryOperationInterceptor i : interceptors) {
                try {
                    i.processSimpleBindResult(op);
                } catch (final Exception e) {
                    Debug.debugException(e);
                    return new LDAPMessage(messageID, new BindResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_DS_INTERCEPTOR_RESULT_ERROR.get(String.valueOf(op), i.getClass().getName(), StaticUtils.getExceptionMessage(e)), null, null));
                }
            }
            return new LDAPMessage(messageID, new BindResponseProtocolOp(op.getResult()), op.getResult().getResponseControls());
        } finally {
            activeOperations.remove(messageID);
        }
    } else {
        final InterceptedSASLBindOperation op = new InterceptedSASLBindOperation(connection, messageID, request, toArray(controls));
        activeOperations.put(messageID, op);
        try {
            for (final InMemoryOperationInterceptor i : interceptors) {
                try {
                    i.processSASLBindRequest(op);
                } catch (final LDAPException le) {
                    Debug.debugException(le);
                    return new LDAPMessage(messageID, new BindResponseProtocolOp(le.toLDAPResult()), le.getResponseControls());
                } catch (final Exception e) {
                    Debug.debugException(e);
                    return new LDAPMessage(messageID, new BindResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_DS_INTERCEPTOR_REQUEST_ERROR.get(String.valueOf(op), i.getClass().getName(), StaticUtils.getExceptionMessage(e)), null, null));
                }
            }
            final LDAPMessage resultMessage = wrappedHandler.processBindRequest(messageID, new BindRequestProtocolOp(op.getRequest()), op.getRequest().getControlList());
            op.setResult(resultMessage.getBindResponseProtocolOp().toBindResult(toArray(resultMessage.getControls())));
            for (final InMemoryOperationInterceptor i : interceptors) {
                try {
                    i.processSASLBindResult(op);
                } catch (final Exception e) {
                    Debug.debugException(e);
                    return new LDAPMessage(messageID, new BindResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_DS_INTERCEPTOR_RESULT_ERROR.get(String.valueOf(op), i.getClass().getName(), StaticUtils.getExceptionMessage(e)), null, null));
                }
            }
            return new LDAPMessage(messageID, new BindResponseProtocolOp(op.getResult()), op.getResult().getResponseControls());
        } finally {
            activeOperations.remove(messageID);
        }
    }
}
Also used : BindResponseProtocolOp(com.unboundid.ldap.protocol.BindResponseProtocolOp) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) BindRequestProtocolOp(com.unboundid.ldap.protocol.BindRequestProtocolOp) LDAPException(com.unboundid.ldap.sdk.LDAPException) NotNull(com.unboundid.util.NotNull)

Example 7 with BindRequestProtocolOp

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

the class SASLBindRequest method sendBindRequest.

/**
 * Sends an LDAP message to the directory server and waits for the response.
 *
 * @param  connection       The connection to the directory server.
 * @param  bindDN           The bind DN to use for the request.  It should be
 *                          {@code null} for most types of SASL bind requests.
 * @param  saslCredentials  The SASL credentials to use for the bind request.
 *                          It may be {@code null} if no credentials are
 *                          required.
 * @param  controls         The set of controls to include in the request.  It
 *                          may be {@code null} if no controls are required.
 * @param  timeoutMillis    The maximum length of time in milliseconds to wait
 *                          for a response, or zero if it should wait forever.
 *
 * @return  The bind response message returned by the directory server.
 *
 * @throws  LDAPException  If a problem occurs while sending the request or
 *                         reading the response, or if a timeout occurred
 *                         while waiting for the response.
 */
@NotNull()
protected final BindResult sendBindRequest(@NotNull final LDAPConnection connection, @Nullable final String bindDN, @Nullable final ASN1OctetString saslCredentials, @Nullable final Control[] controls, final long timeoutMillis) throws LDAPException {
    messageID = connection.nextMessageID();
    final BindRequestProtocolOp protocolOp = new BindRequestProtocolOp(bindDN, getSASLMechanismName(), saslCredentials);
    final LDAPMessage requestMessage = new LDAPMessage(messageID, protocolOp, controls);
    return sendMessage(connection, requestMessage, timeoutMillis);
}
Also used : LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) BindRequestProtocolOp(com.unboundid.ldap.protocol.BindRequestProtocolOp) NotNull(com.unboundid.util.NotNull)

Aggregations

BindRequestProtocolOp (com.unboundid.ldap.protocol.BindRequestProtocolOp)7 LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)5 BindResponseProtocolOp (com.unboundid.ldap.protocol.BindResponseProtocolOp)4 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)3 BindResult (com.unboundid.ldap.sdk.BindResult)3 NotNull (com.unboundid.util.NotNull)3 Test (org.testng.annotations.Test)3 SearchRequestProtocolOp (com.unboundid.ldap.protocol.SearchRequestProtocolOp)2 SearchResultDoneProtocolOp (com.unboundid.ldap.protocol.SearchResultDoneProtocolOp)2 Control (com.unboundid.ldap.sdk.Control)2 LDAPException (com.unboundid.ldap.sdk.LDAPException)2 SimpleBindRequest (com.unboundid.ldap.sdk.SimpleBindRequest)2 ASN1Element (com.unboundid.asn1.ASN1Element)1 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)1 ASN1StreamReader (com.unboundid.asn1.ASN1StreamReader)1 AddRequestProtocolOp (com.unboundid.ldap.protocol.AddRequestProtocolOp)1 AddResponseProtocolOp (com.unboundid.ldap.protocol.AddResponseProtocolOp)1 CompareRequestProtocolOp (com.unboundid.ldap.protocol.CompareRequestProtocolOp)1 CompareResponseProtocolOp (com.unboundid.ldap.protocol.CompareResponseProtocolOp)1 DeleteRequestProtocolOp (com.unboundid.ldap.protocol.DeleteRequestProtocolOp)1