Search in sources :

Example 6 with CompareResponseProtocolOp

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

the class InMemoryDirectoryServer method compare.

/**
 * {@inheritDoc}
 * <BR><BR>
 * This method may be used regardless of whether the server is listening for
 * client connections, and regardless of whether compare operations are
 * allowed in the server.
 */
@Override()
@NotNull()
public CompareResult compare(@NotNull final CompareRequest compareRequest) throws LDAPException {
    final ArrayList<Control> requestControlList = new ArrayList<>(compareRequest.getControlList());
    requestControlList.add(new Control(InMemoryRequestHandler.OID_INTERNAL_OPERATION_REQUEST_CONTROL, false));
    final LDAPMessage responseMessage = inMemoryHandler.processCompareRequest(1, new CompareRequestProtocolOp(compareRequest.getDN(), compareRequest.getAttributeName(), compareRequest.getRawAssertionValue()), requestControlList);
    final CompareResponseProtocolOp compareResponse = responseMessage.getCompareResponseProtocolOp();
    final LDAPResult compareResult = new LDAPResult(responseMessage.getMessageID(), ResultCode.valueOf(compareResponse.getResultCode()), compareResponse.getDiagnosticMessage(), compareResponse.getMatchedDN(), compareResponse.getReferralURLs(), responseMessage.getControls());
    switch(compareResponse.getResultCode()) {
        case ResultCode.COMPARE_TRUE_INT_VALUE:
        case ResultCode.COMPARE_FALSE_INT_VALUE:
            return new CompareResult(compareResult);
        default:
            throw new LDAPException(compareResult);
    }
}
Also used : Control(com.unboundid.ldap.sdk.Control) LDAPException(com.unboundid.ldap.sdk.LDAPException) CompareRequestProtocolOp(com.unboundid.ldap.protocol.CompareRequestProtocolOp) ArrayList(java.util.ArrayList) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) CompareResponseProtocolOp(com.unboundid.ldap.protocol.CompareResponseProtocolOp) CompareResult(com.unboundid.ldap.sdk.CompareResult) NotNull(com.unboundid.util.NotNull)

Example 7 with CompareResponseProtocolOp

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

the class JSONAccessLogRequestHandler method processCompareRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processCompareRequest(final int messageID, @NotNull final CompareRequestProtocolOp request, @NotNull final List<Control> controls) {
    final long opID = nextOperationID.getAndIncrement();
    final JSONBuffer buffer = getRequestHeader("compare", opID, messageID);
    buffer.appendString("dn", request.getDN());
    buffer.appendString("attribute-type", request.getAttributeName());
    buffer.endObject();
    logHandler.publish(new LogRecord(Level.INFO, buffer.toString()));
    logHandler.flush();
    final long startTimeNanos = System.nanoTime();
    final LDAPMessage responseMessage = requestHandler.processCompareRequest(messageID, request, controls);
    final long eTimeNanos = System.nanoTime() - startTimeNanos;
    final CompareResponseProtocolOp protocolOp = responseMessage.getCompareResponseProtocolOp();
    generateResponse(buffer, "compare", opID, messageID, protocolOp.getResultCode(), protocolOp.getDiagnosticMessage(), protocolOp.getMatchedDN(), protocolOp.getReferralURLs(), eTimeNanos);
    buffer.endObject();
    logHandler.publish(new LogRecord(Level.INFO, buffer.toString()));
    logHandler.flush();
    return responseMessage;
}
Also used : LogRecord(java.util.logging.LogRecord) JSONBuffer(com.unboundid.util.json.JSONBuffer) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) CompareResponseProtocolOp(com.unboundid.ldap.protocol.CompareResponseProtocolOp) NotNull(com.unboundid.util.NotNull)

Example 8 with CompareResponseProtocolOp

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

the class LDAPDebuggerRequestHandler method processCompareRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processCompareRequest(final int messageID, @NotNull final CompareRequestProtocolOp request, @NotNull final List<Control> controls) {
    final StringBuilder b = getBuffer();
    appendHeader(b, messageID);
    b.append("     Compare Request Protocol Op:").append(StaticUtils.EOL);
    b.append("          DN:  ").append(request.getDN()).append(StaticUtils.EOL);
    b.append("          Attribute Type:  ").append(request.getAttributeName()).append(StaticUtils.EOL);
    b.append("          Assertion Value:  ").append(request.getAssertionValue().stringValue()).append(StaticUtils.EOL);
    appendControls(b, controls);
    logHandler.publish(new LogRecord(Level.INFO, b.toString()));
    logHandler.flush();
    final LDAPMessage responseMessage = requestHandler.processCompareRequest(messageID, request, controls);
    b.setLength(0);
    appendHeader(b, responseMessage.getMessageID());
    b.append("     Compare Response Protocol Op:").append(StaticUtils.EOL);
    final CompareResponseProtocolOp protocolOp = responseMessage.getCompareResponseProtocolOp();
    appendResponse(b, protocolOp.getResultCode(), protocolOp.getDiagnosticMessage(), protocolOp.getMatchedDN(), protocolOp.getReferralURLs());
    appendControls(b, responseMessage.getControls());
    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) CompareResponseProtocolOp(com.unboundid.ldap.protocol.CompareResponseProtocolOp) NotNull(com.unboundid.util.NotNull)

Example 9 with CompareResponseProtocolOp

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

the class InMemoryRequestHandler method processCompareRequest.

/**
 * Attempts to process the provided compare request.  The attempt will fail if
 * any of the following conditions is true:
 * <UL>
 *   <LI>There is a problem with any of the request controls.</LI>
 *   <LI>The compare request contains a malformed target DN.</LI>
 *   <LI>The target entry does not exist.</LI>
 * </UL>
 *
 * @param  messageID  The message ID of the LDAP message containing the
 *                    compare request.
 * @param  request    The compare request that was included in the LDAP
 *                    message that was received.
 * @param  controls   The set of controls included in the LDAP message.  It
 *                    may be empty if there were no controls, but will not be
 *                    {@code null}.
 *
 * @return  The {@link LDAPMessage} containing the response to send to the
 *          client.  The protocol op in the {@code LDAPMessage} must be a
 *          {@code CompareResponseProtocolOp}.
 */
@Override()
@NotNull()
public LDAPMessage processCompareRequest(final int messageID, @NotNull final CompareRequestProtocolOp request, @NotNull final List<Control> controls) {
    synchronized (entryMap) {
        // Sleep before processing, if appropriate.
        sleepBeforeProcessing();
        // Process the provided request controls.
        final Map<String, Control> controlMap;
        try {
            controlMap = RequestControlPreProcessor.processControls(LDAPMessage.PROTOCOL_OP_TYPE_COMPARE_REQUEST, controls);
        } catch (final LDAPException le) {
            Debug.debugException(le);
            return new LDAPMessage(messageID, new CompareResponseProtocolOp(le.getResultCode().intValue(), null, le.getMessage(), null));
        }
        final ArrayList<Control> responseControls = new ArrayList<>(1);
        // If this operation type is not allowed, then reject it.
        final boolean isInternalOp = controlMap.containsKey(OID_INTERNAL_OPERATION_REQUEST_CONTROL);
        if ((!isInternalOp) && (!config.getAllowedOperationTypes().contains(OperationType.COMPARE))) {
            return new LDAPMessage(messageID, new CompareResponseProtocolOp(ResultCode.UNWILLING_TO_PERFORM_INT_VALUE, null, ERR_MEM_HANDLER_COMPARE_NOT_ALLOWED.get(), null));
        }
        // client is authenticated.
        if ((authenticatedDN.isNullDN() && config.getAuthenticationRequiredOperationTypes().contains(OperationType.COMPARE))) {
            return new LDAPMessage(messageID, new CompareResponseProtocolOp(ResultCode.INSUFFICIENT_ACCESS_RIGHTS_INT_VALUE, null, ERR_MEM_HANDLER_COMPARE_REQUIRES_AUTH.get(), null));
        }
        // Get the parsed target DN.
        final DN dn;
        try {
            dn = new DN(request.getDN(), schemaRef.get());
        } catch (final LDAPException le) {
            Debug.debugException(le);
            return new LDAPMessage(messageID, new CompareResponseProtocolOp(ResultCode.INVALID_DN_SYNTAX_INT_VALUE, null, ERR_MEM_HANDLER_COMPARE_MALFORMED_DN.get(request.getDN(), le.getMessage()), null));
        }
        // See if the target entry or one of its superiors is a smart referral.
        if (!controlMap.containsKey(ManageDsaITRequestControl.MANAGE_DSA_IT_REQUEST_OID)) {
            final Entry referralEntry = findNearestReferral(dn);
            if (referralEntry != null) {
                return new LDAPMessage(messageID, new CompareResponseProtocolOp(ResultCode.REFERRAL_INT_VALUE, referralEntry.getDN(), INFO_MEM_HANDLER_REFERRAL_ENCOUNTERED.get(), getReferralURLs(dn, referralEntry)));
            }
        }
        // Get the target entry (optionally checking for the root DSE or subschema
        // subentry).  If it does not exist, then fail.
        final Entry entry;
        if (dn.isNullDN()) {
            entry = generateRootDSE();
        } else if (dn.equals(subschemaSubentryDN)) {
            entry = subschemaSubentryRef.get();
        } else {
            entry = entryMap.get(dn);
        }
        if (entry == null) {
            return new LDAPMessage(messageID, new CompareResponseProtocolOp(ResultCode.NO_SUCH_OBJECT_INT_VALUE, getMatchedDNString(dn), ERR_MEM_HANDLER_COMPARE_NO_SUCH_ENTRY.get(request.getDN()), null));
        }
        // then perform the appropriate processing.
        try {
            handleAssertionRequestControl(controlMap, entry);
            handleProxiedAuthControl(controlMap);
        } catch (final LDAPException le) {
            Debug.debugException(le);
            return new LDAPMessage(messageID, new CompareResponseProtocolOp(le.getResultCode().intValue(), null, le.getMessage(), null));
        }
        // See if the entry contains the assertion value.
        final int resultCode;
        if (entry.hasAttributeValue(request.getAttributeName(), request.getAssertionValue().getValue())) {
            resultCode = ResultCode.COMPARE_TRUE_INT_VALUE;
        } else {
            resultCode = ResultCode.COMPARE_FALSE_INT_VALUE;
        }
        return new LDAPMessage(messageID, new CompareResponseProtocolOp(resultCode, null, null, null), responseControls);
    }
}
Also used : 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) ChangeLogEntry(com.unboundid.ldap.sdk.ChangeLogEntry) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry) Entry(com.unboundid.ldap.sdk.Entry) ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) ArrayList(java.util.ArrayList) CompareResponseProtocolOp(com.unboundid.ldap.protocol.CompareResponseProtocolOp) RDN(com.unboundid.ldap.sdk.RDN) DN(com.unboundid.ldap.sdk.DN) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) NotNull(com.unboundid.util.NotNull)

Example 10 with CompareResponseProtocolOp

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

Aggregations

CompareResponseProtocolOp (com.unboundid.ldap.protocol.CompareResponseProtocolOp)11 LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)9 NotNull (com.unboundid.util.NotNull)7 Control (com.unboundid.ldap.sdk.Control)5 LDAPException (com.unboundid.ldap.sdk.LDAPException)5 CompareRequestProtocolOp (com.unboundid.ldap.protocol.CompareRequestProtocolOp)3 CompareRequest (com.unboundid.ldap.sdk.CompareRequest)3 LogRecord (java.util.logging.LogRecord)3 Test (org.testng.annotations.Test)3 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)2 AddResponseProtocolOp (com.unboundid.ldap.protocol.AddResponseProtocolOp)2 BindResponseProtocolOp (com.unboundid.ldap.protocol.BindResponseProtocolOp)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 SearchResultDoneProtocolOp (com.unboundid.ldap.protocol.SearchResultDoneProtocolOp)2 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)2 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)2 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)2