use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.
the class JSONAccessLogRequestHandler method processBindRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processBindRequest(final int messageID, @NotNull final BindRequestProtocolOp request, @NotNull final List<Control> controls) {
final long opID = nextOperationID.getAndIncrement();
final JSONBuffer buffer = getRequestHeader("bind", opID, messageID);
buffer.appendNumber("ldap-version", request.getVersion());
buffer.appendString("dn", request.getBindDN());
switch(request.getCredentialsType()) {
case BindRequestProtocolOp.CRED_TYPE_SIMPLE:
buffer.appendString("authentication-type", "simple");
break;
case BindRequestProtocolOp.CRED_TYPE_SASL:
buffer.appendString("authentication-type", "sasl");
buffer.appendString("sasl-mechanism", request.getSASLMechanism());
break;
}
buffer.endObject();
logHandler.publish(new LogRecord(Level.INFO, buffer.toString()));
logHandler.flush();
final long startTimeNanos = System.nanoTime();
final LDAPMessage responseMessage = requestHandler.processBindRequest(messageID, request, controls);
final long eTimeNanos = System.nanoTime() - startTimeNanos;
final BindResponseProtocolOp protocolOp = responseMessage.getBindResponseProtocolOp();
generateResponse(buffer, "bind", 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.LDAPMessage in project ldapsdk by pingidentity.
the class JSONAccessLogRequestHandler method processDeleteRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processDeleteRequest(final int messageID, @NotNull final DeleteRequestProtocolOp request, @NotNull final List<Control> controls) {
final long opID = nextOperationID.getAndIncrement();
final JSONBuffer buffer = getRequestHeader("delete", opID, messageID);
buffer.appendString("dn", request.getDN());
buffer.endObject();
logHandler.publish(new LogRecord(Level.INFO, buffer.toString()));
logHandler.flush();
final long startTimeNanos = System.nanoTime();
final LDAPMessage responseMessage = requestHandler.processDeleteRequest(messageID, request, controls);
final long eTimeNanos = System.nanoTime() - startTimeNanos;
final DeleteResponseProtocolOp protocolOp = responseMessage.getDeleteResponseProtocolOp();
generateResponse(buffer, "delete", 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.LDAPMessage in project ldapsdk by pingidentity.
the class LDAPDebuggerRequestHandler method processModifyDNRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processModifyDNRequest(final int messageID, @NotNull final ModifyDNRequestProtocolOp request, @NotNull final List<Control> controls) {
final StringBuilder b = getBuffer();
appendHeader(b, messageID);
b.append(" Modify DN Request Protocol Op:").append(StaticUtils.EOL);
b.append(" DN: ").append(request.getDN()).append(StaticUtils.EOL);
b.append(" New RDN: ").append(request.getNewRDN()).append(StaticUtils.EOL);
b.append(" Delete Old RDN: ").append(request.deleteOldRDN()).append(StaticUtils.EOL);
final String newSuperior = request.getNewSuperiorDN();
if (newSuperior != null) {
b.append(" New Superior DN: ").append(newSuperior).append(StaticUtils.EOL);
}
appendControls(b, controls);
logHandler.publish(new LogRecord(Level.INFO, b.toString()));
logHandler.flush();
final LDAPMessage responseMessage = requestHandler.processModifyDNRequest(messageID, request, controls);
b.setLength(0);
appendHeader(b, responseMessage.getMessageID());
b.append(" Modify DN Response Protocol Op:").append(StaticUtils.EOL);
final ModifyDNResponseProtocolOp protocolOp = responseMessage.getModifyDNResponseProtocolOp();
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.LDAPMessage in project ldapsdk by pingidentity.
the class LDAPDebuggerRequestHandler method processAddRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processAddRequest(final int messageID, @NotNull final AddRequestProtocolOp request, @NotNull final List<Control> controls) {
final StringBuilder b = getBuffer();
appendHeader(b, messageID);
b.append(" Add Request Protocol Op:").append(StaticUtils.EOL);
final Entry e = new Entry(request.getDN(), request.getAttributes());
final String[] ldifLines = e.toLDIF(80);
for (final String line : ldifLines) {
b.append(" ").append(line).append(StaticUtils.EOL);
}
appendControls(b, controls);
logHandler.publish(new LogRecord(Level.INFO, b.toString()));
logHandler.flush();
final LDAPMessage responseMessage = requestHandler.processAddRequest(messageID, request, controls);
b.setLength(0);
appendHeader(b, responseMessage.getMessageID());
b.append(" Add Response Protocol Op:").append(StaticUtils.EOL);
final AddResponseProtocolOp protocolOp = responseMessage.getAddResponseProtocolOp();
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.LDAPMessage in project ldapsdk by pingidentity.
the class LDAPListenerClientConnection method run.
/**
* Operates in a loop, waiting for a request to arrive from the client and
* handing it off to the request handler for processing. This method is for
* internal use only and must not be invoked by external callers.
*/
@InternalUseOnly()
@Override()
public void run() {
try {
while (true) {
final LDAPMessage requestMessage;
try {
requestMessage = LDAPMessage.readFrom(asn1Reader, false);
if (requestMessage == null) {
// so we won't notify the exception handler.
try {
close();
} catch (final IOException ioe) {
Debug.debugException(ioe);
}
return;
}
} catch (final LDAPException le) {
// This indicates that the client sent a malformed request.
Debug.debugException(le);
close(le);
return;
}
try {
final int messageID = requestMessage.getMessageID();
final List<Control> controls = requestMessage.getControls();
LDAPMessage responseMessage;
switch(requestMessage.getProtocolOpType()) {
case LDAPMessage.PROTOCOL_OP_TYPE_ABANDON_REQUEST:
requestHandler.processAbandonRequest(messageID, requestMessage.getAbandonRequestProtocolOp(), controls);
responseMessage = null;
break;
case LDAPMessage.PROTOCOL_OP_TYPE_ADD_REQUEST:
try {
responseMessage = requestHandler.processAddRequest(messageID, requestMessage.getAddRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new AddResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_BIND_REQUEST:
try {
responseMessage = requestHandler.processBindRequest(messageID, requestMessage.getBindRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new BindResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null, null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_COMPARE_REQUEST:
try {
responseMessage = requestHandler.processCompareRequest(messageID, requestMessage.getCompareRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new CompareResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_DELETE_REQUEST:
try {
responseMessage = requestHandler.processDeleteRequest(messageID, requestMessage.getDeleteRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new DeleteResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_EXTENDED_REQUEST:
try {
responseMessage = requestHandler.processExtendedRequest(messageID, requestMessage.getExtendedRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new ExtendedResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null, null, null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_MODIFY_REQUEST:
try {
responseMessage = requestHandler.processModifyRequest(messageID, requestMessage.getModifyRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new ModifyResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_MODIFY_DN_REQUEST:
try {
responseMessage = requestHandler.processModifyDNRequest(messageID, requestMessage.getModifyDNRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new ModifyDNResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_SEARCH_REQUEST:
try {
responseMessage = requestHandler.processSearchRequest(messageID, requestMessage.getSearchRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new SearchResultDoneProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_UNBIND_REQUEST:
requestHandler.processUnbindRequest(messageID, requestMessage.getUnbindRequestProtocolOp(), controls);
close();
return;
default:
close(new LDAPException(ResultCode.PROTOCOL_ERROR, ERR_CONN_INVALID_PROTOCOL_OP_TYPE.get(StaticUtils.toHex(requestMessage.getProtocolOpType()))));
return;
}
if (responseMessage != null) {
try {
sendMessage(responseMessage);
} catch (final LDAPException le) {
Debug.debugException(le);
close(le);
return;
}
}
} catch (final Throwable t) {
close(new LDAPException(ResultCode.LOCAL_ERROR, ERR_CONN_EXCEPTION_IN_REQUEST_HANDLER.get(String.valueOf(requestMessage), StaticUtils.getExceptionMessage(t))));
StaticUtils.throwErrorOrRuntimeException(t);
}
}
} finally {
if (listener != null) {
listener.connectionClosed(this);
}
}
}
Aggregations