Search in sources :

Example 1 with LDAPSearch

use of com.unboundid.ldap.sdk.examples.LDAPSearch in project ldapsdk by pingidentity.

the class SASLUtilsTestCase method testValidCertificatePlusPasswordBindPWPrompted.

/**
 * Tests the ability to create a valid UNBOUNDID-CERTIFICATE-PLUS-PASSWORD
 * bind request when a password must be obtained via prompt.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testValidCertificatePlusPasswordBindPWPrompted() throws Exception {
    final LDAPSearch tool = new LDAPSearch(null, null);
    final BindRequest bindRequest;
    try {
        PasswordReader.setTestReader(new BufferedReader(new InputStreamReader(new ByteArrayInputStream("password\n".getBytes("UTF-8")))));
        bindRequest = SASLUtils.createBindRequest(null, (byte[]) null, false, tool, null, Arrays.asList("mech=UNBOUNDID-CERTIFICATE-PLUS-PASSWORD"));
    } finally {
        PasswordReader.setTestReader(null);
    }
    assertNotNull(bindRequest);
    assertTrue(bindRequest instanceof UnboundIDCertificatePlusPasswordBindRequest);
    final UnboundIDCertificatePlusPasswordBindRequest certPlusPWBind = (UnboundIDCertificatePlusPasswordBindRequest) bindRequest;
    assertNotNull(certPlusPWBind.getPassword());
    assertEquals(certPlusPWBind.getPassword().stringValue(), "password");
}
Also used : UnboundIDCertificatePlusPasswordBindRequest(com.unboundid.ldap.sdk.unboundidds.UnboundIDCertificatePlusPasswordBindRequest) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) LDAPSearch(com.unboundid.ldap.sdk.examples.LDAPSearch) ANONYMOUSBindRequest(com.unboundid.ldap.sdk.ANONYMOUSBindRequest) GSSAPIBindRequest(com.unboundid.ldap.sdk.GSSAPIBindRequest) UnboundIDCertificatePlusPasswordBindRequest(com.unboundid.ldap.sdk.unboundidds.UnboundIDCertificatePlusPasswordBindRequest) BindRequest(com.unboundid.ldap.sdk.BindRequest) SCRAMSHA512BindRequest(com.unboundid.ldap.sdk.SCRAMSHA512BindRequest) SingleUseTOTPBindRequest(com.unboundid.ldap.sdk.unboundidds.SingleUseTOTPBindRequest) PLAINBindRequest(com.unboundid.ldap.sdk.PLAINBindRequest) UnboundIDYubiKeyOTPBindRequest(com.unboundid.ldap.sdk.unboundidds.UnboundIDYubiKeyOTPBindRequest) EXTERNALBindRequest(com.unboundid.ldap.sdk.EXTERNALBindRequest) DIGESTMD5BindRequest(com.unboundid.ldap.sdk.DIGESTMD5BindRequest) UnboundIDDeliveredOTPBindRequest(com.unboundid.ldap.sdk.unboundidds.UnboundIDDeliveredOTPBindRequest) OAUTHBEARERBindRequest(com.unboundid.ldap.sdk.OAUTHBEARERBindRequest) UnboundIDTOTPBindRequest(com.unboundid.ldap.sdk.unboundidds.UnboundIDTOTPBindRequest) SCRAMSHA1BindRequest(com.unboundid.ldap.sdk.SCRAMSHA1BindRequest) SCRAMSHA256BindRequest(com.unboundid.ldap.sdk.SCRAMSHA256BindRequest) CRAMMD5BindRequest(com.unboundid.ldap.sdk.CRAMMD5BindRequest) BufferedReader(java.io.BufferedReader) Test(org.testng.annotations.Test)

Example 2 with LDAPSearch

use of com.unboundid.ldap.sdk.examples.LDAPSearch in project ldapsdk by pingidentity.

the class InteractiveCommandLineToolTestCase method testLDAPSearchDefaultValuesQuitBeforeSearch.

/**
 * Tests the ldapsearch tool with a minimal set of arguments.  Default values
 * for all of the arguments will be provided when possible, and the tool will
 * quit before actually attempting a search.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testLDAPSearchDefaultValuesQuitBeforeSearch() throws Exception {
    final InMemoryDirectoryServer ds = getTestDS();
    System.setIn(getInputStream(// Default to localhost for the server address.
    "", // Do not attempt to communicate securely.
    "5", // Server port
    String.valueOf(ds.getListenPort()), // Do not attempt to authenticate.
    "3", // Search base DN.
    "dc=example,dc=com", // First trailing argument.
    "(objectClass=*)", // No more trailing arguments
    "", // Quit.
    "q"));
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final LDAPSearch tool = new LDAPSearch(out, out);
    final ResultCode resultCode = tool.runTool();
    assertEquals(resultCode, ResultCode.SUCCESS, "Tool output:  " + StaticUtils.toUTF8String(out.toByteArray()));
}
Also used : InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) LDAPSearch(com.unboundid.ldap.sdk.examples.LDAPSearch) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResultCode(com.unboundid.ldap.sdk.ResultCode) Test(org.testng.annotations.Test)

Example 3 with LDAPSearch

use of com.unboundid.ldap.sdk.examples.LDAPSearch in project ldapsdk by pingidentity.

the class InteractiveCommandLineToolTestCase method testLDAPSearchStartTLSWithPKCS12Trust.

/**
 * Tests the ldapsearch tool to establish a secure connection over StartTLS
 * with a client certificate and trust based on a PKCS#12 keystore.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testLDAPSearchStartTLSWithPKCS12Trust() throws Exception {
    final InMemoryDirectoryServer ds = getTestDS();
    // Create the SSL socket factory to use for StartTLS.
    final File resourceDir = new File(System.getProperty("unit.resource.dir"));
    final File keyStore = new File(resourceDir, "keystore.p12");
    final SSLUtil serverSSLUtil = new SSLUtil(new KeyStoreKeyManager(keyStore, "password".toCharArray(), "PKCS12", "server-cert"), new TrustAllTrustManager());
    System.setIn(getInputStream(// Server address
    "localhost", // Use StartTLS with non-default settings
    "4", // Present a client certificate from a JKS keystore
    "2", keyStore.getAbsolutePath(), // PIN for the client keystore
    "password", // Certificate nickname
    "server-cert", // Don't authenticate via SASL external
    "2", // Trust using a JKS truststore
    "3", keyStore.getAbsolutePath(), // Trust store PIN
    "password", // Server port
    String.valueOf(ds.getListenPort()), // Use SASL authentication
    "3", // Use SASL PLAIN authentication
    "3", // Authentication ID
    "dn:cn=Directory Manager", // Authorization ID
    "dn:cn=Directory Manager", // Bind password
    "password", // Quit.
    "q"));
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final LDAPSearch tool = new LDAPSearch(out, out);
    final ResultCode resultCode = tool.runTool();
    assertEquals(resultCode, ResultCode.SUCCESS, "Tool output:  " + StaticUtils.toUTF8String(out.toByteArray()));
}
Also used : SSLUtil(com.unboundid.util.ssl.SSLUtil) KeyStoreKeyManager(com.unboundid.util.ssl.KeyStoreKeyManager) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) LDAPSearch(com.unboundid.ldap.sdk.examples.LDAPSearch) TrustAllTrustManager(com.unboundid.util.ssl.TrustAllTrustManager) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) ResultCode(com.unboundid.ldap.sdk.ResultCode) Test(org.testng.annotations.Test)

Example 4 with LDAPSearch

use of com.unboundid.ldap.sdk.examples.LDAPSearch in project ldapsdk by pingidentity.

the class InteractiveCommandLineToolTestCase method testLDAPSearchSSLBlindTrust.

/**
 * Tests the ldapsearch tool to establish a secure connection over SSL with no
 * client certificate and blind trust of the server certificate.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testLDAPSearchSSLBlindTrust() throws Exception {
    final InMemoryDirectoryServer ds = getTestDSWithSSL();
    System.setIn(getInputStream(// Server address
    "localhost", // Use SSL with non-default settings
    "2", // Do not provide a client certificate
    "1", // Blindly trust any server certificate
    "4", // Server port
    String.valueOf(ds.getListenPort()), // Use simple authentication.
    "1", // Bind DN
    "cn=Directory Manager", // Bind password
    "password", // Base DN
    "", // First trailing argument -- filter
    "(objectClass=*)", // Second trailing argument -- return all user attributes
    "*", // Second trailing argument -- return all operational attributes
    "+", // No more trailing arguments.
    "", // Change scope
    "3", // BaseObject scope.
    "1", // Change follow referrals
    "4", // Yes to follow referrals
    "1", // Display the arguments.
    "d", // Return from displaying the arguments.
    "", // Run the tool with the selected arguments.
    "r"));
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final LDAPSearch tool = new LDAPSearch(out, out);
    final ResultCode resultCode = tool.runTool();
    assertEquals(resultCode, ResultCode.SUCCESS, "Tool output:  " + StaticUtils.toUTF8String(out.toByteArray()));
}
Also used : InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) LDAPSearch(com.unboundid.ldap.sdk.examples.LDAPSearch) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResultCode(com.unboundid.ldap.sdk.ResultCode) Test(org.testng.annotations.Test)

Example 5 with LDAPSearch

use of com.unboundid.ldap.sdk.examples.LDAPSearch in project ldapsdk by pingidentity.

the class InteractiveCommandLineToolTestCase method testLDAPSearchStartTLSWithJKSTrust.

/**
 * Tests the ldapsearch tool to establish a secure connection over StartTLS
 * with a client certificate and trust based on a JKS keystore.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testLDAPSearchStartTLSWithJKSTrust() throws Exception {
    // Create the SSL socket factory to use for StartTLS.
    final File resourceDir = new File(System.getProperty("unit.resource.dir"));
    final File clientKeyStore = new File(resourceDir, "client.keystore");
    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()));
    final InMemoryDirectoryServer ds = new InMemoryDirectoryServer(cfg);
    ds.startListening();
    System.setIn(getInputStream(// Server address
    "localhost", // Use StartTLS with non-default settings
    "4", // Present a client certificate from a JKS keystore
    "2", clientKeyStore.getAbsolutePath(), // PIN for the client keystore
    "password", // No certificate nickname
    "", // Don't authenticate via SASL external
    "2", // Trust using a JKS truststore
    "2", serverKeyStore.getAbsolutePath(), // No trust store PIN required
    "", // Server port
    String.valueOf(ds.getListenPort()), // Use SASL authentication
    "2", // Use SASL PLAIN authentication
    "3", // Authentication ID
    "dn:cn=Directory Manager", // No authorization ID
    "", // Bind password
    "password", // Base DN
    "", // First trailing argument -- filter
    "(objectClass=*)", // Second trailing argument -- return all user attributes
    "*", // Second trailing argument -- return all operational attributes
    "+", // No more trailing arguments.
    "", // Change scope
    "3", // BaseObject scope.
    "1", // Change follow referrals
    "4", // Yes to follow referrals
    "1", // Display the arguments.
    "d", // Return from displaying the arguments.
    "", // Run the tool with the selected arguments.
    "r"));
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final LDAPSearch tool = new LDAPSearch(out, out);
    final ResultCode resultCode = tool.runTool();
    assertEquals(resultCode, ResultCode.SUCCESS, "Tool output:  " + StaticUtils.toUTF8String(out.toByteArray()));
    ds.shutDown(true);
}
Also used : SSLUtil(com.unboundid.util.ssl.SSLUtil) KeyStoreKeyManager(com.unboundid.util.ssl.KeyStoreKeyManager) InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) LDAPSearch(com.unboundid.ldap.sdk.examples.LDAPSearch) InMemoryDirectoryServerConfig(com.unboundid.ldap.listener.InMemoryDirectoryServerConfig) TrustAllTrustManager(com.unboundid.util.ssl.TrustAllTrustManager) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) ResultCode(com.unboundid.ldap.sdk.ResultCode) Test(org.testng.annotations.Test)

Aggregations

LDAPSearch (com.unboundid.ldap.sdk.examples.LDAPSearch)39 Test (org.testng.annotations.Test)39 ResultCode (com.unboundid.ldap.sdk.ResultCode)35 File (java.io.File)21 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)20 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 ANONYMOUSBindRequest (com.unboundid.ldap.sdk.ANONYMOUSBindRequest)3 BindRequest (com.unboundid.ldap.sdk.BindRequest)3 CRAMMD5BindRequest (com.unboundid.ldap.sdk.CRAMMD5BindRequest)3 DIGESTMD5BindRequest (com.unboundid.ldap.sdk.DIGESTMD5BindRequest)3 EXTERNALBindRequest (com.unboundid.ldap.sdk.EXTERNALBindRequest)3 GSSAPIBindRequest (com.unboundid.ldap.sdk.GSSAPIBindRequest)3 OAUTHBEARERBindRequest (com.unboundid.ldap.sdk.OAUTHBEARERBindRequest)3 PLAINBindRequest (com.unboundid.ldap.sdk.PLAINBindRequest)3 SCRAMSHA1BindRequest (com.unboundid.ldap.sdk.SCRAMSHA1BindRequest)3 SCRAMSHA256BindRequest (com.unboundid.ldap.sdk.SCRAMSHA256BindRequest)3 SCRAMSHA512BindRequest (com.unboundid.ldap.sdk.SCRAMSHA512BindRequest)3 SingleUseTOTPBindRequest (com.unboundid.ldap.sdk.unboundidds.SingleUseTOTPBindRequest)3 UnboundIDCertificatePlusPasswordBindRequest (com.unboundid.ldap.sdk.unboundidds.UnboundIDCertificatePlusPasswordBindRequest)3 UnboundIDDeliveredOTPBindRequest (com.unboundid.ldap.sdk.unboundidds.UnboundIDDeliveredOTPBindRequest)3