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