Search in sources :

Example 6 with DIGESTMD5BindRequest

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));
}
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) DIGESTMD5BindRequest(com.unboundid.ldap.sdk.DIGESTMD5BindRequest) Test(org.testng.annotations.Test)

Example 7 with DIGESTMD5BindRequest

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));
}
Also used : InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) DIGESTMD5BindRequest(com.unboundid.ldap.sdk.DIGESTMD5BindRequest) Test(org.testng.annotations.Test)

Example 8 with DIGESTMD5BindRequest

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();
    }
}
Also used : SimpleBindRequest(com.unboundid.ldap.sdk.SimpleBindRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) BindRequest(com.unboundid.ldap.sdk.BindRequest) PLAINBindRequest(com.unboundid.ldap.sdk.PLAINBindRequest) DIGESTMD5BindRequest(com.unboundid.ldap.sdk.DIGESTMD5BindRequest) CRAMMD5BindRequest(com.unboundid.ldap.sdk.CRAMMD5BindRequest) SimpleBindRequest(com.unboundid.ldap.sdk.SimpleBindRequest) DIGESTMD5BindRequest(com.unboundid.ldap.sdk.DIGESTMD5BindRequest) PLAINBindRequest(com.unboundid.ldap.sdk.PLAINBindRequest) SearchResult(com.unboundid.ldap.sdk.SearchResult) CRAMMD5BindRequest(com.unboundid.ldap.sdk.CRAMMD5BindRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) ResultCode(com.unboundid.ldap.sdk.ResultCode)

Aggregations

DIGESTMD5BindRequest (com.unboundid.ldap.sdk.DIGESTMD5BindRequest)8 Test (org.testng.annotations.Test)5 BindRequest (com.unboundid.ldap.sdk.BindRequest)4 CRAMMD5BindRequest (com.unboundid.ldap.sdk.CRAMMD5BindRequest)4 PLAINBindRequest (com.unboundid.ldap.sdk.PLAINBindRequest)4 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)3 EXTERNALBindRequest (com.unboundid.ldap.sdk.EXTERNALBindRequest)3 LDAPException (com.unboundid.ldap.sdk.LDAPException)3 ANONYMOUSBindRequest (com.unboundid.ldap.sdk.ANONYMOUSBindRequest)2 GSSAPIBindRequest (com.unboundid.ldap.sdk.GSSAPIBindRequest)2 OAUTHBEARERBindRequest (com.unboundid.ldap.sdk.OAUTHBEARERBindRequest)2 SCRAMSHA1BindRequest (com.unboundid.ldap.sdk.SCRAMSHA1BindRequest)2 SCRAMSHA256BindRequest (com.unboundid.ldap.sdk.SCRAMSHA256BindRequest)2 SCRAMSHA512BindRequest (com.unboundid.ldap.sdk.SCRAMSHA512BindRequest)2 SimpleBindRequest (com.unboundid.ldap.sdk.SimpleBindRequest)2 SingleUseTOTPBindRequest (com.unboundid.ldap.sdk.unboundidds.SingleUseTOTPBindRequest)2 UnboundIDCertificatePlusPasswordBindRequest (com.unboundid.ldap.sdk.unboundidds.UnboundIDCertificatePlusPasswordBindRequest)2 UnboundIDDeliveredOTPBindRequest (com.unboundid.ldap.sdk.unboundidds.UnboundIDDeliveredOTPBindRequest)2 UnboundIDTOTPBindRequest (com.unboundid.ldap.sdk.unboundidds.UnboundIDTOTPBindRequest)2 UnboundIDYubiKeyOTPBindRequest (com.unboundid.ldap.sdk.unboundidds.UnboundIDYubiKeyOTPBindRequest)2