Search in sources :

Example 11 with BindResponseProtocolOp

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

the class LDAPDebuggerRequestHandler method processBindRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processBindRequest(final int messageID, @NotNull final BindRequestProtocolOp request, @NotNull final List<Control> controls) {
    final StringBuilder b = getBuffer();
    appendHeader(b, messageID);
    b.append("     Bind Request Protocol Op:").append(StaticUtils.EOL);
    b.append("          LDAP Version:  ").append(request.getVersion()).append(StaticUtils.EOL);
    b.append("          Bind DN:  ").append(request.getBindDN()).append(StaticUtils.EOL);
    switch(request.getCredentialsType()) {
        case BindRequestProtocolOp.CRED_TYPE_SIMPLE:
            b.append("          Credentials Type:  SIMPLE").append(StaticUtils.EOL);
            b.append("               Password:  ").append(request.getSimplePassword()).append(StaticUtils.EOL);
            break;
        case BindRequestProtocolOp.CRED_TYPE_SASL:
            b.append("          Credentials Type:  SASL").append(StaticUtils.EOL);
            b.append("               Mechanism:  ").append(request.getSASLMechanism()).append(StaticUtils.EOL);
            final ASN1OctetString saslCredentials = request.getSASLCredentials();
            if (saslCredentials != null) {
                b.append("               Encoded Credentials:");
                b.append(StaticUtils.EOL);
                StaticUtils.toHexPlusASCII(saslCredentials.getValue(), 20, b);
            }
            break;
    }
    appendControls(b, controls);
    logHandler.publish(new LogRecord(Level.INFO, b.toString()));
    logHandler.flush();
    final LDAPMessage responseMessage = requestHandler.processBindRequest(messageID, request, controls);
    b.setLength(0);
    appendHeader(b, responseMessage.getMessageID());
    b.append("     Bind Response Protocol Op:").append(StaticUtils.EOL);
    final BindResponseProtocolOp protocolOp = responseMessage.getBindResponseProtocolOp();
    appendResponse(b, protocolOp.getResultCode(), protocolOp.getDiagnosticMessage(), protocolOp.getMatchedDN(), protocolOp.getReferralURLs());
    final ASN1OctetString serverSASLCredentials = protocolOp.getServerSASLCredentials();
    if (serverSASLCredentials != null) {
        b.append("               Encoded Server SASL Credentials:");
        b.append(StaticUtils.EOL);
        StaticUtils.toHexPlusASCII(serverSASLCredentials.getValue(), 20, b);
    }
    appendControls(b, responseMessage.getControls());
    logHandler.publish(new LogRecord(Level.INFO, b.toString()));
    logHandler.flush();
    return responseMessage;
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) BindResponseProtocolOp(com.unboundid.ldap.protocol.BindResponseProtocolOp) LogRecord(java.util.logging.LogRecord) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) NotNull(com.unboundid.util.NotNull)

Example 12 with BindResponseProtocolOp

use of com.unboundid.ldap.protocol.BindResponseProtocolOp 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)

Example 13 with BindResponseProtocolOp

use of com.unboundid.ldap.protocol.BindResponseProtocolOp 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)

Aggregations

BindResponseProtocolOp (com.unboundid.ldap.protocol.BindResponseProtocolOp)13 LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)10 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)7 NotNull (com.unboundid.util.NotNull)7 Control (com.unboundid.ldap.sdk.Control)6 LDAPException (com.unboundid.ldap.sdk.LDAPException)5 BindRequestProtocolOp (com.unboundid.ldap.protocol.BindRequestProtocolOp)4 Test (org.testng.annotations.Test)4 SearchResultDoneProtocolOp (com.unboundid.ldap.protocol.SearchResultDoneProtocolOp)3 SimpleBindRequest (com.unboundid.ldap.sdk.SimpleBindRequest)3 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)3 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)3 LogRecord (java.util.logging.LogRecord)3 AddResponseProtocolOp (com.unboundid.ldap.protocol.AddResponseProtocolOp)2 CompareResponseProtocolOp (com.unboundid.ldap.protocol.CompareResponseProtocolOp)2 DeleteResponseProtocolOp (com.unboundid.ldap.protocol.DeleteResponseProtocolOp)2 ExtendedResponseProtocolOp (com.unboundid.ldap.protocol.ExtendedResponseProtocolOp)2 ModifyDNResponseProtocolOp (com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp)2 ModifyResponseProtocolOp (com.unboundid.ldap.protocol.ModifyResponseProtocolOp)2 SearchRequestProtocolOp (com.unboundid.ldap.protocol.SearchRequestProtocolOp)2