use of com.unboundid.ldap.protocol.BindResponseProtocolOp in project ldapsdk by pingidentity.
the class LDAPDebuggerRequestHandler method processBindRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processBindRequest(final int messageID, @NotNull final BindRequestProtocolOp request, @NotNull final List<Control> controls) {
final StringBuilder b = getBuffer();
appendHeader(b, messageID);
b.append(" Bind Request Protocol Op:").append(StaticUtils.EOL);
b.append(" LDAP Version: ").append(request.getVersion()).append(StaticUtils.EOL);
b.append(" Bind DN: ").append(request.getBindDN()).append(StaticUtils.EOL);
switch(request.getCredentialsType()) {
case BindRequestProtocolOp.CRED_TYPE_SIMPLE:
b.append(" Credentials Type: SIMPLE").append(StaticUtils.EOL);
b.append(" Password: ").append(request.getSimplePassword()).append(StaticUtils.EOL);
break;
case BindRequestProtocolOp.CRED_TYPE_SASL:
b.append(" Credentials Type: SASL").append(StaticUtils.EOL);
b.append(" Mechanism: ").append(request.getSASLMechanism()).append(StaticUtils.EOL);
final ASN1OctetString saslCredentials = request.getSASLCredentials();
if (saslCredentials != null) {
b.append(" Encoded Credentials:");
b.append(StaticUtils.EOL);
StaticUtils.toHexPlusASCII(saslCredentials.getValue(), 20, b);
}
break;
}
appendControls(b, controls);
logHandler.publish(new LogRecord(Level.INFO, b.toString()));
logHandler.flush();
final LDAPMessage responseMessage = requestHandler.processBindRequest(messageID, request, controls);
b.setLength(0);
appendHeader(b, responseMessage.getMessageID());
b.append(" Bind Response Protocol Op:").append(StaticUtils.EOL);
final BindResponseProtocolOp protocolOp = responseMessage.getBindResponseProtocolOp();
appendResponse(b, protocolOp.getResultCode(), protocolOp.getDiagnosticMessage(), protocolOp.getMatchedDN(), protocolOp.getReferralURLs());
final ASN1OctetString serverSASLCredentials = protocolOp.getServerSASLCredentials();
if (serverSASLCredentials != null) {
b.append(" Encoded Server SASL Credentials:");
b.append(StaticUtils.EOL);
StaticUtils.toHexPlusASCII(serverSASLCredentials.getValue(), 20, b);
}
appendControls(b, responseMessage.getControls());
logHandler.publish(new LogRecord(Level.INFO, b.toString()));
logHandler.flush();
return responseMessage;
}
use of com.unboundid.ldap.protocol.BindResponseProtocolOp in project ldapsdk by pingidentity.
the class ProxyRequestHandler method processBindRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processBindRequest(final int messageID, @NotNull final BindRequestProtocolOp request, @NotNull final List<Control> controls) {
final Control[] controlArray;
if ((controls == null) || (controls.isEmpty())) {
controlArray = StaticUtils.NO_CONTROLS;
} else {
controlArray = new Control[controls.size()];
controls.toArray(controlArray);
}
final BindRequest bindRequest;
if (request.getCredentialsType() == BindRequestProtocolOp.CRED_TYPE_SIMPLE) {
bindRequest = new SimpleBindRequest(request.getBindDN(), request.getSimplePassword().getValue(), controlArray);
} else {
bindRequest = new GenericSASLBindRequest(request.getBindDN(), request.getSASLMechanism(), request.getSASLCredentials(), controlArray);
}
bindRequest.setIntermediateResponseListener(this);
LDAPResult bindResult;
try {
bindResult = ldapConnection.bind(bindRequest);
} catch (final LDAPException le) {
Debug.debugException(le);
bindResult = le.toLDAPResult();
}
final BindResponseProtocolOp bindResponseProtocolOp = new BindResponseProtocolOp(bindResult.getResultCode().intValue(), bindResult.getMatchedDN(), bindResult.getDiagnosticMessage(), Arrays.asList(bindResult.getReferralURLs()), null);
return new LDAPMessage(messageID, bindResponseProtocolOp, Arrays.asList(bindResult.getResponseControls()));
}
use of com.unboundid.ldap.protocol.BindResponseProtocolOp in project ldapsdk by pingidentity.
the class InMemoryOperationInterceptorRequestHandler method processBindRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processBindRequest(final int messageID, @NotNull final BindRequestProtocolOp request, @NotNull final List<Control> controls) {
if (request.getCredentialsType() == BindRequestProtocolOp.CRED_TYPE_SIMPLE) {
final InterceptedSimpleBindOperation op = new InterceptedSimpleBindOperation(connection, messageID, request, toArray(controls));
activeOperations.put(messageID, op);
try {
for (final InMemoryOperationInterceptor i : interceptors) {
try {
i.processSimpleBindRequest(op);
} catch (final LDAPException le) {
Debug.debugException(le);
return new LDAPMessage(messageID, new BindResponseProtocolOp(le.toLDAPResult()), le.getResponseControls());
} catch (final Exception e) {
Debug.debugException(e);
return new LDAPMessage(messageID, new BindResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_DS_INTERCEPTOR_REQUEST_ERROR.get(String.valueOf(op), i.getClass().getName(), StaticUtils.getExceptionMessage(e)), null, null));
}
}
final LDAPMessage resultMessage = wrappedHandler.processBindRequest(messageID, new BindRequestProtocolOp(op.getRequest()), op.getRequest().getControlList());
op.setResult(resultMessage.getBindResponseProtocolOp().toBindResult(toArray(resultMessage.getControls())));
for (final InMemoryOperationInterceptor i : interceptors) {
try {
i.processSimpleBindResult(op);
} catch (final Exception e) {
Debug.debugException(e);
return new LDAPMessage(messageID, new BindResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_DS_INTERCEPTOR_RESULT_ERROR.get(String.valueOf(op), i.getClass().getName(), StaticUtils.getExceptionMessage(e)), null, null));
}
}
return new LDAPMessage(messageID, new BindResponseProtocolOp(op.getResult()), op.getResult().getResponseControls());
} finally {
activeOperations.remove(messageID);
}
} else {
final InterceptedSASLBindOperation op = new InterceptedSASLBindOperation(connection, messageID, request, toArray(controls));
activeOperations.put(messageID, op);
try {
for (final InMemoryOperationInterceptor i : interceptors) {
try {
i.processSASLBindRequest(op);
} catch (final LDAPException le) {
Debug.debugException(le);
return new LDAPMessage(messageID, new BindResponseProtocolOp(le.toLDAPResult()), le.getResponseControls());
} catch (final Exception e) {
Debug.debugException(e);
return new LDAPMessage(messageID, new BindResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_DS_INTERCEPTOR_REQUEST_ERROR.get(String.valueOf(op), i.getClass().getName(), StaticUtils.getExceptionMessage(e)), null, null));
}
}
final LDAPMessage resultMessage = wrappedHandler.processBindRequest(messageID, new BindRequestProtocolOp(op.getRequest()), op.getRequest().getControlList());
op.setResult(resultMessage.getBindResponseProtocolOp().toBindResult(toArray(resultMessage.getControls())));
for (final InMemoryOperationInterceptor i : interceptors) {
try {
i.processSASLBindResult(op);
} catch (final Exception e) {
Debug.debugException(e);
return new LDAPMessage(messageID, new BindResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_DS_INTERCEPTOR_RESULT_ERROR.get(String.valueOf(op), i.getClass().getName(), StaticUtils.getExceptionMessage(e)), null, null));
}
}
return new LDAPMessage(messageID, new BindResponseProtocolOp(op.getResult()), op.getResult().getResponseControls());
} finally {
activeOperations.remove(messageID);
}
}
}
Aggregations