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