Search in sources :

Example 1 with SimpleTestDigestAuthenticator

use of org.pac4j.http.credentials.authenticator.test.SimpleTestDigestAuthenticator in project pac4j by pac4j.

the class DirectDigestAuthClientTests method testAuthentication.

@Test
public void testAuthentication() {
    final DirectDigestAuthClient client = new DirectDigestAuthClient(new SimpleTestDigestAuthenticator());
    client.setRealm(REALM);
    final MockWebContext context = MockWebContext.create();
    context.addRequestHeader(AUTHORIZATION_HEADER, DIGEST_AUTHORIZATION_HEADER_VALUE);
    context.setRequestMethod(HTTP_METHOD.GET.name());
    final DigestCredentials credentials = client.getCredentials(context);
    final CommonProfile profile = client.getUserProfile(credentials, context);
    String ha1 = CredentialUtil.encryptMD5(USERNAME + ":" + REALM + ":" + PASSWORD);
    String serverDigest1 = credentials.calculateServerDigest(true, ha1);
    String serverDigest2 = credentials.calculateServerDigest(false, PASSWORD);
    assertEquals(DIGEST_RESPONSE, serverDigest1);
    assertEquals(DIGEST_RESPONSE, serverDigest2);
    assertEquals(USERNAME, profile.getId());
}
Also used : DigestCredentials(org.pac4j.http.credentials.DigestCredentials) MockWebContext(org.pac4j.core.context.MockWebContext) SimpleTestDigestAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestDigestAuthenticator) CommonProfile(org.pac4j.core.profile.CommonProfile) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 MockWebContext (org.pac4j.core.context.MockWebContext)1 CommonProfile (org.pac4j.core.profile.CommonProfile)1 DigestCredentials (org.pac4j.http.credentials.DigestCredentials)1 SimpleTestDigestAuthenticator (org.pac4j.http.credentials.authenticator.test.SimpleTestDigestAuthenticator)1