use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.
the class InMemoryDirectoryServer method bind.
/**
* Processes the provided bind request. Only simple and SASL PLAIN bind
* requests are supported. Note that the bind processing will verify that the
* provided credentials are valid, but it will not alter the server in any
* way.
*
* @param bindRequest The bind request to be processed. It must not be
* {@code null}.
*
* @return The result of processing the bind operation.
*
* @throws LDAPException If the server rejects the bind request, or if a
* problem occurs while sending the request or reading
* the response.
*/
@NotNull()
public BindResult bind(@NotNull final BindRequest bindRequest) throws LDAPException {
final ArrayList<Control> requestControlList = new ArrayList<>(bindRequest.getControlList());
requestControlList.add(new Control(InMemoryRequestHandler.OID_INTERNAL_OPERATION_REQUEST_CONTROL, false));
final BindRequestProtocolOp bindOp;
if (bindRequest instanceof SimpleBindRequest) {
final SimpleBindRequest r = (SimpleBindRequest) bindRequest;
bindOp = new BindRequestProtocolOp(r.getBindDN(), r.getPassword().getValue());
} else if (bindRequest instanceof PLAINBindRequest) {
final PLAINBindRequest r = (PLAINBindRequest) bindRequest;
// Create the byte array that should comprise the credentials.
final byte[] authZIDBytes = StaticUtils.getBytes(r.getAuthorizationID());
final byte[] authNIDBytes = StaticUtils.getBytes(r.getAuthenticationID());
final byte[] passwordBytes = r.getPasswordBytes();
final byte[] credBytes = new byte[2 + authZIDBytes.length + authNIDBytes.length + passwordBytes.length];
System.arraycopy(authZIDBytes, 0, credBytes, 0, authZIDBytes.length);
int pos = authZIDBytes.length + 1;
System.arraycopy(authNIDBytes, 0, credBytes, pos, authNIDBytes.length);
pos += authNIDBytes.length + 1;
System.arraycopy(passwordBytes, 0, credBytes, pos, passwordBytes.length);
bindOp = new BindRequestProtocolOp(null, "PLAIN", new ASN1OctetString(credBytes));
} else {
throw new LDAPException(ResultCode.AUTH_METHOD_NOT_SUPPORTED, ERR_MEM_DS_UNSUPPORTED_BIND_TYPE.get());
}
final LDAPMessage responseMessage = inMemoryHandler.processBindRequest(1, bindOp, requestControlList);
final BindResponseProtocolOp bindResponse = responseMessage.getBindResponseProtocolOp();
final BindResult bindResult = new BindResult(new LDAPResult(responseMessage.getMessageID(), ResultCode.valueOf(bindResponse.getResultCode()), bindResponse.getDiagnosticMessage(), bindResponse.getMatchedDN(), bindResponse.getReferralURLs(), responseMessage.getControls()));
switch(bindResponse.getResultCode()) {
case ResultCode.SUCCESS_INT_VALUE:
return bindResult;
default:
throw new LDAPException(bindResult);
}
}
use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.
the class AccessLogRequestHandler 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 StringBuilder b = getRequestHeader("COMPARE", opID, messageID);
b.append(" dn=\"");
b.append(request.getDN());
b.append("\" attr=\"");
b.append(request.getAttributeName());
b.append('"');
logHandler.publish(new LogRecord(Level.INFO, b.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(b, "COMPARE", 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 processAddRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processAddRequest(final int messageID, @NotNull final AddRequestProtocolOp request, @NotNull final List<Control> controls) {
final long opID = nextOperationID.getAndIncrement();
final StringBuilder b = getRequestHeader("ADD", 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.processAddRequest(messageID, request, controls);
final long eTimeNanos = System.nanoTime() - startTimeNanos;
final AddResponseProtocolOp protocolOp = responseMessage.getAddResponseProtocolOp();
generateResponse(b, "ADD", 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 processExtendedRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processExtendedRequest(final int messageID, @NotNull final ExtendedRequestProtocolOp request, @NotNull final List<Control> controls) {
final long opID = nextOperationID.getAndIncrement();
final StringBuilder b = getRequestHeader("EXTENDED", opID, messageID);
b.append(" requestOID=\"");
b.append(request.getOID());
b.append('"');
logHandler.publish(new LogRecord(Level.INFO, b.toString()));
logHandler.flush();
final long startTimeNanos = System.nanoTime();
final LDAPMessage responseMessage = requestHandler.processExtendedRequest(messageID, request, controls);
final long eTimeNanos = System.nanoTime() - startTimeNanos;
final ExtendedResponseProtocolOp protocolOp = responseMessage.getExtendedResponseProtocolOp();
generateResponse(b, "EXTENDED", opID, messageID, protocolOp.getResultCode(), protocolOp.getDiagnosticMessage(), protocolOp.getMatchedDN(), protocolOp.getReferralURLs(), eTimeNanos);
final String responseOID = protocolOp.getResponseOID();
if (responseOID != null) {
b.append(" responseOID=\"");
b.append(responseOID);
b.append('"');
}
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 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 StringBuilder b = getRequestHeader("BIND", opID, messageID);
b.append(" version=");
b.append(request.getVersion());
b.append(" dn=\"");
b.append(request.getBindDN());
b.append("\" authType=\"");
switch(request.getCredentialsType()) {
case BindRequestProtocolOp.CRED_TYPE_SIMPLE:
b.append("SIMPLE");
break;
case BindRequestProtocolOp.CRED_TYPE_SASL:
b.append("SASL ");
b.append(request.getSASLMechanism());
break;
}
b.append('"');
logHandler.publish(new LogRecord(Level.INFO, b.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(b, "BIND", opID, messageID, protocolOp.getResultCode(), protocolOp.getDiagnosticMessage(), protocolOp.getMatchedDN(), protocolOp.getReferralURLs(), eTimeNanos);
logHandler.publish(new LogRecord(Level.INFO, b.toString()));
logHandler.flush();
return responseMessage;
}
Aggregations