use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.
the class InMemoryRequestHandler method processTransactionRequest.
/**
* Determines whether the provided set of controls includes a transaction
* specification request control. If so, then it will verify that it
* references a valid transaction for the client. If the request is part of a
* valid transaction, then the transaction specification request control will
* be removed and the request will be stashed in the client connection state
* so that it can be retrieved and processed when the transaction is
* committed.
*
* @param messageID The message ID for the request to be processed.
* @param request The protocol op for the request to be processed.
* @param controls The set of controls for the request to be processed.
*
* @return The transaction ID for the associated transaction, or {@code null}
* if the request is not part of any transaction.
*
* @throws LDAPException If the transaction specification request control is
* present but does not refer to a valid transaction
* for the associated client connection.
*/
@SuppressWarnings("unchecked")
@Nullable()
private ASN1OctetString processTransactionRequest(final int messageID, @NotNull final ProtocolOp request, @NotNull final Map<String, Control> controls) throws LDAPException {
final TransactionSpecificationRequestControl txnControl = (TransactionSpecificationRequestControl) controls.remove(TransactionSpecificationRequestControl.TRANSACTION_SPECIFICATION_REQUEST_OID);
if (txnControl == null) {
return null;
}
// See if the client has an active transaction. If not, then fail.
final ASN1OctetString txnID = txnControl.getTransactionID();
final ObjectPair<ASN1OctetString, List<LDAPMessage>> txnInfo = (ObjectPair<ASN1OctetString, List<LDAPMessage>>) connectionState.get(TransactionExtendedOperationHandler.STATE_VARIABLE_TXN_INFO);
if (txnInfo == null) {
throw new LDAPException(ResultCode.UNAVAILABLE_CRITICAL_EXTENSION, ERR_MEM_HANDLER_TXN_CONTROL_WITHOUT_TXN.get(txnID.stringValue()));
}
// Make sure that the active transaction has a transaction ID that matches
// the transaction ID from the control. If not, then abort the existing
// transaction and fail.
final ASN1OctetString existingTxnID = txnInfo.getFirst();
if (!txnID.stringValue().equals(existingTxnID.stringValue())) {
connectionState.remove(TransactionExtendedOperationHandler.STATE_VARIABLE_TXN_INFO);
connection.sendUnsolicitedNotification(new AbortedTransactionExtendedResult(existingTxnID, ResultCode.CONSTRAINT_VIOLATION, ERR_MEM_HANDLER_TXN_ABORTED_BY_CONTROL_TXN_ID_MISMATCH.get(existingTxnID.stringValue(), txnID.stringValue()), null, null, null));
throw new LDAPException(ResultCode.UNAVAILABLE_CRITICAL_EXTENSION, ERR_MEM_HANDLER_TXN_CONTROL_ID_MISMATCH.get(txnID.stringValue(), existingTxnID.stringValue()));
}
// Stash the request in the transaction state information so that it will
// be processed when the transaction is committed.
txnInfo.getSecond().add(new LDAPMessage(messageID, request, new ArrayList<>(controls.values())));
return txnID;
}
use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.
the class InMemoryRequestHandler method modify.
/**
* Processes the provided modify request.
* <BR><BR>
* This method may be used regardless of whether the server is listening for
* client connections, and regardless of whether modify operations are allowed
* in the server.
*
* @param modifyRequest The modify request to be processed. It must not be
* {@code null}.
*
* @return The result of processing the modify operation.
*
* @throws LDAPException If the server rejects the modify request, or if a
* problem is encountered while sending the request or
* reading the response.
*/
@NotNull()
public LDAPResult modify(@NotNull final ModifyRequest modifyRequest) throws LDAPException {
final ArrayList<Control> requestControlList = new ArrayList<>(modifyRequest.getControlList());
requestControlList.add(new Control(OID_INTERNAL_OPERATION_REQUEST_CONTROL, false));
final LDAPMessage responseMessage = processModifyRequest(1, new ModifyRequestProtocolOp(modifyRequest.getDN(), modifyRequest.getModifications()), requestControlList);
final ModifyResponseProtocolOp modifyResponse = responseMessage.getModifyResponseProtocolOp();
final LDAPResult ldapResult = new LDAPResult(responseMessage.getMessageID(), ResultCode.valueOf(modifyResponse.getResultCode()), modifyResponse.getDiagnosticMessage(), modifyResponse.getMatchedDN(), modifyResponse.getReferralURLs(), responseMessage.getControls());
switch(modifyResponse.getResultCode()) {
case ResultCode.SUCCESS_INT_VALUE:
case ResultCode.NO_OPERATION_INT_VALUE:
return ldapResult;
default:
throw new LDAPException(ldapResult);
}
}
use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.
the class ProxyRequestHandler method processDeleteRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processDeleteRequest(final int messageID, @NotNull final DeleteRequestProtocolOp request, @NotNull final List<Control> controls) {
final DeleteRequest deleteRequest = new DeleteRequest(request.getDN());
if (!controls.isEmpty()) {
deleteRequest.setControls(controls);
}
deleteRequest.setIntermediateResponseListener(this);
LDAPResult deleteResult;
try {
deleteResult = ldapConnection.delete(deleteRequest);
} catch (final LDAPException le) {
Debug.debugException(le);
deleteResult = le.toLDAPResult();
}
final DeleteResponseProtocolOp deleteResponseProtocolOp = new DeleteResponseProtocolOp(deleteResult.getResultCode().intValue(), deleteResult.getMatchedDN(), deleteResult.getDiagnosticMessage(), Arrays.asList(deleteResult.getReferralURLs()));
return new LDAPMessage(messageID, deleteResponseProtocolOp, Arrays.asList(deleteResult.getResponseControls()));
}
use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.
the class ProxyRequestHandler method processAddRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processAddRequest(final int messageID, @NotNull final AddRequestProtocolOp request, @NotNull final List<Control> controls) {
final AddRequest addRequest = new AddRequest(request.getDN(), request.getAttributes());
if (!controls.isEmpty()) {
addRequest.setControls(controls);
}
addRequest.setIntermediateResponseListener(this);
LDAPResult addResult;
try {
addResult = ldapConnection.add(addRequest);
} catch (final LDAPException le) {
Debug.debugException(le);
addResult = le.toLDAPResult();
}
final AddResponseProtocolOp addResponseProtocolOp = new AddResponseProtocolOp(addResult.getResultCode().intValue(), addResult.getMatchedDN(), addResult.getDiagnosticMessage(), Arrays.asList(addResult.getReferralURLs()));
return new LDAPMessage(messageID, addResponseProtocolOp, Arrays.asList(addResult.getResponseControls()));
}
use of com.unboundid.ldap.protocol.LDAPMessage 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()));
}
Aggregations