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