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);
}
}
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;
}
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;
}
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);
}
}
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()));
}
Aggregations