Search in sources :

Example 76 with LDAPMessage

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

the class ProxyRequestHandler method processCompareRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processCompareRequest(final int messageID, @NotNull final CompareRequestProtocolOp request, @NotNull final List<Control> controls) {
    final CompareRequest compareRequest = new CompareRequest(request.getDN(), request.getAttributeName(), request.getAssertionValue().getValue());
    if (!controls.isEmpty()) {
        compareRequest.setControls(controls);
    }
    compareRequest.setIntermediateResponseListener(this);
    LDAPResult compareResult;
    try {
        compareResult = ldapConnection.compare(compareRequest);
    } catch (final LDAPException le) {
        Debug.debugException(le);
        compareResult = le.toLDAPResult();
    }
    final CompareResponseProtocolOp compareResponseProtocolOp = new CompareResponseProtocolOp(compareResult.getResultCode().intValue(), compareResult.getMatchedDN(), compareResult.getDiagnosticMessage(), Arrays.asList(compareResult.getReferralURLs()));
    return new LDAPMessage(messageID, compareResponseProtocolOp, Arrays.asList(compareResult.getResponseControls()));
}
Also used : CompareRequest(com.unboundid.ldap.sdk.CompareRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) CompareResponseProtocolOp(com.unboundid.ldap.protocol.CompareResponseProtocolOp) NotNull(com.unboundid.util.NotNull)

Example 77 with LDAPMessage

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

the class AccessLogRequestHandler method processSearchRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processSearchRequest(final int messageID, @NotNull final SearchRequestProtocolOp request, @NotNull final List<Control> controls) {
    final long opID = nextOperationID.getAndIncrement();
    final StringBuilder b = getRequestHeader("SEARCH", opID, messageID);
    b.append(" base=\"");
    b.append(request.getBaseDN());
    b.append("\" scope=");
    b.append(request.getScope().intValue());
    b.append(" filter=\"");
    request.getFilter().toString(b);
    b.append("\" attrs=\"");
    final List<String> attrList = request.getAttributes();
    if (attrList.isEmpty()) {
        b.append("ALL");
    } else {
        final Iterator<String> iterator = attrList.iterator();
        while (iterator.hasNext()) {
            b.append(iterator.next());
            if (iterator.hasNext()) {
                b.append(',');
            }
        }
    }
    b.append('"');
    logHandler.publish(new LogRecord(Level.INFO, b.toString()));
    logHandler.flush();
    final AtomicLong l = new AtomicLong(0L);
    entryCounts.put(messageID, l);
    try {
        final long startTimeNanos = System.nanoTime();
        final LDAPMessage responseMessage = requestHandler.processSearchRequest(messageID, request, controls);
        final long eTimeNanos = System.nanoTime() - startTimeNanos;
        final SearchResultDoneProtocolOp protocolOp = responseMessage.getSearchResultDoneProtocolOp();
        generateResponse(b, "SEARCH", opID, messageID, protocolOp.getResultCode(), protocolOp.getDiagnosticMessage(), protocolOp.getMatchedDN(), protocolOp.getReferralURLs(), eTimeNanos);
        b.append(" entriesReturned=");
        b.append(l.get());
        logHandler.publish(new LogRecord(Level.INFO, b.toString()));
        logHandler.flush();
        return responseMessage;
    } finally {
        entryCounts.remove(messageID);
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) LogRecord(java.util.logging.LogRecord) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) SearchResultDoneProtocolOp(com.unboundid.ldap.protocol.SearchResultDoneProtocolOp) NotNull(com.unboundid.util.NotNull)

Example 78 with LDAPMessage

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

the class AccessLogRequestHandler method processModifyRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processModifyRequest(final int messageID, @NotNull final ModifyRequestProtocolOp request, @NotNull final List<Control> controls) {
    final long opID = nextOperationID.getAndIncrement();
    final StringBuilder b = getRequestHeader("MODIFY", opID, messageID);
    b.append(" dn=\"");
    b.append(request.getDN());
    b.append('"');
    logHandler.publish(new LogRecord(Level.INFO, b.toString()));
    logHandler.flush();
    final long startTimeNanos = System.nanoTime();
    final LDAPMessage responseMessage = requestHandler.processModifyRequest(messageID, request, controls);
    final long eTimeNanos = System.nanoTime() - startTimeNanos;
    final ModifyResponseProtocolOp protocolOp = responseMessage.getModifyResponseProtocolOp();
    generateResponse(b, "MODIFY", opID, messageID, protocolOp.getResultCode(), protocolOp.getDiagnosticMessage(), protocolOp.getMatchedDN(), protocolOp.getReferralURLs(), eTimeNanos);
    logHandler.publish(new LogRecord(Level.INFO, b.toString()));
    logHandler.flush();
    return responseMessage;
}
Also used : LogRecord(java.util.logging.LogRecord) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) ModifyResponseProtocolOp(com.unboundid.ldap.protocol.ModifyResponseProtocolOp) NotNull(com.unboundid.util.NotNull)

Example 79 with LDAPMessage

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

the class AccessLogRequestHandler method processModifyDNRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processModifyDNRequest(final int messageID, @NotNull final ModifyDNRequestProtocolOp request, @NotNull final List<Control> controls) {
    final long opID = nextOperationID.getAndIncrement();
    final StringBuilder b = getRequestHeader("MODDN", opID, messageID);
    b.append(" dn=\"");
    b.append(request.getDN());
    b.append("\" newRDN=\"");
    b.append(request.getNewRDN());
    b.append("\" deleteOldRDN=");
    b.append(request.deleteOldRDN());
    final String newSuperior = request.getNewSuperiorDN();
    if (newSuperior != null) {
        b.append(" newSuperior=\"");
        b.append(newSuperior);
        b.append('"');
    }
    logHandler.publish(new LogRecord(Level.INFO, b.toString()));
    logHandler.flush();
    final long startTimeNanos = System.nanoTime();
    final LDAPMessage responseMessage = requestHandler.processModifyDNRequest(messageID, request, controls);
    final long eTimeNanos = System.nanoTime() - startTimeNanos;
    final ModifyDNResponseProtocolOp protocolOp = responseMessage.getModifyDNResponseProtocolOp();
    generateResponse(b, "MODDN", opID, messageID, protocolOp.getResultCode(), protocolOp.getDiagnosticMessage(), protocolOp.getMatchedDN(), protocolOp.getReferralURLs(), eTimeNanos);
    logHandler.publish(new LogRecord(Level.INFO, b.toString()));
    logHandler.flush();
    return responseMessage;
}
Also used : LogRecord(java.util.logging.LogRecord) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) ModifyDNResponseProtocolOp(com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp) NotNull(com.unboundid.util.NotNull)

Example 80 with LDAPMessage

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

the class StartTLSRequestHandler method processExtendedRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processExtendedRequest(final int messageID, @NotNull final ExtendedRequestProtocolOp request, @NotNull final List<Control> controls) {
    if (request.getOID().equals(StartTLSExtendedRequest.STARTTLS_REQUEST_OID)) {
        try {
            // Make sure we can decode the request as a valid StartTLS request.
            final StartTLSExtendedRequest startTLSRequest = new StartTLSExtendedRequest(new ExtendedRequest(request.getOID(), request.getValue()));
            final OutputStream clearOutputStream = connection.convertToTLS(sslSocketFactory, requestClientCertificate, requireClientCertificate);
            final LDAPMessage responseMessage = new LDAPMessage(messageID, new ExtendedResponseProtocolOp(ResultCode.SUCCESS_INT_VALUE, null, null, null, null, null));
            final ASN1Buffer buffer = new ASN1Buffer();
            responseMessage.writeTo(buffer);
            try {
                buffer.writeTo(clearOutputStream);
                clearOutputStream.flush();
            } catch (final Exception e) {
                Debug.debugException(e);
                final LDAPException le = new LDAPException(ResultCode.LOCAL_ERROR, ERR_START_TLS_REQUEST_HANDLER_WRITE_RESPONSE_FAILURE.get(StaticUtils.getExceptionMessage(e)), e);
                connection.close(le);
                throw le;
            }
            return responseMessage;
        } catch (final LDAPException le) {
            Debug.debugException(le);
            return new LDAPMessage(messageID, new ExtendedResponseProtocolOp(le.getResultCode().intValue(), le.getMatchedDN(), le.getDiagnosticMessage(), StaticUtils.toList(le.getReferralURLs()), null, null), le.getResponseControls());
        }
    } else {
        return requestHandler.processExtendedRequest(messageID, request, controls);
    }
}
Also used : ExtendedResponseProtocolOp(com.unboundid.ldap.protocol.ExtendedResponseProtocolOp) LDAPException(com.unboundid.ldap.sdk.LDAPException) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) ExtendedRequest(com.unboundid.ldap.sdk.ExtendedRequest) StartTLSExtendedRequest(com.unboundid.ldap.sdk.extensions.StartTLSExtendedRequest) OutputStream(java.io.OutputStream) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) StartTLSExtendedRequest(com.unboundid.ldap.sdk.extensions.StartTLSExtendedRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) 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