Search in sources :

Example 16 with PLAINBindRequest

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

the class SASLUtilsTestCase method testValidPLAINBindWithAuthzID.

/**
 * Tests the ability to create a valid PLAIN bind request with an alternate
 * authorization ID.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testValidPLAINBindWithAuthzID() throws Exception {
    final BindRequest bindRequest = SASLUtils.createBindRequest(null, "password", null, "mech=PLAIN", "authID=u:test.user", "authzID=u:another.user");
    assertNotNull(bindRequest);
    assertTrue(bindRequest instanceof PLAINBindRequest);
    final PLAINBindRequest plainBind = (PLAINBindRequest) bindRequest;
    assertNotNull(plainBind.getAuthenticationID());
    assertEquals(plainBind.getAuthenticationID(), "u:test.user");
    assertNotNull(plainBind.getAuthorizationID());
    assertEquals(plainBind.getAuthorizationID(), "u:another.user");
}
Also used : 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) PLAINBindRequest(com.unboundid.ldap.sdk.PLAINBindRequest) Test(org.testng.annotations.Test)

Example 17 with PLAINBindRequest

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

the class SASLUtilsTestCase method testValidPLAINBindWithoutAuthzID.

/**
 * Tests the ability to create a valid PLAIN bind request without an alternate
 * authorization ID.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testValidPLAINBindWithoutAuthzID() throws Exception {
    final BindRequest bindRequest = SASLUtils.createBindRequest(null, "password", null, "mech=PLAIN", "authID=u:test.user");
    assertNotNull(bindRequest);
    assertTrue(bindRequest instanceof PLAINBindRequest);
    final PLAINBindRequest plainBind = (PLAINBindRequest) bindRequest;
    assertNotNull(plainBind.getAuthenticationID());
    assertEquals(plainBind.getAuthenticationID(), "u:test.user");
    assertNull(plainBind.getAuthorizationID());
}
Also used : 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) PLAINBindRequest(com.unboundid.ldap.sdk.PLAINBindRequest) Test(org.testng.annotations.Test)

Example 18 with PLAINBindRequest

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

the class MultiServerLDAPCommandLineToolTestCase method testTwoServersWithPrefix.

/**
 * Tests the ability to work with two servers using only a name prefix.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testTwoServersWithPrefix() throws Exception {
    final String[] prefixes = { "source", "target" };
    final String[] suffixes = null;
    final TestMultiServerLDAPCommandLineTool t = new TestMultiServerLDAPCommandLineTool(prefixes, suffixes);
    final ResultCode resultCode = t.runTool("--sourceHostname", "source.example.com", "--sourcePort", "123", "--sourceBindDN", "cn=Source Bind DN", "--sourceBindPassword", "sourcePassword", "--targetHostname", "target.example.com", "--targetPort", "456", "--targetUseSSL", "--targetTrustAll", "--targetBindDN", "", "--targetSASLOption", "mech=PLAIN", "--targetSASLOption", "authID=dn:cn=Target Bind DN", "--targetBindPassword", "targetPassword");
    assertEquals(resultCode, ResultCode.SUCCESS);
    assertNotNull(t.getConnectionOptions());
    final ServerSet sourceSet = t.createServerSet(0);
    assertNotNull(sourceSet);
    assertTrue(sourceSet instanceof SingleServerSet);
    final SingleServerSet sourceSingleSet = (SingleServerSet) sourceSet;
    assertEquals(sourceSingleSet.getAddress(), "source.example.com");
    assertEquals(sourceSingleSet.getPort(), 123);
    assertNotNull(sourceSingleSet.getSocketFactory());
    final ServerSet targetSet = t.createServerSet(1);
    assertNotNull(targetSet);
    assertTrue(targetSet instanceof SingleServerSet);
    final SingleServerSet targetSingleSet = (SingleServerSet) targetSet;
    assertEquals(targetSingleSet.getAddress(), "target.example.com");
    assertEquals(targetSingleSet.getPort(), 456);
    assertNotNull(targetSingleSet.getSocketFactory());
    assertNull(t.createSSLUtil(0));
    assertNotNull(t.createSSLUtil(1));
    final BindRequest sourceBindRequest = t.createBindRequest(0);
    assertTrue(sourceBindRequest instanceof SimpleBindRequest);
    final SimpleBindRequest sourceSimpleRequest = (SimpleBindRequest) sourceBindRequest;
    assertEquals(new DN(sourceSimpleRequest.getBindDN()), new DN("cn=Source Bind DN"));
    assertEquals(sourceSimpleRequest.getPassword().stringValue(), "sourcePassword");
    final BindRequest targetBindRequest = t.createBindRequest(1);
    assertTrue(targetBindRequest instanceof PLAINBindRequest);
    final PLAINBindRequest targetPLAINRequest = (PLAINBindRequest) targetBindRequest;
    assertEquals(targetPLAINRequest.getAuthenticationID(), "dn:cn=Target Bind DN");
    assertEquals(targetPLAINRequest.getPasswordString(), "targetPassword");
}
Also used : SingleServerSet(com.unboundid.ldap.sdk.SingleServerSet) ServerSet(com.unboundid.ldap.sdk.ServerSet) SimpleBindRequest(com.unboundid.ldap.sdk.SimpleBindRequest) SingleServerSet(com.unboundid.ldap.sdk.SingleServerSet) BindRequest(com.unboundid.ldap.sdk.BindRequest) PLAINBindRequest(com.unboundid.ldap.sdk.PLAINBindRequest) SimpleBindRequest(com.unboundid.ldap.sdk.SimpleBindRequest) PLAINBindRequest(com.unboundid.ldap.sdk.PLAINBindRequest) DN(com.unboundid.ldap.sdk.DN) ResultCode(com.unboundid.ldap.sdk.ResultCode) Test(org.testng.annotations.Test)

Example 19 with PLAINBindRequest

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

the class LDAPDebuggerTestCase method testFailedSASLPLAINBind.

/**
 * Provides test coverage for a failed SASL PLAIN bind operation.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testFailedSASLPLAINBind() throws Exception {
    TestRequestHandler.setReturnOp(new BindResponseProtocolOp(32, "dc=example,dc=com", "msg", Arrays.asList("ldap://server1.example.com/dc=example,dc=com", "ldap://server2.example.com/dc=example,dc=com"), new ASN1OctetString("foo")));
    conn.bind(new PLAINBindRequest("u:admin", "wrong", new ManageDsaITRequestControl(), new AuthorizationIdentityRequestControl()));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) BindResponseProtocolOp(com.unboundid.ldap.protocol.BindResponseProtocolOp) PLAINBindRequest(com.unboundid.ldap.sdk.PLAINBindRequest) AuthorizationIdentityRequestControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl) ManageDsaITRequestControl(com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl) Test(org.testng.annotations.Test)

Example 20 with PLAINBindRequest

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

the class AuthenticationDetailsTestCase method testAuthTypePLAINNonAnonymous.

/**
 * Tests the behavior for the case in which the JSON object has an
 * authentication-details field that has an authentication type of PLAIN and
 * is configured for non-anonymous authentication.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testAuthTypePLAINNonAnonymous() throws Exception {
    final InMemoryDirectoryServer ds = getTestDS();
    final JSONObject o = new JSONObject(new JSONField("server-details", new JSONObject(new JSONField("single-server", new JSONObject(new JSONField("address", "localhost"), new JSONField("port", ds.getListenPort()))))), new JSONField("authentication-details", new JSONObject(new JSONField("authentication-type", "PLAIN"), new JSONField("authentication-id", "u:john.doe"), new JSONField("authorization-id", "u:another.user"), new JSONField("password", "password"))));
    final LDAPConnectionDetailsJSONSpecification spec = new LDAPConnectionDetailsJSONSpecification(o);
    assertNotNull(spec.getBindRequest());
    assertTrue(spec.getBindRequest() instanceof PLAINBindRequest);
    final PLAINBindRequest bindRequest = (PLAINBindRequest) spec.getBindRequest();
    assertEquals(bindRequest.getAuthenticationID(), "u:john.doe");
    assertEquals(bindRequest.getAuthorizationID(), "u:another.user");
    assertEquals(bindRequest.getPasswordString(), "password");
}
Also used : InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) PLAINBindRequest(com.unboundid.ldap.sdk.PLAINBindRequest) Test(org.testng.annotations.Test)

Aggregations

PLAINBindRequest (com.unboundid.ldap.sdk.PLAINBindRequest)22 Test (org.testng.annotations.Test)18 SimpleBindRequest (com.unboundid.ldap.sdk.SimpleBindRequest)12 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)11 LDAPException (com.unboundid.ldap.sdk.LDAPException)8 BindRequest (com.unboundid.ldap.sdk.BindRequest)7 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)6 BindResult (com.unboundid.ldap.sdk.BindResult)6 CRAMMD5BindRequest (com.unboundid.ldap.sdk.CRAMMD5BindRequest)5 DN (com.unboundid.ldap.sdk.DN)5 DIGESTMD5BindRequest (com.unboundid.ldap.sdk.DIGESTMD5BindRequest)4 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)4 Control (com.unboundid.ldap.sdk.Control)3 EXTERNALBindRequest (com.unboundid.ldap.sdk.EXTERNALBindRequest)3 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)3 ResultCode (com.unboundid.ldap.sdk.ResultCode)3 AuthorizationIdentityResponseControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl)3 WhoAmIExtendedRequest (com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest)3 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)2 BindResponseProtocolOp (com.unboundid.ldap.protocol.BindResponseProtocolOp)2