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();
}
}
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);
}
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);
}
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);
}
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());
}
Aggregations