Search in sources :

Example 6 with WhoAmIExtendedRequest

use of com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest in project ldapsdk by pingidentity.

the class LDAPConnectionTestCase method testLastCommunicationTimeNonSynchronousMode.

/**
 * Tests to ensure that the last communication time is properly updated for
 * connections operating in non-synchronous mode.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testLastCommunicationTimeNonSynchronousMode() throws Exception {
    final InMemoryDirectoryServer ds = getTestDS(true, true);
    final LDAPConnectionOptions opts = new LDAPConnectionOptions();
    opts.setUseSynchronousMode(false);
    final LDAPConnection conn = new LDAPConnection(opts);
    assertEquals(conn.getConnectTime(), -1L);
    assertEquals(conn.getLastCommunicationTime(), -1L);
    conn.connect("localhost", ds.getListenPort());
    final long connectTime = conn.getConnectTime();
    assertTrue(connectTime > 0L);
    long lastCommunicationTime = conn.getLastCommunicationTime();
    assertTrue(lastCommunicationTime > 0L);
    assertTrue(lastCommunicationTime >= connectTime);
    // Get entry.
    Thread.sleep(10L);
    conn.getEntry("dc=example,dc=com");
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Get root DSE.
    Thread.sleep(10L);
    conn.getRootDSE();
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Get schema.
    Thread.sleep(10L);
    conn.getSchema();
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Add.
    Thread.sleep(10L);
    conn.add("dn: ou=test,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: test");
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Simple bind.
    Thread.sleep(10L);
    conn.bind("cn=Directory Manager", "password");
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // SASL bind.
    Thread.sleep(10L);
    conn.bind(new PLAINBindRequest("dn:cn=Directory Manager", "password"));
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Compare.
    Thread.sleep(10L);
    conn.compare("dc=example,dc=com", "dc", "example");
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Delete.
    Thread.sleep(10L);
    conn.delete("ou=test,dc=example,dc=com");
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Extended.
    Thread.sleep(10L);
    conn.processExtendedOperation(new WhoAmIExtendedRequest());
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Modify.
    Thread.sleep(10L);
    conn.modify("dn: uid=test.user,ou=People,dc=example,dc=com", "changetype: modify", "replace: description", "description: foo");
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Modify DN.
    Thread.sleep(10L);
    conn.modifyDN("uid=test.user,ou=People,dc=example,dc=com", "cn=Test User", false);
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Search.
    Thread.sleep(10L);
    conn.search("dc=example,dc=com", SearchScope.SUB, "(objectClass=*)");
    assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Close.
    conn.close();
    assertEquals(conn.getConnectTime(), -1L);
    assertEquals(conn.getLastCommunicationTime(), -1L);
}
Also used : WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) Test(org.testng.annotations.Test)

Example 7 with WhoAmIExtendedRequest

use of com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest in project ldapsdk by pingidentity.

the class LDAPConnectionTestCase method testExtendedWhoAmI.

/**
 * Tests the {@code processExtendedOperation} method variant that takes an
 * extended request object, using the "Who Am I?" extended request object.
 * <BR><BR>
 * Access to a Directory Server instance is required for complete processing.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testExtendedWhoAmI() throws Exception {
    if (!isDirectoryInstanceAvailable()) {
        return;
    }
    LDAPConnection conn = getAdminConnection();
    try {
        assertTrue(conn.isConnected());
        assertNotNull(conn.getConnectedAddress());
        assertTrue((conn.getConnectedPort() >= 1) && (conn.getConnectedPort() <= 65535));
        assertNotNull(conn.toString());
        WhoAmIExtendedRequest extendedRequest = new WhoAmIExtendedRequest();
        ExtendedResult extendedResult = conn.processExtendedOperation(extendedRequest);
        assertNotNull(extendedResult);
        assertEquals(extendedResult.getResultCode(), ResultCode.SUCCESS);
        assertNull(extendedResult.getOID());
        assertNotNull(extendedResult.getValue());
        assertTrue(extendedResult instanceof WhoAmIExtendedResult);
        WhoAmIExtendedResult whoAmIResult = (WhoAmIExtendedResult) extendedResult;
        assertNotNull(whoAmIResult);
        assertNotNull(whoAmIResult.getAuthorizationID());
    } finally {
        conn.close();
        assertFalse(conn.isConnected());
        assertNull(conn.getConnectedAddress());
        assertTrue(conn.getConnectedPort() < 0);
        assertNotNull(conn.toString());
    }
}
Also used : WhoAmIExtendedResult(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedResult) WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest) WhoAmIExtendedResult(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedResult) Test(org.testng.annotations.Test)

Example 8 with WhoAmIExtendedRequest

use of com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest in project ldapsdk by pingidentity.

the class LDAPConnectionTestCase method testLastCommunicationTimeSynchronousMode.

/**
 * Tests to ensure that the last communication time is properly updated for
 * connections operating in synchronous mode.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testLastCommunicationTimeSynchronousMode() throws Exception {
    final InMemoryDirectoryServer ds = getTestDS(true, true);
    final LDAPConnectionOptions opts = new LDAPConnectionOptions();
    opts.setUseSynchronousMode(true);
    final LDAPConnection conn = new LDAPConnection(opts);
    assertEquals(conn.getConnectTime(), -1L);
    assertEquals(conn.getLastCommunicationTime(), -1L);
    conn.connect("localhost", ds.getListenPort());
    final long connectTime = conn.getConnectTime();
    assertTrue(connectTime > 0L);
    long lastCommunicationTime = conn.getLastCommunicationTime();
    assertTrue(lastCommunicationTime > 0L);
    assertTrue(lastCommunicationTime >= connectTime);
    // Get entry.
    Thread.sleep(10L);
    conn.getEntry("dc=example,dc=com");
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Get root DSE.
    Thread.sleep(10L);
    conn.getRootDSE();
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Get schema.
    Thread.sleep(10L);
    conn.getSchema();
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Add.
    Thread.sleep(10L);
    conn.add("dn: ou=test,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: test");
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Simple bind.
    Thread.sleep(10L);
    conn.bind("cn=Directory Manager", "password");
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // SASL bind.
    Thread.sleep(10L);
    conn.bind(new PLAINBindRequest("dn:cn=Directory Manager", "password"));
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Compare.
    Thread.sleep(10L);
    conn.compare("dc=example,dc=com", "dc", "example");
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Delete.
    Thread.sleep(10L);
    conn.delete("ou=test,dc=example,dc=com");
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Extended.
    Thread.sleep(10L);
    conn.processExtendedOperation(new WhoAmIExtendedRequest());
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Modify.
    Thread.sleep(10L);
    conn.modify("dn: uid=test.user,ou=People,dc=example,dc=com", "changetype: modify", "replace: description", "description: foo");
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Modify DN.
    Thread.sleep(10L);
    conn.modifyDN("uid=test.user,ou=People,dc=example,dc=com", "cn=Test User", false);
    lastCommunicationTime = assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Search.
    Thread.sleep(10L);
    conn.search("dc=example,dc=com", SearchScope.SUB, "(objectClass=*)");
    assertLastCommunicationTimeUpdated(conn, lastCommunicationTime);
    // Close.
    conn.close();
    assertEquals(conn.getConnectTime(), -1L);
    assertEquals(conn.getLastCommunicationTime(), -1L);
}
Also used : WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) Test(org.testng.annotations.Test)

Example 9 with WhoAmIExtendedRequest

use of com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest in project ldapsdk by pingidentity.

the class LDAPConnectionLoggerTestCase method testLogExtendedOperationsSynchronous.

/**
 * Tests to ensure that extended operations are logged as expected when using
 * synchronous mode.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testLogExtendedOperationsSynchronous() throws Exception {
    final InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=example,dc=com");
    config.addAdditionalBindCredentials("cn=Directory Manager", "password");
    config.addExtendedOperationHandler(new TestIntermediateResponseExtendedOperationHandler("1.2.3.4", "1.2.3.5", "1.2.3.6", 2, 3));
    final InMemoryDirectoryServer ds = new InMemoryDirectoryServer(config);
    ds.startListening();
    try {
        final int port = ds.getListenPort();
        final TestLDAPConnectionLogger logger = new TestLDAPConnectionLogger();
        final LDAPConnectionOptions options = new LDAPConnectionOptions();
        options.setUseSynchronousMode(true);
        options.setConnectionLogger(logger);
        assertEquals(logger.getSuccessfulConnectCount(), 0);
        assertEquals(logger.getFailedConnectCount(), 0);
        assertEquals(logger.getDisconnectCount(), 0);
        assertEquals(logger.getAbandonRequestCount(), 0);
        assertEquals(logger.getAddRequestCount(), 0);
        assertEquals(logger.getAddResultCount(), 0);
        assertEquals(logger.getSimpleBindRequestCount(), 0);
        assertEquals(logger.getSASLBindRequestCount(), 0);
        assertEquals(logger.getBindResultCount(), 0);
        assertEquals(logger.getCompareRequestCount(), 0);
        assertEquals(logger.getCompareResultCount(), 0);
        assertEquals(logger.getDeleteRequestCount(), 0);
        assertEquals(logger.getDeleteResultCount(), 0);
        assertEquals(logger.getExtendedRequestCount(), 0);
        assertEquals(logger.getExtendedResultCount(), 0);
        assertEquals(logger.getModifyRequestCount(), 0);
        assertEquals(logger.getModifyResultCount(), 0);
        assertEquals(logger.getModifyDNRequestCount(), 0);
        assertEquals(logger.getModifyDNResultCount(), 0);
        assertEquals(logger.getSearchRequestCount(), 0);
        assertEquals(logger.getSearchResultEntryCount(), 0);
        assertEquals(logger.getSearchResultReferenceCount(), 0);
        assertEquals(logger.getSearchResultDoneCount(), 0);
        assertEquals(logger.getUnbindRequestCount(), 0);
        assertEquals(logger.getIntermediateResponseCount(), 0);
        try (LDAPConnection connection = new LDAPConnection(options, "localhost", port)) {
            // Verify that the connect was logged.
            assertEquals(logger.getSuccessfulConnectCount(), 1);
            assertEquals(logger.getFailedConnectCount(), 0);
            assertEquals(logger.getDisconnectCount(), 0);
            assertEquals(logger.getAbandonRequestCount(), 0);
            assertEquals(logger.getAddRequestCount(), 0);
            assertEquals(logger.getAddResultCount(), 0);
            assertEquals(logger.getSimpleBindRequestCount(), 0);
            assertEquals(logger.getSASLBindRequestCount(), 0);
            assertEquals(logger.getBindResultCount(), 0);
            assertEquals(logger.getCompareRequestCount(), 0);
            assertEquals(logger.getCompareResultCount(), 0);
            assertEquals(logger.getDeleteRequestCount(), 0);
            assertEquals(logger.getDeleteResultCount(), 0);
            assertEquals(logger.getExtendedRequestCount(), 0);
            assertEquals(logger.getExtendedResultCount(), 0);
            assertEquals(logger.getModifyRequestCount(), 0);
            assertEquals(logger.getModifyResultCount(), 0);
            assertEquals(logger.getModifyDNRequestCount(), 0);
            assertEquals(logger.getModifyDNResultCount(), 0);
            assertEquals(logger.getSearchRequestCount(), 0);
            assertEquals(logger.getSearchResultEntryCount(), 0);
            assertEquals(logger.getSearchResultReferenceCount(), 0);
            assertEquals(logger.getSearchResultDoneCount(), 0);
            assertEquals(logger.getUnbindRequestCount(), 0);
            assertEquals(logger.getIntermediateResponseCount(), 0);
            // Authenticate the connection.
            assertResultCodeEquals(connection, new SimpleBindRequest("cn=Directory Manager", "password"), ResultCode.SUCCESS);
            assertEquals(logger.getSuccessfulConnectCount(), 1);
            assertEquals(logger.getFailedConnectCount(), 0);
            assertEquals(logger.getDisconnectCount(), 0);
            assertEquals(logger.getAbandonRequestCount(), 0);
            assertEquals(logger.getAddRequestCount(), 0);
            assertEquals(logger.getAddResultCount(), 0);
            assertEquals(logger.getSimpleBindRequestCount(), 1);
            assertEquals(logger.getSASLBindRequestCount(), 0);
            assertEquals(logger.getBindResultCount(), 1);
            assertEquals(logger.getCompareRequestCount(), 0);
            assertEquals(logger.getCompareResultCount(), 0);
            assertEquals(logger.getDeleteRequestCount(), 0);
            assertEquals(logger.getDeleteResultCount(), 0);
            assertEquals(logger.getExtendedRequestCount(), 0);
            assertEquals(logger.getExtendedResultCount(), 0);
            assertEquals(logger.getModifyRequestCount(), 0);
            assertEquals(logger.getModifyResultCount(), 0);
            assertEquals(logger.getModifyDNRequestCount(), 0);
            assertEquals(logger.getModifyDNResultCount(), 0);
            assertEquals(logger.getSearchRequestCount(), 0);
            assertEquals(logger.getSearchResultEntryCount(), 0);
            assertEquals(logger.getSearchResultReferenceCount(), 0);
            assertEquals(logger.getSearchResultDoneCount(), 0);
            assertEquals(logger.getUnbindRequestCount(), 0);
            assertEquals(logger.getIntermediateResponseCount(), 0);
            // Send a "Who Am I?" extended request on the connection.
            assertResultCodeEquals(connection, new WhoAmIExtendedRequest(), ResultCode.SUCCESS);
            assertEquals(logger.getSuccessfulConnectCount(), 1);
            assertEquals(logger.getFailedConnectCount(), 0);
            assertEquals(logger.getDisconnectCount(), 0);
            assertEquals(logger.getAbandonRequestCount(), 0);
            assertEquals(logger.getAddRequestCount(), 0);
            assertEquals(logger.getAddResultCount(), 0);
            assertEquals(logger.getSimpleBindRequestCount(), 1);
            assertEquals(logger.getSASLBindRequestCount(), 0);
            assertEquals(logger.getBindResultCount(), 1);
            assertEquals(logger.getCompareRequestCount(), 0);
            assertEquals(logger.getCompareResultCount(), 0);
            assertEquals(logger.getDeleteRequestCount(), 0);
            assertEquals(logger.getDeleteResultCount(), 0);
            assertEquals(logger.getExtendedRequestCount(), 1);
            assertEquals(logger.getExtendedResultCount(), 1);
            assertEquals(logger.getModifyRequestCount(), 0);
            assertEquals(logger.getModifyResultCount(), 0);
            assertEquals(logger.getModifyDNRequestCount(), 0);
            assertEquals(logger.getModifyDNResultCount(), 0);
            assertEquals(logger.getSearchRequestCount(), 0);
            assertEquals(logger.getSearchResultEntryCount(), 0);
            assertEquals(logger.getSearchResultReferenceCount(), 0);
            assertEquals(logger.getSearchResultDoneCount(), 0);
            assertEquals(logger.getUnbindRequestCount(), 0);
            assertEquals(logger.getIntermediateResponseCount(), 0);
            // Send an extended request that will include intermediate responses.
            assertResultCodeEquals(connection, new ExtendedRequest("1.2.3.4"), ResultCode.SUCCESS);
            assertEquals(logger.getSuccessfulConnectCount(), 1);
            assertEquals(logger.getFailedConnectCount(), 0);
            assertEquals(logger.getDisconnectCount(), 0);
            assertEquals(logger.getAbandonRequestCount(), 0);
            assertEquals(logger.getAddRequestCount(), 0);
            assertEquals(logger.getAddResultCount(), 0);
            assertEquals(logger.getSimpleBindRequestCount(), 1);
            assertEquals(logger.getSASLBindRequestCount(), 0);
            assertEquals(logger.getBindResultCount(), 1);
            assertEquals(logger.getCompareRequestCount(), 0);
            assertEquals(logger.getCompareResultCount(), 0);
            assertEquals(logger.getDeleteRequestCount(), 0);
            assertEquals(logger.getDeleteResultCount(), 0);
            assertEquals(logger.getExtendedRequestCount(), 2);
            assertEquals(logger.getExtendedResultCount(), 2);
            assertEquals(logger.getModifyRequestCount(), 0);
            assertEquals(logger.getModifyResultCount(), 0);
            assertEquals(logger.getModifyDNRequestCount(), 0);
            assertEquals(logger.getModifyDNResultCount(), 0);
            assertEquals(logger.getSearchRequestCount(), 0);
            assertEquals(logger.getSearchResultEntryCount(), 0);
            assertEquals(logger.getSearchResultReferenceCount(), 0);
            assertEquals(logger.getSearchResultDoneCount(), 0);
            assertEquals(logger.getUnbindRequestCount(), 0);
            assertEquals(logger.getIntermediateResponseCount(), 5);
            // Send an extended request with an unrecognized request OID.
            assertResultCodeEquals(connection, new ExtendedRequest("4.3.2.1"), ResultCode.UNWILLING_TO_PERFORM);
            assertEquals(logger.getSuccessfulConnectCount(), 1);
            assertEquals(logger.getFailedConnectCount(), 0);
            assertEquals(logger.getDisconnectCount(), 0);
            assertEquals(logger.getAbandonRequestCount(), 0);
            assertEquals(logger.getAddRequestCount(), 0);
            assertEquals(logger.getAddResultCount(), 0);
            assertEquals(logger.getSimpleBindRequestCount(), 1);
            assertEquals(logger.getSASLBindRequestCount(), 0);
            assertEquals(logger.getBindResultCount(), 1);
            assertEquals(logger.getCompareRequestCount(), 0);
            assertEquals(logger.getCompareResultCount(), 0);
            assertEquals(logger.getDeleteRequestCount(), 0);
            assertEquals(logger.getDeleteResultCount(), 0);
            assertEquals(logger.getExtendedRequestCount(), 3);
            assertEquals(logger.getExtendedResultCount(), 3);
            assertEquals(logger.getModifyRequestCount(), 0);
            assertEquals(logger.getModifyResultCount(), 0);
            assertEquals(logger.getModifyDNRequestCount(), 0);
            assertEquals(logger.getModifyDNResultCount(), 0);
            assertEquals(logger.getSearchRequestCount(), 0);
            assertEquals(logger.getSearchResultEntryCount(), 0);
            assertEquals(logger.getSearchResultReferenceCount(), 0);
            assertEquals(logger.getSearchResultDoneCount(), 0);
            assertEquals(logger.getUnbindRequestCount(), 0);
            assertEquals(logger.getIntermediateResponseCount(), 5);
        }
        // Verify that the unbind and disconnect were logged.
        assertEquals(logger.getSuccessfulConnectCount(), 1);
        assertEquals(logger.getFailedConnectCount(), 0);
        assertEquals(logger.getDisconnectCount(), 1);
        assertEquals(logger.getAbandonRequestCount(), 0);
        assertEquals(logger.getAddRequestCount(), 0);
        assertEquals(logger.getAddResultCount(), 0);
        assertEquals(logger.getSimpleBindRequestCount(), 1);
        assertEquals(logger.getSASLBindRequestCount(), 0);
        assertEquals(logger.getBindResultCount(), 1);
        assertEquals(logger.getCompareRequestCount(), 0);
        assertEquals(logger.getCompareResultCount(), 0);
        assertEquals(logger.getDeleteRequestCount(), 0);
        assertEquals(logger.getDeleteResultCount(), 0);
        assertEquals(logger.getExtendedRequestCount(), 3);
        assertEquals(logger.getExtendedResultCount(), 3);
        assertEquals(logger.getModifyRequestCount(), 0);
        assertEquals(logger.getModifyResultCount(), 0);
        assertEquals(logger.getModifyDNRequestCount(), 0);
        assertEquals(logger.getModifyDNResultCount(), 0);
        assertEquals(logger.getSearchRequestCount(), 0);
        assertEquals(logger.getSearchResultEntryCount(), 0);
        assertEquals(logger.getSearchResultReferenceCount(), 0);
        assertEquals(logger.getSearchResultDoneCount(), 0);
        assertEquals(logger.getUnbindRequestCount(), 1);
        assertEquals(logger.getIntermediateResponseCount(), 5);
    } finally {
        ds.shutDown(true);
    }
}
Also used : WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest) InMemoryDirectoryServerConfig(com.unboundid.ldap.listener.InMemoryDirectoryServerConfig) TestIntermediateResponseExtendedOperationHandler(com.unboundid.ldap.listener.TestIntermediateResponseExtendedOperationHandler) Test(org.testng.annotations.Test)

Example 10 with WhoAmIExtendedRequest

use of com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest in project ldapsdk by pingidentity.

the class LDAPConnectionLoggerTestCase method testLogExtendedOperationsNonSynchronous.

/**
 * Tests to ensure that extended operations are logged as expected when not
 * using synchronous mode.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testLogExtendedOperationsNonSynchronous() throws Exception {
    final InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=example,dc=com");
    config.addAdditionalBindCredentials("cn=Directory Manager", "password");
    config.addExtendedOperationHandler(new TestIntermediateResponseExtendedOperationHandler("1.2.3.4", "1.2.3.5", "1.2.3.6", 2, 3));
    final InMemoryDirectoryServer ds = new InMemoryDirectoryServer(config);
    ds.startListening();
    try {
        final int port = ds.getListenPort();
        final TestLDAPConnectionLogger logger = new TestLDAPConnectionLogger();
        final LDAPConnectionOptions options = new LDAPConnectionOptions();
        options.setConnectionLogger(logger);
        assertEquals(logger.getSuccessfulConnectCount(), 0);
        assertEquals(logger.getFailedConnectCount(), 0);
        assertEquals(logger.getDisconnectCount(), 0);
        assertEquals(logger.getAbandonRequestCount(), 0);
        assertEquals(logger.getAddRequestCount(), 0);
        assertEquals(logger.getAddResultCount(), 0);
        assertEquals(logger.getSimpleBindRequestCount(), 0);
        assertEquals(logger.getSASLBindRequestCount(), 0);
        assertEquals(logger.getBindResultCount(), 0);
        assertEquals(logger.getCompareRequestCount(), 0);
        assertEquals(logger.getCompareResultCount(), 0);
        assertEquals(logger.getDeleteRequestCount(), 0);
        assertEquals(logger.getDeleteResultCount(), 0);
        assertEquals(logger.getExtendedRequestCount(), 0);
        assertEquals(logger.getExtendedResultCount(), 0);
        assertEquals(logger.getModifyRequestCount(), 0);
        assertEquals(logger.getModifyResultCount(), 0);
        assertEquals(logger.getModifyDNRequestCount(), 0);
        assertEquals(logger.getModifyDNResultCount(), 0);
        assertEquals(logger.getSearchRequestCount(), 0);
        assertEquals(logger.getSearchResultEntryCount(), 0);
        assertEquals(logger.getSearchResultReferenceCount(), 0);
        assertEquals(logger.getSearchResultDoneCount(), 0);
        assertEquals(logger.getUnbindRequestCount(), 0);
        assertEquals(logger.getIntermediateResponseCount(), 0);
        try (LDAPConnection connection = new LDAPConnection(options, "localhost", port)) {
            // Verify that the connect was logged.
            assertEquals(logger.getSuccessfulConnectCount(), 1);
            assertEquals(logger.getFailedConnectCount(), 0);
            assertEquals(logger.getDisconnectCount(), 0);
            assertEquals(logger.getAbandonRequestCount(), 0);
            assertEquals(logger.getAddRequestCount(), 0);
            assertEquals(logger.getAddResultCount(), 0);
            assertEquals(logger.getSimpleBindRequestCount(), 0);
            assertEquals(logger.getSASLBindRequestCount(), 0);
            assertEquals(logger.getBindResultCount(), 0);
            assertEquals(logger.getCompareRequestCount(), 0);
            assertEquals(logger.getCompareResultCount(), 0);
            assertEquals(logger.getDeleteRequestCount(), 0);
            assertEquals(logger.getDeleteResultCount(), 0);
            assertEquals(logger.getExtendedRequestCount(), 0);
            assertEquals(logger.getExtendedResultCount(), 0);
            assertEquals(logger.getModifyRequestCount(), 0);
            assertEquals(logger.getModifyResultCount(), 0);
            assertEquals(logger.getModifyDNRequestCount(), 0);
            assertEquals(logger.getModifyDNResultCount(), 0);
            assertEquals(logger.getSearchRequestCount(), 0);
            assertEquals(logger.getSearchResultEntryCount(), 0);
            assertEquals(logger.getSearchResultReferenceCount(), 0);
            assertEquals(logger.getSearchResultDoneCount(), 0);
            assertEquals(logger.getUnbindRequestCount(), 0);
            assertEquals(logger.getIntermediateResponseCount(), 0);
            // Authenticate the connection.
            assertResultCodeEquals(connection, new SimpleBindRequest("cn=Directory Manager", "password"), ResultCode.SUCCESS);
            assertEquals(logger.getSuccessfulConnectCount(), 1);
            assertEquals(logger.getFailedConnectCount(), 0);
            assertEquals(logger.getDisconnectCount(), 0);
            assertEquals(logger.getAbandonRequestCount(), 0);
            assertEquals(logger.getAddRequestCount(), 0);
            assertEquals(logger.getAddResultCount(), 0);
            assertEquals(logger.getSimpleBindRequestCount(), 1);
            assertEquals(logger.getSASLBindRequestCount(), 0);
            assertEquals(logger.getBindResultCount(), 1);
            assertEquals(logger.getCompareRequestCount(), 0);
            assertEquals(logger.getCompareResultCount(), 0);
            assertEquals(logger.getDeleteRequestCount(), 0);
            assertEquals(logger.getDeleteResultCount(), 0);
            assertEquals(logger.getExtendedRequestCount(), 0);
            assertEquals(logger.getExtendedResultCount(), 0);
            assertEquals(logger.getModifyRequestCount(), 0);
            assertEquals(logger.getModifyResultCount(), 0);
            assertEquals(logger.getModifyDNRequestCount(), 0);
            assertEquals(logger.getModifyDNResultCount(), 0);
            assertEquals(logger.getSearchRequestCount(), 0);
            assertEquals(logger.getSearchResultEntryCount(), 0);
            assertEquals(logger.getSearchResultReferenceCount(), 0);
            assertEquals(logger.getSearchResultDoneCount(), 0);
            assertEquals(logger.getUnbindRequestCount(), 0);
            assertEquals(logger.getIntermediateResponseCount(), 0);
            // Send a "Who Am I?" extended request on the connection.
            assertResultCodeEquals(connection, new WhoAmIExtendedRequest(), ResultCode.SUCCESS);
            assertEquals(logger.getSuccessfulConnectCount(), 1);
            assertEquals(logger.getFailedConnectCount(), 0);
            assertEquals(logger.getDisconnectCount(), 0);
            assertEquals(logger.getAbandonRequestCount(), 0);
            assertEquals(logger.getAddRequestCount(), 0);
            assertEquals(logger.getAddResultCount(), 0);
            assertEquals(logger.getSimpleBindRequestCount(), 1);
            assertEquals(logger.getSASLBindRequestCount(), 0);
            assertEquals(logger.getBindResultCount(), 1);
            assertEquals(logger.getCompareRequestCount(), 0);
            assertEquals(logger.getCompareResultCount(), 0);
            assertEquals(logger.getDeleteRequestCount(), 0);
            assertEquals(logger.getDeleteResultCount(), 0);
            assertEquals(logger.getExtendedRequestCount(), 1);
            assertEquals(logger.getExtendedResultCount(), 1);
            assertEquals(logger.getModifyRequestCount(), 0);
            assertEquals(logger.getModifyResultCount(), 0);
            assertEquals(logger.getModifyDNRequestCount(), 0);
            assertEquals(logger.getModifyDNResultCount(), 0);
            assertEquals(logger.getSearchRequestCount(), 0);
            assertEquals(logger.getSearchResultEntryCount(), 0);
            assertEquals(logger.getSearchResultReferenceCount(), 0);
            assertEquals(logger.getSearchResultDoneCount(), 0);
            assertEquals(logger.getUnbindRequestCount(), 0);
            assertEquals(logger.getIntermediateResponseCount(), 0);
            // Send an extended request that will include intermediate responses.
            assertResultCodeEquals(connection, new ExtendedRequest("1.2.3.4"), ResultCode.SUCCESS);
            assertEquals(logger.getSuccessfulConnectCount(), 1);
            assertEquals(logger.getFailedConnectCount(), 0);
            assertEquals(logger.getDisconnectCount(), 0);
            assertEquals(logger.getAbandonRequestCount(), 0);
            assertEquals(logger.getAddRequestCount(), 0);
            assertEquals(logger.getAddResultCount(), 0);
            assertEquals(logger.getSimpleBindRequestCount(), 1);
            assertEquals(logger.getSASLBindRequestCount(), 0);
            assertEquals(logger.getBindResultCount(), 1);
            assertEquals(logger.getCompareRequestCount(), 0);
            assertEquals(logger.getCompareResultCount(), 0);
            assertEquals(logger.getDeleteRequestCount(), 0);
            assertEquals(logger.getDeleteResultCount(), 0);
            assertEquals(logger.getExtendedRequestCount(), 2);
            assertEquals(logger.getExtendedResultCount(), 2);
            assertEquals(logger.getModifyRequestCount(), 0);
            assertEquals(logger.getModifyResultCount(), 0);
            assertEquals(logger.getModifyDNRequestCount(), 0);
            assertEquals(logger.getModifyDNResultCount(), 0);
            assertEquals(logger.getSearchRequestCount(), 0);
            assertEquals(logger.getSearchResultEntryCount(), 0);
            assertEquals(logger.getSearchResultReferenceCount(), 0);
            assertEquals(logger.getSearchResultDoneCount(), 0);
            assertEquals(logger.getUnbindRequestCount(), 0);
            assertEquals(logger.getIntermediateResponseCount(), 5);
            // Send an extended request with an unrecognized request OID.
            assertResultCodeEquals(connection, new ExtendedRequest("4.3.2.1"), ResultCode.UNWILLING_TO_PERFORM);
            assertEquals(logger.getSuccessfulConnectCount(), 1);
            assertEquals(logger.getFailedConnectCount(), 0);
            assertEquals(logger.getDisconnectCount(), 0);
            assertEquals(logger.getAbandonRequestCount(), 0);
            assertEquals(logger.getAddRequestCount(), 0);
            assertEquals(logger.getAddResultCount(), 0);
            assertEquals(logger.getSimpleBindRequestCount(), 1);
            assertEquals(logger.getSASLBindRequestCount(), 0);
            assertEquals(logger.getBindResultCount(), 1);
            assertEquals(logger.getCompareRequestCount(), 0);
            assertEquals(logger.getCompareResultCount(), 0);
            assertEquals(logger.getDeleteRequestCount(), 0);
            assertEquals(logger.getDeleteResultCount(), 0);
            assertEquals(logger.getExtendedRequestCount(), 3);
            assertEquals(logger.getExtendedResultCount(), 3);
            assertEquals(logger.getModifyRequestCount(), 0);
            assertEquals(logger.getModifyResultCount(), 0);
            assertEquals(logger.getModifyDNRequestCount(), 0);
            assertEquals(logger.getModifyDNResultCount(), 0);
            assertEquals(logger.getSearchRequestCount(), 0);
            assertEquals(logger.getSearchResultEntryCount(), 0);
            assertEquals(logger.getSearchResultReferenceCount(), 0);
            assertEquals(logger.getSearchResultDoneCount(), 0);
            assertEquals(logger.getUnbindRequestCount(), 0);
            assertEquals(logger.getIntermediateResponseCount(), 5);
        }
        // Verify that the unbind and disconnect were logged.
        assertEquals(logger.getSuccessfulConnectCount(), 1);
        assertEquals(logger.getFailedConnectCount(), 0);
        assertEquals(logger.getDisconnectCount(), 1);
        assertEquals(logger.getAbandonRequestCount(), 0);
        assertEquals(logger.getAddRequestCount(), 0);
        assertEquals(logger.getAddResultCount(), 0);
        assertEquals(logger.getSimpleBindRequestCount(), 1);
        assertEquals(logger.getSASLBindRequestCount(), 0);
        assertEquals(logger.getBindResultCount(), 1);
        assertEquals(logger.getCompareRequestCount(), 0);
        assertEquals(logger.getCompareResultCount(), 0);
        assertEquals(logger.getDeleteRequestCount(), 0);
        assertEquals(logger.getDeleteResultCount(), 0);
        assertEquals(logger.getExtendedRequestCount(), 3);
        assertEquals(logger.getExtendedResultCount(), 3);
        assertEquals(logger.getModifyRequestCount(), 0);
        assertEquals(logger.getModifyResultCount(), 0);
        assertEquals(logger.getModifyDNRequestCount(), 0);
        assertEquals(logger.getModifyDNResultCount(), 0);
        assertEquals(logger.getSearchRequestCount(), 0);
        assertEquals(logger.getSearchResultEntryCount(), 0);
        assertEquals(logger.getSearchResultReferenceCount(), 0);
        assertEquals(logger.getSearchResultDoneCount(), 0);
        assertEquals(logger.getUnbindRequestCount(), 1);
        assertEquals(logger.getIntermediateResponseCount(), 5);
    } finally {
        ds.shutDown(true);
    }
}
Also used : WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest) InMemoryDirectoryServerConfig(com.unboundid.ldap.listener.InMemoryDirectoryServerConfig) TestIntermediateResponseExtendedOperationHandler(com.unboundid.ldap.listener.TestIntermediateResponseExtendedOperationHandler) Test(org.testng.annotations.Test)

Aggregations

WhoAmIExtendedRequest (com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest)37 Test (org.testng.annotations.Test)31 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)21 WhoAmIExtendedResult (com.unboundid.ldap.sdk.extensions.WhoAmIExtendedResult)15 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)9 Control (com.unboundid.ldap.sdk.Control)8 LDAPException (com.unboundid.ldap.sdk.LDAPException)7 SimpleBindRequest (com.unboundid.ldap.sdk.SimpleBindRequest)7 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)6 AuthorizationIdentityResponseControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl)6 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)4 BindResult (com.unboundid.ldap.sdk.BindResult)4 AddRequest (com.unboundid.ldap.sdk.AddRequest)3 CompareRequest (com.unboundid.ldap.sdk.CompareRequest)3 DeleteRequest (com.unboundid.ldap.sdk.DeleteRequest)3 ExtendedResult (com.unboundid.ldap.sdk.ExtendedResult)3 LDAPConnectionOptions (com.unboundid.ldap.sdk.LDAPConnectionOptions)3 ModifyDNRequest (com.unboundid.ldap.sdk.ModifyDNRequest)3 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)3 PLAINBindRequest (com.unboundid.ldap.sdk.PLAINBindRequest)3