Search in sources :

Example 21 with WhoAmIExtendedRequest

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

the class DSEETestCase method testWhoAmI.

/**
 * Tests the ability to use the "Who Am I?" extended request and result.
 * <BR><BR>
 * Access to a Sun DSEE instance is required for complete processing.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testWhoAmI() throws Exception {
    if (!available) {
        return;
    }
    LDAPConnection conn = getAdminDSEEConnection();
    try {
        ExtendedResult extendedResult = conn.processExtendedOperation(new WhoAmIExtendedRequest());
        assertNotNull(extendedResult);
        assertEquals(extendedResult.getResultCode(), ResultCode.SUCCESS);
        assertTrue(extendedResult instanceof WhoAmIExtendedResult);
        WhoAmIExtendedResult whoAmIResult = (WhoAmIExtendedResult) extendedResult;
        String authzID = whoAmIResult.getAuthorizationID();
        assertNotNull(authzID);
        assertTrue(authzID.startsWith("dn:"));
        assertEquals(new DN(authzID.substring(3)), new DN(getTestBindDN()));
    } finally {
        conn.close();
    }
}
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 22 with WhoAmIExtendedRequest

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

the class ConcurrentRequestLimiterRequestHandlerTestCase method testRateLimiterAllSuccessful.

/**
 * Tests the behavior of the rate limiter with the default set of operation
 * types and with a semaphore created by the request handler.  All of the
 * operations should be successful.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testRateLimiterAllSuccessful() throws Exception {
    final InMemoryDirectoryServerConfig inMemoryConfig = new InMemoryDirectoryServerConfig("dc=example,dc=com");
    inMemoryConfig.addAdditionalBindCredentials("cn=Directory Manager", "password");
    final InMemoryRequestHandler inMemoryRequestHandler = new InMemoryRequestHandler(inMemoryConfig);
    final ConcurrentRequestLimiterRequestHandler rateLimiterRequestHandler = new ConcurrentRequestLimiterRequestHandler(inMemoryRequestHandler, 1, -1L);
    final LDAPListenerConfig listenerConfig = new LDAPListenerConfig(0, rateLimiterRequestHandler);
    final LDAPListener listener = new LDAPListener(listenerConfig);
    listener.startListening();
    final LDAPConnection conn = new LDAPConnection("127.0.0.1", listener.getListenPort());
    conn.bind("cn=Directory Manager", "password");
    conn.add("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example");
    conn.add("dn: ou=People,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: People");
    conn.search("dc=example,dc=com", SearchScope.SUB, "(objectClass=*)");
    conn.compare("dc=example,dc=com", "dc", "example");
    conn.modify("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: foo");
    conn.modifyDN("ou=People,dc=example,dc=com", "ou=Users", true);
    conn.delete("ou=Users,dc=example,dc=com");
    conn.delete("dc=example,dc=com");
    conn.processExtendedOperation(new WhoAmIExtendedRequest());
    conn.abandon(InternalSDKHelper.createAsyncRequestID(1, conn));
    conn.close();
    listener.shutDown(true);
}
Also used : WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) Test(org.testng.annotations.Test)

Example 23 with WhoAmIExtendedRequest

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

the class ConcurrentRequestLimiterRequestHandlerTestCase method testRateLimiterAllFailWithWait.

/**
 * Tests the behavior of the rate limiter in the case where all of the
 * operations fail after a short wait because no semaphore permit is
 * available.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testRateLimiterAllFailWithWait() throws Exception {
    final InMemoryDirectoryServerConfig inMemoryConfig = new InMemoryDirectoryServerConfig("dc=example,dc=com");
    inMemoryConfig.addAdditionalBindCredentials("cn=Directory Manager", "password");
    final InMemoryRequestHandler inMemoryRequestHandler = new InMemoryRequestHandler(inMemoryConfig);
    final Semaphore semaphore = new Semaphore(1);
    final ConcurrentRequestLimiterRequestHandler rateLimiterRequestHandler = new ConcurrentRequestLimiterRequestHandler(inMemoryRequestHandler, semaphore, semaphore, semaphore, semaphore, semaphore, semaphore, semaphore, semaphore, semaphore, 1L);
    final LDAPListenerConfig listenerConfig = new LDAPListenerConfig(0, rateLimiterRequestHandler);
    final LDAPListener listener = new LDAPListener(listenerConfig);
    listener.startListening();
    assertTrue(semaphore.tryAcquire());
    final LDAPConnection conn = new LDAPConnection("127.0.0.1", listener.getListenPort());
    try {
        conn.bind("cn=Directory Manager", "password");
        fail("Expected an exception when trying to bind");
    } catch (final LDAPException le) {
    // This is expected.
    }
    try {
        conn.add("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example");
        fail("Expected an exception when trying to add");
    } catch (final LDAPException le) {
    // This is expected
    }
    try {
        conn.search("dc=example,dc=com", SearchScope.SUB, "(objectClass=*)");
        fail("Expected an exception when trying to search");
    } catch (final LDAPException le) {
    // This is expected
    }
    try {
        conn.compare("dc=example,dc=com", "dc", "example");
        fail("Expected an exception when trying to compare");
    } catch (final LDAPException le) {
    // This is expected
    }
    try {
        conn.modify("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: foo");
        fail("Expected an exception when trying to modify");
    } catch (final LDAPException le) {
    // This is expected
    }
    try {
        conn.modifyDN("ou=People,dc=example,dc=com", "ou=Users", true);
        fail("Expected an exception when trying to modify DN");
    } catch (final LDAPException le) {
    // This is expected
    }
    try {
        conn.delete("dc=example,dc=com");
        fail("Expected an exception when trying to delete");
    } catch (final LDAPException le) {
    // This is expected
    }
    try {
        conn.processExtendedOperation(new WhoAmIExtendedRequest());
    } catch (final LDAPException le) {
    // This may or may not happen, depending on the nature of the problem.
    }
    conn.abandon(InternalSDKHelper.createAsyncRequestID(1, conn));
    conn.close();
    semaphore.release();
    listener.shutDown(true);
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest) Semaphore(java.util.concurrent.Semaphore) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) Test(org.testng.annotations.Test)

Example 24 with WhoAmIExtendedRequest

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

the class ConcurrentRequestLimiterRequestHandlerTestCase method testRateLimiterAllFailNoWait.

/**
 * Tests the behavior of the rate limiter in the case where all of the
 * operations fail without waiting because no semaphore permit is available.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testRateLimiterAllFailNoWait() throws Exception {
    final InMemoryDirectoryServerConfig inMemoryConfig = new InMemoryDirectoryServerConfig("dc=example,dc=com");
    inMemoryConfig.addAdditionalBindCredentials("cn=Directory Manager", "password");
    final InMemoryRequestHandler inMemoryRequestHandler = new InMemoryRequestHandler(inMemoryConfig);
    final Semaphore semaphore = new Semaphore(1);
    final ConcurrentRequestLimiterRequestHandler rateLimiterRequestHandler = new ConcurrentRequestLimiterRequestHandler(inMemoryRequestHandler, semaphore, semaphore, semaphore, semaphore, semaphore, semaphore, semaphore, semaphore, semaphore, 0L);
    final LDAPListenerConfig listenerConfig = new LDAPListenerConfig(0, rateLimiterRequestHandler);
    final LDAPListener listener = new LDAPListener(listenerConfig);
    listener.startListening();
    assertTrue(semaphore.tryAcquire());
    final LDAPConnection conn = new LDAPConnection("127.0.0.1", listener.getListenPort());
    try {
        conn.bind("cn=Directory Manager", "password");
        fail("Expected an exception when trying to bind");
    } catch (final LDAPException le) {
    // This is expected.
    }
    try {
        conn.add("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example");
        fail("Expected an exception when trying to add");
    } catch (final LDAPException le) {
    // This is expected
    }
    try {
        conn.search("dc=example,dc=com", SearchScope.SUB, "(objectClass=*)");
        fail("Expected an exception when trying to search");
    } catch (final LDAPException le) {
    // This is expected
    }
    try {
        conn.compare("dc=example,dc=com", "dc", "example");
        fail("Expected an exception when trying to compare");
    } catch (final LDAPException le) {
    // This is expected
    }
    try {
        conn.modify("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: foo");
        fail("Expected an exception when trying to modify");
    } catch (final LDAPException le) {
    // This is expected
    }
    try {
        conn.modifyDN("ou=People,dc=example,dc=com", "ou=Users", true);
        fail("Expected an exception when trying to modify DN");
    } catch (final LDAPException le) {
    // This is expected
    }
    try {
        conn.delete("dc=example,dc=com");
        fail("Expected an exception when trying to delete");
    } catch (final LDAPException le) {
    // This is expected
    }
    try {
        conn.processExtendedOperation(new WhoAmIExtendedRequest());
    } catch (final LDAPException le) {
    // This may or may not happen, depending on the nature of the problem.
    }
    conn.abandon(InternalSDKHelper.createAsyncRequestID(1, conn));
    conn.close();
    semaphore.release();
    listener.shutDown(true);
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest) Semaphore(java.util.concurrent.Semaphore) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) Test(org.testng.annotations.Test)

Example 25 with WhoAmIExtendedRequest

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

the class InMemoryDirectoryServerLDAPInterfaceTestCase method testExtended.

/**
 * Provides test coverage for the methods that can be used to process extended
 * operations.  This isn't really part of LDAPInterface, but it's close enough
 * to be tested here.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testExtended() throws Exception {
    ds.restoreSnapshot(snapshot);
    // Test the method that takes just an OID.
    ExtendedResult extendedResult = ds.processExtendedOperation("1.2.3.4");
    assertNotNull(extendedResult);
    assertEquals(extendedResult.getResultCode(), ResultCode.UNWILLING_TO_PERFORM);
    // Test the method that takes an OID and value.
    extendedResult = ds.processExtendedOperation("1.2.3.4", new ASN1OctetString());
    assertNotNull(extendedResult);
    assertEquals(extendedResult.getResultCode(), ResultCode.UNWILLING_TO_PERFORM);
    // Test the method that takes a generic extended request.
    extendedResult = ds.processExtendedOperation(new ExtendedRequest("1.2.3.4"));
    assertNotNull(extendedResult);
    assertEquals(extendedResult.getResultCode(), ResultCode.UNWILLING_TO_PERFORM);
    // Test the method that takes a specific extended request.
    extendedResult = ds.processExtendedOperation(new WhoAmIExtendedRequest());
    final WhoAmIExtendedResult whoAmIResult = new WhoAmIExtendedResult(extendedResult);
    assertNotNull(whoAmIResult);
    assertEquals(whoAmIResult.getResultCode(), ResultCode.SUCCESS);
    assertNotNull(whoAmIResult.getAuthorizationID());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) WhoAmIExtendedResult(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedResult) WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest) ExtendedRequest(com.unboundid.ldap.sdk.ExtendedRequest) StartTransactionExtendedRequest(com.unboundid.ldap.sdk.extensions.StartTransactionExtendedRequest) EndTransactionExtendedRequest(com.unboundid.ldap.sdk.extensions.EndTransactionExtendedRequest) WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest) PasswordModifyExtendedRequest(com.unboundid.ldap.sdk.extensions.PasswordModifyExtendedRequest) WhoAmIExtendedResult(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedResult) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult) 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