use of com.unboundid.ldap.sdk.DIGESTMD5BindRequest in project ldapsdk by pingidentity.
the class SASLUtilsTestCase method testValidDIGESTMD5WithMinimalProperties.
/**
* Tests the ability to create a valid DIGEST-MD5 bind request with a minimal
* set of properties.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testValidDIGESTMD5WithMinimalProperties() throws Exception {
final BindRequest bindRequest = SASLUtils.createBindRequest(null, "password", null, "mech=DIGEST-MD5", "authID=u:test.user");
assertNotNull(bindRequest);
assertTrue(bindRequest instanceof DIGESTMD5BindRequest);
final DIGESTMD5BindRequest digestMD5Bind = (DIGESTMD5BindRequest) bindRequest;
assertNotNull(digestMD5Bind.getAuthenticationID());
assertEquals(digestMD5Bind.getAuthenticationID(), "u:test.user");
assertNotNull(digestMD5Bind.getPasswordString());
assertEquals(digestMD5Bind.getPasswordString(), "password");
assertNull(digestMD5Bind.getAuthorizationID());
assertNull(digestMD5Bind.getRealm());
assertNotNull(digestMD5Bind.getAllowedQoP());
assertEquals(digestMD5Bind.getAllowedQoP(), Arrays.asList(SASLQualityOfProtection.AUTH));
}
use of com.unboundid.ldap.sdk.DIGESTMD5BindRequest in project ldapsdk by pingidentity.
the class AuthenticationDetailsTestCase method testAuthTypeDIGESTMD5NonAnonymousQoPArray.
/**
* Tests the behavior for the case in which the JSON object has an
* authentication-details field that has an authentication type of DIGEST-MD5
* and is configured for non-anonymous authentication with an array of
* quality of protection values.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testAuthTypeDIGESTMD5NonAnonymousQoPArray() 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", "DIGEST-MD5"), new JSONField("authentication-id", "u:john.doe"), new JSONField("authorization-id", "u:someone.else"), new JSONField("password", "password"), new JSONField("realm", "dc=example,dc=com"), new JSONField("qop", new JSONArray(new JSONString("auth-conf"), new JSONString("auth-int"), new JSONString("auth"))))));
final LDAPConnectionDetailsJSONSpecification spec = new LDAPConnectionDetailsJSONSpecification(o);
assertNotNull(spec.getBindRequest());
assertTrue(spec.getBindRequest() instanceof DIGESTMD5BindRequest);
final DIGESTMD5BindRequest bindRequest = (DIGESTMD5BindRequest) spec.getBindRequest();
assertEquals(bindRequest.getAuthenticationID(), "u:john.doe");
assertEquals(bindRequest.getAuthorizationID(), "u:someone.else");
assertEquals(bindRequest.getPasswordString(), "password");
assertEquals(bindRequest.getRealm(), "dc=example,dc=com");
assertNotNull(bindRequest.getAllowedQoP());
assertEquals(bindRequest.getAllowedQoP(), Arrays.asList(SASLQualityOfProtection.AUTH_CONF, SASLQualityOfProtection.AUTH_INT, SASLQualityOfProtection.AUTH));
}
use of com.unboundid.ldap.sdk.DIGESTMD5BindRequest in project ldapsdk by pingidentity.
the class AuthRateThread method run.
/**
* Performs all search processing for this thread.
*/
@Override()
public void run() {
try {
authThread.set(currentThread());
runningThreads.incrementAndGet();
try {
startBarrier.await();
} catch (final Exception e) {
Debug.debugException(e);
}
while (!stopRequested.get()) {
if (searchConnection == null) {
try {
searchConnection = authRate.getConnection();
} catch (final LDAPException le) {
Debug.debugException(le);
errorCounter.incrementAndGet();
final ResultCode rc = le.getResultCode();
rcCounter.increment(rc);
resultCode.compareAndSet(null, rc);
if (fixedRateBarrier != null) {
fixedRateBarrier.await();
}
continue;
}
}
if (bindConnection == null) {
try {
bindConnection = authRate.getConnection();
} catch (final LDAPException le) {
Debug.debugException(le);
errorCounter.incrementAndGet();
final ResultCode rc = le.getResultCode();
rcCounter.increment(rc);
resultCode.compareAndSet(null, rc);
if (fixedRateBarrier != null) {
fixedRateBarrier.await();
}
continue;
}
}
if (!bindOnly) {
try {
searchRequest.setBaseDN(baseDN.nextValue());
searchRequest.setFilter(filter.nextValue());
} catch (final LDAPException le) {
Debug.debugException(le);
errorCounter.incrementAndGet();
final ResultCode rc = le.getResultCode();
rcCounter.increment(rc);
resultCode.compareAndSet(null, rc);
continue;
}
}
// wait until starting the next authorization.
if (fixedRateBarrier != null) {
fixedRateBarrier.await();
}
final long startTime = System.nanoTime();
try {
final String bindDN;
if (bindOnly) {
bindDN = baseDN.nextValue();
} else {
final SearchResult r = searchConnection.search(searchRequest);
switch(r.getEntryCount()) {
case 0:
errorCounter.incrementAndGet();
rcCounter.increment(ResultCode.NO_RESULTS_RETURNED);
resultCode.compareAndSet(null, ResultCode.NO_RESULTS_RETURNED);
continue;
case 1:
// This is acceptable, and we can continue processing.
bindDN = r.getSearchEntries().get(0).getDN();
break;
default:
errorCounter.incrementAndGet();
rcCounter.increment(ResultCode.MORE_RESULTS_TO_RETURN);
resultCode.compareAndSet(null, ResultCode.MORE_RESULTS_TO_RETURN);
continue;
}
}
BindRequest bindRequest = null;
switch(authType) {
case AUTH_TYPE_SIMPLE:
bindRequest = new SimpleBindRequest(bindDN, userPassword, bindControls);
break;
case AUTH_TYPE_CRAM_MD5:
bindRequest = new CRAMMD5BindRequest("dn:" + bindDN, userPassword, bindControls);
break;
case AUTH_TYPE_DIGEST_MD5:
bindRequest = new DIGESTMD5BindRequest("dn:" + bindDN, null, userPassword, null, bindControls);
break;
case AUTH_TYPE_PLAIN:
bindRequest = new PLAINBindRequest("dn:" + bindDN, userPassword, bindControls);
break;
}
bindConnection.bind(bindRequest);
} catch (final LDAPException le) {
Debug.debugException(le);
errorCounter.incrementAndGet();
final ResultCode rc = le.getResultCode();
rcCounter.increment(rc);
resultCode.compareAndSet(null, rc);
if (!le.getResultCode().isConnectionUsable()) {
searchConnection.close();
searchConnection = null;
bindConnection.close();
bindConnection = null;
}
} finally {
authCounter.incrementAndGet();
authDurations.addAndGet(System.nanoTime() - startTime);
}
}
} finally {
if (searchConnection != null) {
searchConnection.close();
}
if (bindConnection != null) {
bindConnection.close();
}
authThread.set(null);
runningThreads.decrementAndGet();
}
}
Aggregations