use of com.unboundid.ldap.protocol.ExtendedResponseProtocolOp in project ldapsdk by pingidentity.
the class CannedResponseRequestHandlerTestCase method testDefaultConstructor.
/**
* Tests the behavior of the request handler with the default configuration.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testDefaultConstructor() throws Exception {
final CannedResponseRequestHandler handler = new CannedResponseRequestHandler().newInstance(null);
LDAPMessage m = handler.processAddRequest(1, new AddRequestProtocolOp("dc=example,dc=com", Arrays.asList(new Attribute("objectClass", "top", "domain"), new Attribute("dc", "example"))), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 1);
assertTrue(m.getProtocolOp() instanceof AddResponseProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
m = handler.processBindRequest(2, new BindRequestProtocolOp("uid=admin,dc=example,dc=com", "password"), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 2);
assertTrue(m.getProtocolOp() instanceof BindResponseProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
m = handler.processCompareRequest(3, new CompareRequestProtocolOp("dc=example,dc=com", "objectClass", new ASN1OctetString("top")), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 3);
assertTrue(m.getProtocolOp() instanceof CompareResponseProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
m = handler.processDeleteRequest(4, new DeleteRequestProtocolOp("dc=example,dc=com"), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 4);
assertTrue(m.getProtocolOp() instanceof DeleteResponseProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
m = handler.processExtendedRequest(5, new ExtendedRequestProtocolOp("1.2.3.4", null), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 5);
assertTrue(m.getProtocolOp() instanceof ExtendedResponseProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
m = handler.processModifyRequest(6, new ModifyRequestProtocolOp("dc=example,dc=com", Arrays.asList(new Modification(ModificationType.REPLACE, "description", "foo"))), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 6);
assertTrue(m.getProtocolOp() instanceof ModifyResponseProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
m = handler.processModifyDNRequest(6, new ModifyDNRequestProtocolOp("ou=People,dc=example,dc=com", "ou=Users", true, null), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 6);
assertTrue(m.getProtocolOp() instanceof ModifyDNResponseProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
m = handler.processSearchRequest(7, new SearchRequestProtocolOp("dc=example,dc=com", SearchScope.SUB, DereferencePolicy.NEVER, 0, 0, false, Filter.createEqualityFilter("uid", "test"), Arrays.<String>asList()), Collections.<Control>emptyList());
assertNotNull(m);
assertEquals(m.getMessageID(), 7);
assertTrue(m.getProtocolOp() instanceof SearchResultDoneProtocolOp);
assertNotNull(m.getControls());
assertTrue(m.getControls().isEmpty());
}
use of com.unboundid.ldap.protocol.ExtendedResponseProtocolOp in project ldapsdk by pingidentity.
the class LDAPDebuggerRequestHandler method processExtendedRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processExtendedRequest(final int messageID, @NotNull final ExtendedRequestProtocolOp request, @NotNull final List<Control> controls) {
final StringBuilder b = getBuffer();
appendHeader(b, messageID);
b.append(" Extended Request Protocol Op:").append(StaticUtils.EOL);
b.append(" Request OID: ").append(request.getOID()).append(StaticUtils.EOL);
final ASN1OctetString requestValue = request.getValue();
if (requestValue != null) {
b.append(" Encoded Request Value:");
b.append(StaticUtils.EOL);
StaticUtils.toHexPlusASCII(requestValue.getValue(), 15, b);
}
appendControls(b, controls);
logHandler.publish(new LogRecord(Level.INFO, b.toString()));
logHandler.flush();
final LDAPMessage responseMessage = requestHandler.processExtendedRequest(messageID, request, controls);
b.setLength(0);
appendHeader(b, responseMessage.getMessageID());
b.append(" Extended Response Protocol Op:").append(StaticUtils.EOL);
final ExtendedResponseProtocolOp protocolOp = responseMessage.getExtendedResponseProtocolOp();
appendResponse(b, protocolOp.getResultCode(), protocolOp.getDiagnosticMessage(), protocolOp.getMatchedDN(), protocolOp.getReferralURLs());
final String responseOID = protocolOp.getResponseOID();
if (responseOID != null) {
b.append(" Response OID: ").append(responseOID).append(StaticUtils.EOL);
}
final ASN1OctetString responseValue = protocolOp.getResponseValue();
if (responseValue != null) {
b.append(" Encoded Response Value:");
b.append(StaticUtils.EOL);
StaticUtils.toHexPlusASCII(responseValue.getValue(), 15, b);
}
appendControls(b, responseMessage.getControls());
logHandler.publish(new LogRecord(Level.INFO, b.toString()));
logHandler.flush();
return responseMessage;
}
use of com.unboundid.ldap.protocol.ExtendedResponseProtocolOp 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);
}
}
use of com.unboundid.ldap.protocol.ExtendedResponseProtocolOp in project ldapsdk by pingidentity.
the class MultiUpdateExtendedResult method encodeValue.
/**
* Encodes the information from the provided set of results into a form
* suitable for use as the value of a multi-update extended result.
*
* @param changesApplied The value which indicates whether any or all of the
* changes from the request were successfully applied.
* @param results The set of operation results to be included in the
* extended result value. It may be {@code null} or
* empty if no operation results should be included.
*
* @return An ASN.1 element suitable for use as the value of a multi-update
* extended result.
*
* @throws LDAPException If any of the results are for an inappropriate
* operation type.
*/
@Nullable()
private static ASN1OctetString encodeValue(@Nullable final MultiUpdateChangesApplied changesApplied, @Nullable final List<ObjectPair<OperationType, LDAPResult>> results) throws LDAPException {
if ((results == null) || results.isEmpty()) {
return null;
}
final ArrayList<ASN1Element> opElements = new ArrayList<>(results.size());
for (final ObjectPair<OperationType, LDAPResult> p : results) {
final OperationType t = p.getFirst();
final LDAPResult r = p.getSecond();
final ASN1Element protocolOpElement;
switch(t) {
case ADD:
protocolOpElement = new AddResponseProtocolOp(r).encodeProtocolOp();
break;
case DELETE:
protocolOpElement = new DeleteResponseProtocolOp(r).encodeProtocolOp();
break;
case EXTENDED:
protocolOpElement = new ExtendedResponseProtocolOp(r).encodeProtocolOp();
break;
case MODIFY:
protocolOpElement = new ModifyResponseProtocolOp(r).encodeProtocolOp();
break;
case MODIFY_DN:
protocolOpElement = new ModifyDNResponseProtocolOp(r).encodeProtocolOp();
break;
default:
throw new LDAPException(ResultCode.PARAM_ERROR, ERR_MULTI_UPDATE_RESULT_INVALID_OP_TYPE.get(t.name()));
}
final Control[] controls = r.getResponseControls();
if ((controls == null) || (controls.length == 0)) {
opElements.add(new ASN1Sequence(protocolOpElement));
} else {
opElements.add(new ASN1Sequence(protocolOpElement, Control.encodeControls(controls)));
}
}
final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1Enumerated(changesApplied.intValue()), new ASN1Sequence(opElements));
return new ASN1OctetString(valueSequence.encode());
}
Aggregations