use of com.unboundid.ldap.sdk.RootDSE in project ldapsdk by pingidentity.
the class StartTransactionExtendedRequestTestCase method testAbortTransaction.
/**
* Tests the process of creating a transaction, including multiple operations
* as part of that transaction, and then aborting it.
* <BR><BR>
* Access to a Directory Server instance is required for complete processing.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testAbortTransaction() throws Exception {
if (!isDirectoryInstanceAvailable()) {
return;
}
LDAPConnection conn = getAdminConnection();
RootDSE rootDSE = conn.getRootDSE();
if ((rootDSE == null) || (!rootDSE.supportsExtendedOperation(StartTransactionExtendedRequest.START_TRANSACTION_REQUEST_OID))) {
conn.close();
return;
}
StartTransactionExtendedResult startTxnResult = (StartTransactionExtendedResult) conn.processExtendedOperation(new StartTransactionExtendedRequest());
assertEquals(startTxnResult.getResultCode(), ResultCode.SUCCESS);
ASN1OctetString txnID = startTxnResult.getTransactionID();
assertNotNull(txnID);
assertNotNull(startTxnResult.toString());
Control[] controls = { new TransactionSpecificationRequestControl(txnID) };
AddRequest addRequest = new AddRequest(getTestBaseDN(), getBaseEntryAttributes(), controls);
conn.add(addRequest);
Modification[] mods = { new Modification(ModificationType.REPLACE, "description", "foo") };
ModifyRequest modifyRequest = new ModifyRequest(getTestBaseDN(), mods, controls);
conn.modify(modifyRequest);
ExtendedResult endTxnResult = conn.processExtendedOperation(new EndTransactionExtendedRequest(txnID, false));
assertEquals(endTxnResult.getResultCode(), ResultCode.SUCCESS);
assertNotNull(endTxnResult.toString());
try {
assertNull(conn.getEntry(getTestBaseDN()));
} finally {
conn.close();
}
}
use of com.unboundid.ldap.sdk.RootDSE in project ldapsdk by pingidentity.
the class MoveSubtreeTestCase method serversSupportInteractiveTransactions.
/**
* Determines whether both the source and target servers support interactive
* transactions.
*
* @param sourceConn A connection that may be used to interact with the
* source server.
* @param targetConn A connection that may be used to interact with the
* target server.
*
* @return {@code true} if both servers support interactive transactions, or
* {@code false} if at least one server does not support interactive
* transactions.
*
* @throws Exception If an unexpected problem occurs.
*/
@SuppressWarnings("deprecation")
private static boolean serversSupportInteractiveTransactions(final LDAPConnection sourceConn, final LDAPConnection targetConn) throws Exception {
final RootDSE sourceRootDSE = sourceConn.getRootDSE();
assertNotNull(sourceRootDSE);
if (!sourceRootDSE.supportsExtendedOperation(com.unboundid.ldap.sdk.unboundidds.extensions.StartInteractiveTransactionExtendedRequest.START_INTERACTIVE_TRANSACTION_REQUEST_OID)) {
return false;
}
final RootDSE targetRootDSE = targetConn.getRootDSE();
assertNotNull(targetRootDSE);
if (!targetRootDSE.supportsExtendedOperation(com.unboundid.ldap.sdk.unboundidds.extensions.StartInteractiveTransactionExtendedRequest.START_INTERACTIVE_TRANSACTION_REQUEST_OID)) {
return false;
}
return true;
}
use of com.unboundid.ldap.sdk.RootDSE in project ldapsdk by pingidentity.
the class InMemoryDirectoryServerTestCase method testServerWithSSLAndClientTrustAll.
/**
* Tests the ability to create an in-memory directory server instance that
* uses SSL for secure communication and will use a "trust all" approach for
* client connections created by the server.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testServerWithSSLAndClientTrustAll() 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");
// Create SSLUtil objects for client and server use.
final SSLUtil serverSSLUtil = new SSLUtil(new KeyStoreKeyManager(serverKeyStore, "password".toCharArray(), "JKS", "server-cert"), new TrustStoreTrustManager(serverTrustStore));
final SSLUtil clientSSLUtil = new SSLUtil(new TrustAllTrustManager());
// 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);
final RootDSE rootDSE = dsProvidedConn.getRootDSE();
assertNotNull(rootDSE);
dsProvidedConn.close();
assertNull(dsProvidedConn.getSSLSession());
ds.shutDown(true);
}
use of com.unboundid.ldap.sdk.RootDSE in project ldapsdk by pingidentity.
the class InMemoryDirectoryServerTestCase method testServerWithStartTLS.
/**
* Tests the ability to create an in-memory directory server instance that
* supports the StartTLS extended operation.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testServerWithStartTLS() throws Exception {
// Create the SSL socket factory to use for StartTLS.
final File resourceDir = new File(System.getProperty("unit.resource.dir"));
final File serverKeyStore = new File(resourceDir, "server.keystore");
final SSLUtil serverSSLUtil = new SSLUtil(new KeyStoreKeyManager(serverKeyStore, "password".toCharArray(), "JKS", "server-cert"), new TrustAllTrustManager());
// Create the in-memory directory server instance.
final InMemoryDirectoryServerConfig cfg = new InMemoryDirectoryServerConfig("dc=example,dc=com");
cfg.addAdditionalBindCredentials("cn=Directory Manager", "password");
cfg.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("LDAP+StartTLS", null, 0, serverSSLUtil.createSSLSocketFactory()));
cfg.setCodeLogDetails(createTempFile().getAbsolutePath(), true);
final InMemoryDirectoryServer ds = new InMemoryDirectoryServer(cfg);
ds.startListening();
final int listenPort = ds.getListenPort();
// Verify that we can use the server's getConnection method.
final LDAPConnection conn = ds.getConnection();
assertNull(conn.getSSLSession());
RootDSE rootDSE = conn.getRootDSE();
assertNotNull(rootDSE);
assertTrue(rootDSE.supportsExtendedOperation(StartTLSExtendedRequest.STARTTLS_REQUEST_OID));
// Use the StartTLS extended operation to secure the connection.
final SSLUtil clientSSLUtil = new SSLUtil(new TrustAllTrustManager());
final ExtendedResult startTLSResult = conn.processExtendedOperation(new StartTLSExtendedRequest(clientSSLUtil.createSSLContext()));
assertNotNull(startTLSResult);
assertEquals(startTLSResult.getResultCode(), ResultCode.SUCCESS);
assertNotNull(conn.getSSLSession());
assertNotNull(conn.getSSLSession().getPeerCertificateChain());
assertTrue(conn.getSSLSession().getPeerCertificateChain().length > 0);
// Test an additional set of operations over the newly-secured connection.
conn.bind("cn=Directory Manager", "password");
conn.processExtendedOperation(new WhoAmIExtendedRequest());
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.modify("dn: ou=People,dc=example,dc=com", "changeType: modify", "replace: description", "description: foo");
assertTrue(conn.compare("ou=People,dc=example,dc=com", "description", "foo").compareMatched());
conn.search("dc=example,dc=com", SearchScope.BASE, "(objectClass=*)");
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");
final Control[] abandonControls = { new Control("1.2.3.4", false), new Control("1.2.3.5", false, new ASN1OctetString("foo")) };
conn.abandon(InternalSDKHelper.createAsyncRequestID(1, conn), abandonControls);
final Control[] unbindControls = { new Control("1.2.3.4", false), new Control("1.2.3.5", false, new ASN1OctetString("foo")) };
conn.close(unbindControls);
assertNull(conn.getSSLSession());
ds.shutDown(true);
}
use of com.unboundid.ldap.sdk.RootDSE in project ldapsdk by pingidentity.
the class InMemoryDirectoryServerTestCase method testDefaultUnitTestServerWithSSLAndNoEntries.
/**
* Tests the ability to communicate securely with the default SSL-enabled
* server provided by the unit test framework.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testDefaultUnitTestServerWithSSLAndNoEntries() throws Exception {
final InMemoryDirectoryServer ds = getTestDSWithSSL();
assertNotNull(ds.getClientSocketFactory());
// Verify that we can use the server's getConnection method.
LDAPConnection dsProvidedConn = ds.getConnection();
assertNotNull(dsProvidedConn.getSSLSession());
// Work around a bug in the TLSv3 implementation in some versions of Java 11
// that interfere with the ability to get peer certificates when resuming
// a TLS session. To prevent that from happening here, invalidate the
// TLS session and create a new connection so that it gets a new session.
assertNotNull(dsProvidedConn.getRootDSE());
dsProvidedConn.getSSLSession().invalidate();
dsProvidedConn.close();
dsProvidedConn = ds.getConnection();
assertNotNull(dsProvidedConn.getSSLSession());
// End the workaround.
assertNotNull(dsProvidedConn.getSSLSession().getPeerCertificateChain());
assertTrue(dsProvidedConn.getSSLSession().getPeerCertificateChain().length > 0);
final RootDSE rootDSE = dsProvidedConn.getRootDSE();
assertNotNull(rootDSE);
assertEntryMissing(dsProvidedConn, "dc=example,dc=com");
assertEntryMissing(dsProvidedConn, "ou=People,dc=example,dc=com");
assertEntryMissing(dsProvidedConn, "uid=test.user,ou=People,dc=example,dc=com");
dsProvidedConn.close();
assertNull(dsProvidedConn.getSSLSession());
}
Aggregations