Search in sources :

Example 21 with RootDSE

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();
    }
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Modification(com.unboundid.ldap.sdk.Modification) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) RootDSE(com.unboundid.ldap.sdk.RootDSE) AddRequest(com.unboundid.ldap.sdk.AddRequest) TransactionSpecificationRequestControl(com.unboundid.ldap.sdk.controls.TransactionSpecificationRequestControl) Control(com.unboundid.ldap.sdk.Control) PostReadRequestControl(com.unboundid.ldap.sdk.controls.PostReadRequestControl) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult) TransactionSpecificationRequestControl(com.unboundid.ldap.sdk.controls.TransactionSpecificationRequestControl) Test(org.testng.annotations.Test)

Example 22 with RootDSE

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;
}
Also used : RootDSE(com.unboundid.ldap.sdk.RootDSE)

Example 23 with RootDSE

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);
}
Also used : SSLUtil(com.unboundid.util.ssl.SSLUtil) KeyStoreKeyManager(com.unboundid.util.ssl.KeyStoreKeyManager) TrustStoreTrustManager(com.unboundid.util.ssl.TrustStoreTrustManager) TrustAllTrustManager(com.unboundid.util.ssl.TrustAllTrustManager) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) File(java.io.File) RootDSE(com.unboundid.ldap.sdk.RootDSE) Test(org.testng.annotations.Test)

Example 24 with RootDSE

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);
}
Also used : KeyStoreKeyManager(com.unboundid.util.ssl.KeyStoreKeyManager) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest) TrustAllTrustManager(com.unboundid.util.ssl.TrustAllTrustManager) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) RootDSE(com.unboundid.ldap.sdk.RootDSE) SSLUtil(com.unboundid.util.ssl.SSLUtil) AuthorizationIdentityRequestControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl) Control(com.unboundid.ldap.sdk.Control) IgnoreNoUserModificationRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.IgnoreNoUserModificationRequestControl) AuthorizationIdentityResponseControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult) File(java.io.File) StartTLSExtendedRequest(com.unboundid.ldap.sdk.extensions.StartTLSExtendedRequest) Test(org.testng.annotations.Test)

Example 25 with RootDSE

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());
}
Also used : LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) RootDSE(com.unboundid.ldap.sdk.RootDSE) Test(org.testng.annotations.Test)

Aggregations

RootDSE (com.unboundid.ldap.sdk.RootDSE)32 Test (org.testng.annotations.Test)26 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)23 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)13 ExtendedResult (com.unboundid.ldap.sdk.ExtendedResult)12 Control (com.unboundid.ldap.sdk.Control)11 LDAPException (com.unboundid.ldap.sdk.LDAPException)9 DN (com.unboundid.ldap.sdk.DN)7 AddRequest (com.unboundid.ldap.sdk.AddRequest)6 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)6 SSLUtil (com.unboundid.util.ssl.SSLUtil)6 TrustAllTrustManager (com.unboundid.util.ssl.TrustAllTrustManager)6 Modification (com.unboundid.ldap.sdk.Modification)5 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)4 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)4 SearchResult (com.unboundid.ldap.sdk.SearchResult)4 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)4 AuthorizationIdentityResponseControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl)4 PostReadRequestControl (com.unboundid.ldap.sdk.controls.PostReadRequestControl)4 IgnoreNoUserModificationRequestControl (com.unboundid.ldap.sdk.unboundidds.controls.IgnoreNoUserModificationRequestControl)4