use of com.unboundid.ldap.sdk.RootDSE in project ldapsdk by pingidentity.
the class InMemoryDirectoryServerTestCase method testBaseDNConstructor.
/**
* Tests the ability to create an in-memory directory server instance using
* only a set of base DNs, and then perform a basic set of operations using
* that server.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testBaseDNConstructor() throws Exception {
final InMemoryDirectoryServer ds = new InMemoryDirectoryServer("dc=example,dc=com");
assertNull(ds.getListenAddress());
assertEquals(ds.getListenPort(), -1);
assertNull(ds.getClientSocketFactory());
assertNotNull(ds.getSchema());
assertNotNull(ds.getBaseDNs());
assertFalse(ds.getBaseDNs().isEmpty());
assertEquals(ds.getBaseDNs().size(), 1);
assertTrue(ds.getBaseDNs().contains(new DN("dc=example,dc=com")));
try {
ds.getConnection();
fail("Expected an exception when trying to get a connection to a " + "server that hasn't been started yet.");
} catch (final LDAPException le) {
assertEquals(le.getResultCode(), ResultCode.CONNECT_ERROR);
}
ds.startListening();
final int listenPort = ds.getListenPort();
assertTrue((listenPort >= 1) && (listenPort <= 65535));
assertEquals(listenPort, ds.getListenPort());
assertNull(ds.getListenAddress());
assertNull(ds.getClientSocketFactory());
final LDAPConnection conn = ds.getConnection();
assertNotNull(conn);
assertTrue(conn.isConnected());
assertNull(conn.getSSLSession());
final RootDSE rootDSE = conn.getRootDSE();
assertNotNull(rootDSE);
assertNotNull(rootDSE.getNamingContextDNs());
assertEquals(rootDSE.getNamingContextDNs().length, 1);
assertEquals(new DN(rootDSE.getNamingContextDNs()[0]), new DN("dc=example,dc=com"));
assertNotNull(ds.getEntry(""));
final Schema schema = conn.getSchema();
assertNotNull(schema);
assertNotNull(ds.getEntry("cn=schema"));
LDAPResult result = conn.add("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example");
assertNotNull(result);
assertEquals(result.getResultCode(), ResultCode.SUCCESS);
result = conn.add("dn: ou=People,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: People");
assertNotNull(result);
assertEquals(result.getResultCode(), ResultCode.SUCCESS);
result = conn.add("dn: uid=test.user,ou=People,dc=example,dc=com", "objectClass: top", "objectClass: person", "objectClass: organizationalPerson", "objectClass: inetOrgPerson", "uid: test.user", "givenName: Test", "sn: User", "cn: Test User", "userPassword: password");
assertNotNull(result);
assertEquals(result.getResultCode(), ResultCode.SUCCESS);
result = conn.bind("uid=test.user,ou=People,dc=example,dc=com", "password");
assertNotNull(result);
assertEquals(result.getResultCode(), ResultCode.SUCCESS);
result = conn.compare("uid=test.user,ou=People,dc=example,dc=com", "cn", "Test User");
assertNotNull(result);
assertEquals(result.getResultCode(), ResultCode.COMPARE_TRUE);
result = conn.delete("uid=test.user,ou=People,dc=example,dc=com");
assertNotNull(result);
assertEquals(result.getResultCode(), ResultCode.SUCCESS);
final ExtendedResult extendedResult = conn.processExtendedOperation("1.2.3.4");
assertNotNull(extendedResult);
assertEquals(extendedResult.getResultCode(), ResultCode.UNWILLING_TO_PERFORM);
result = conn.modify("dn: ou=People,dc=example,dc=com", "changetype: modify", "replace: description", "description: foo");
assertNotNull(result);
assertEquals(result.getResultCode(), ResultCode.SUCCESS);
result = conn.modifyDN("ou=People,dc=example,dc=com", "ou=Users", true);
assertNotNull(result);
assertEquals(result.getResultCode(), ResultCode.SUCCESS);
SearchResult searchResult = conn.search("dc=example,dc=com", SearchScope.SUB, "(objectClass=*)");
assertNotNull(searchResult);
assertEquals(searchResult.getResultCode(), ResultCode.SUCCESS);
assertEquals(searchResult.getEntryCount(), 2);
assertEquals(searchResult.getSearchEntries().get(0).getParsedDN(), new DN("dc=example,dc=com"));
assertEquals(searchResult.getSearchEntries().get(1).getParsedDN(), new DN("ou=Users,dc=example,dc=com"));
final Control[] unbindControls = { new Control("1.2.3.4", false), new Control("1.2.3.5", false, new ASN1OctetString("foo")) };
conn.close(unbindControls);
final LDAPConnectionPool pool = ds.getConnectionPool(10);
assertNotNull(pool);
searchResult = pool.search("dc=example,dc=com", SearchScope.SUB, "(objectClass=*)");
assertNotNull(searchResult);
assertEquals(searchResult.getResultCode(), ResultCode.SUCCESS);
assertEquals(searchResult.getEntryCount(), 2);
assertEquals(searchResult.getSearchEntries().get(0).getParsedDN(), new DN("dc=example,dc=com"));
assertEquals(searchResult.getSearchEntries().get(1).getParsedDN(), new DN("ou=Users,dc=example,dc=com"));
pool.close();
assertEquals(ds.countEntries(), 2);
ds.clear();
assertEquals(ds.countEntries(), 0);
ds.shutDown(true);
assertNull(ds.getListenAddress());
assertEquals(ds.getListenPort(), -1);
assertNull(ds.getClientSocketFactory());
}
use of com.unboundid.ldap.sdk.RootDSE in project ldapsdk by pingidentity.
the class InMemoryDirectoryServerTestCase method testServerWithSSLAndClientTrustStore.
/**
* Tests the ability to create an in-memory directory server instance that
* uses SSL for secure communication and will use an explicit trust store for
* client connections created by the server.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testServerWithSSLAndClientTrustStore() throws Exception {
// Get the paths to the client and server key and trust stores.
final File resourceDir = new File(System.getProperty("unit.resource.dir"));
final File serverKeyStore = new File(resourceDir, "server.keystore");
final File serverTrustStore = new File(resourceDir, "server.truststore");
final File clientTrustStore = new File(resourceDir, "client.truststore");
// Create SSLUtil objects for client and server use.
final SSLUtil serverSSLUtil = new SSLUtil(new KeyStoreKeyManager(serverKeyStore, "password".toCharArray()), new TrustStoreTrustManager(serverTrustStore));
final SSLUtil clientSSLUtil = new SSLUtil(new TrustStoreTrustManager(clientTrustStore));
// Create the in-memory directory server instance.
final InMemoryDirectoryServerConfig cfg = new InMemoryDirectoryServerConfig("dc=example,dc=com");
cfg.setListenerConfigs(InMemoryListenerConfig.createLDAPSConfig("LDAPS", null, 0, serverSSLUtil.createSSLServerSocketFactory(), clientSSLUtil.createSSLSocketFactory()));
cfg.setCodeLogDetails(createTempFile().getAbsolutePath(), true);
final InMemoryDirectoryServer ds = new InMemoryDirectoryServer(cfg);
ds.startListening();
final int listenPort = ds.getListenPort();
assertNotNull(ds.getClientSocketFactory());
// Verify that we can use the server's getConnection method.
final LDAPConnection dsProvidedConn = ds.getConnection();
assertNotNull(dsProvidedConn.getSSLSession());
assertNotNull(dsProvidedConn.getSSLSession().getPeerCertificateChain());
assertTrue(dsProvidedConn.getSSLSession().getPeerCertificateChain().length > 0);
RootDSE rootDSE = dsProvidedConn.getRootDSE();
assertNotNull(rootDSE);
dsProvidedConn.close();
assertNull(dsProvidedConn.getSSLSession());
// Verify that we can create an SSL client connection with a trust all
// trust manager.
final SSLUtil trustAllSSLUtil = new SSLUtil(new TrustAllTrustManager());
final LDAPConnection trustAllConn = new LDAPConnection(trustAllSSLUtil.createSSLSocketFactory(), "127.0.0.1", listenPort);
assertNotNull(trustAllConn.getSSLSession());
assertNotNull(trustAllConn.getSSLSession().getPeerCertificateChain());
assertTrue(trustAllConn.getSSLSession().getPeerCertificateChain().length > 0);
rootDSE = trustAllConn.getRootDSE();
assertNotNull(rootDSE);
trustAllConn.close();
assertNull(trustAllConn.getSSLSession());
ds.shutDown(true);
}
use of com.unboundid.ldap.sdk.RootDSE in project ldapsdk by pingidentity.
the class InMemoryDirectoryServerConfigTestCase method testSASLBindHandlers.
/**
* Tests the behavior of the methods for the SASL bind handlers.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSASLBindHandlers() throws Exception {
final InMemoryDirectoryServerConfig cfg = new InMemoryDirectoryServerConfig("dc=example,dc=com");
assertNotNull(cfg.getSASLBindHandlers());
assertFalse(cfg.getSASLBindHandlers().isEmpty());
assertEquals(cfg.getSASLBindHandlers().size(), 1);
assertNotNull(cfg.toString());
InMemoryDirectoryServer ds = new InMemoryDirectoryServer(cfg);
RootDSE rootDSE = RootDSE.getRootDSE(ds);
assertTrue(rootDSE.supportsSASLMechanism("PLAIN"));
cfg.addSASLBindHandler(new TestSASLBindHandler());
assertFalse(cfg.getSASLBindHandlers().isEmpty());
assertEquals(cfg.getSASLBindHandlers().size(), 2);
ds = new InMemoryDirectoryServer(cfg);
rootDSE = RootDSE.getRootDSE(ds);
assertTrue(rootDSE.supportsSASLMechanism("PLAIN"));
assertTrue(rootDSE.supportsSASLMechanism("TEST"));
cfg.getSASLBindHandlers().clear();
assertTrue(cfg.getSASLBindHandlers().isEmpty());
assertNotNull(cfg.toString());
ds = new InMemoryDirectoryServer(cfg);
rootDSE = RootDSE.getRootDSE(ds);
assertFalse(rootDSE.supportsSASLMechanism("PLAIN"));
cfg.addSASLBindHandler(new PLAINBindHandler());
assertNotNull(cfg.toString());
ds = new InMemoryDirectoryServer(cfg);
rootDSE = RootDSE.getRootDSE(ds);
assertTrue(rootDSE.supportsSASLMechanism("PLAIN"));
}
use of com.unboundid.ldap.sdk.RootDSE in project ldapsdk by pingidentity.
the class InMemoryDirectoryServerLDAPInterfaceTestCase method testGetRootDSE.
/**
* Tests the {@code getRootDSE} method.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testGetRootDSE() throws Exception {
ds.restoreSnapshot(snapshot);
final RootDSE rootDSE = ds.getRootDSE();
assertNotNull(rootDSE);
assertNotNull(rootDSE.getNamingContextDNs());
assertEquals(rootDSE.getNamingContextDNs().length, 2);
assertEquals(new DN(rootDSE.getNamingContextDNs()[0]), new DN("dc=example,dc=com"));
assertEquals(new DN(rootDSE.getNamingContextDNs()[1]), new DN("o=example.com"));
assertNotNull(rootDSE.getSubschemaSubentryDN());
assertEquals(new DN(rootDSE.getSubschemaSubentryDN()), new DN("cn=schema"));
assertNotNull(rootDSE.getSupportedControlOIDs());
assertTrue(rootDSE.supportsControl(AssertionRequestControl.ASSERTION_REQUEST_OID));
assertTrue(rootDSE.supportsControl(AuthorizationIdentityRequestControl.AUTHORIZATION_IDENTITY_REQUEST_OID));
assertTrue(rootDSE.supportsControl(DraftLDUPSubentriesRequestControl.SUBENTRIES_REQUEST_OID));
assertTrue(rootDSE.supportsControl(ManageDsaITRequestControl.MANAGE_DSA_IT_REQUEST_OID));
assertTrue(rootDSE.supportsControl(PermissiveModifyRequestControl.PERMISSIVE_MODIFY_REQUEST_OID));
assertTrue(rootDSE.supportsControl(PostReadRequestControl.POST_READ_REQUEST_OID));
assertTrue(rootDSE.supportsControl(PreReadRequestControl.PRE_READ_REQUEST_OID));
assertTrue(rootDSE.supportsControl(ProxiedAuthorizationV1RequestControl.PROXIED_AUTHORIZATION_V1_REQUEST_OID));
assertTrue(rootDSE.supportsControl(ProxiedAuthorizationV2RequestControl.PROXIED_AUTHORIZATION_V2_REQUEST_OID));
assertTrue(rootDSE.supportsControl(RFC3672SubentriesRequestControl.SUBENTRIES_REQUEST_OID));
assertTrue(rootDSE.supportsControl(ServerSideSortRequestControl.SERVER_SIDE_SORT_REQUEST_OID));
assertTrue(rootDSE.supportsControl(SimplePagedResultsControl.PAGED_RESULTS_OID));
assertTrue(rootDSE.supportsControl(SubtreeDeleteRequestControl.SUBTREE_DELETE_REQUEST_OID));
assertTrue(rootDSE.supportsControl(TransactionSpecificationRequestControl.TRANSACTION_SPECIFICATION_REQUEST_OID));
assertTrue(rootDSE.supportsControl(VirtualListViewRequestControl.VIRTUAL_LIST_VIEW_REQUEST_OID));
assertNotNull(rootDSE.getSupportedExtendedOperationOIDs());
assertTrue(rootDSE.supportsExtendedOperation(EndTransactionExtendedRequest.END_TRANSACTION_REQUEST_OID));
assertTrue(rootDSE.supportsExtendedOperation(PasswordModifyExtendedRequest.PASSWORD_MODIFY_REQUEST_OID));
assertTrue(rootDSE.supportsExtendedOperation(StartTransactionExtendedRequest.START_TRANSACTION_REQUEST_OID));
assertTrue(rootDSE.supportsExtendedOperation(WhoAmIExtendedRequest.WHO_AM_I_REQUEST_OID));
assertNotNull(rootDSE.getSupportedFeatureOIDs());
assertTrue(rootDSE.supportsFeature("1.3.6.1.4.1.4203.1.5.1"));
assertTrue(rootDSE.supportsFeature("1.3.6.1.4.1.4203.1.5.2"));
assertTrue(rootDSE.supportsFeature("1.3.6.1.4.1.4203.1.5.3"));
assertTrue(rootDSE.supportsFeature("1.3.6.1.1.14"));
assertNotNull(rootDSE.getSupportedLDAPVersions());
assertEquals(rootDSE.getSupportedLDAPVersions().length, 1);
assertEquals(rootDSE.getSupportedLDAPVersions()[0], 3);
assertTrue(rootDSE.supportsLDAPVersion(3));
assertNotNull(rootDSE.getSupportedSASLMechanismNames());
assertTrue(rootDSE.supportsSASLMechanism("PLAIN"));
assertNotNull(rootDSE.getVendorName());
assertNotNull(rootDSE.getVendorVersion());
}
use of com.unboundid.ldap.sdk.RootDSE in project ldapsdk by pingidentity.
the class SanityCheck method validateSDKIsUsable.
/**
* Validates that the SDK appears to be usable by at least instantiating some
* key SDK data structures. If a directory server instance is available, then
* try to communicate with it.
*
* @throws BuildException If a problem occurs while trying to use the SDK.
*/
private void validateSDKIsUsable() throws BuildException {
// First, try to instantiate common SDK data structures.
try {
final LDAPConnection connection = new LDAPConnection();
final Attribute attribute = new Attribute("name", "value");
final DN dn = new DN("dc=example,dc=com");
final Entry entry = new Entry("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example");
final Filter filter = Filter.create("(objectClass=*)");
final Modification mod = new Modification(ModificationType.REPLACE, "foo", "bar");
} catch (final Exception e) {
throw new BuildException("ERROR: Unable to instantiate common SDK " + "data structures: " + e, e);
}
// If it appears that a directory server instance is available, then verify
// that we can communicate with it.
String address = dsHost;
if ((address == null) || (address.length() == 0) || (address.equals("${ds.host}"))) {
address = "127.0.0.1";
}
int port = -1;
if (dsPort != null) {
try {
port = Integer.parseInt(dsPort);
} catch (final Exception e) {
}
}
if ((port > 0) && (port < 65536)) {
try {
final LDAPConnection conn = new LDAPConnection(address, port);
final RootDSE rootDSE = conn.getRootDSE();
conn.close();
} catch (final LDAPException le) {
throw new BuildException("ERROR: Unable to retrieve root DSE from " + "directory server " + address + ':' + port + ": " + le, le);
}
}
}
Aggregations