Search in sources :

Example 91 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class DirectDigestAuthClientTests method testAuthentication.

@Test
public void testAuthentication() {
    final var client = new DirectDigestAuthClient(new SimpleTestDigestAuthenticator());
    client.setRealm(REALM);
    final var context = MockWebContext.create();
    context.addRequestHeader(AUTHORIZATION_HEADER, DIGEST_AUTHORIZATION_HEADER_VALUE);
    context.setRequestMethod(HTTP_METHOD.GET.name());
    final var credentials = (DigestCredentials) client.getCredentials(context, new MockSessionStore()).get();
    final var profile = (CommonProfile) client.getUserProfile(credentials, context, new MockSessionStore()).get();
    var ha1 = CredentialUtil.encryptMD5(USERNAME + ":" + REALM + ":" + PASSWORD);
    var serverDigest1 = credentials.calculateServerDigest(true, ha1);
    var 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) SimpleTestDigestAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestDigestAuthenticator) MockSessionStore(org.pac4j.core.context.session.MockSessionStore) CommonProfile(org.pac4j.core.profile.CommonProfile) Test(org.junit.Test)

Example 92 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class HeaderClientTests method testAuthentication.

@Test
public void testAuthentication() {
    final var client = new HeaderClient(HEADER_NAME, PREFIX_HEADER, new SimpleTestTokenAuthenticator());
    final var context = MockWebContext.create();
    context.addRequestHeader(HEADER_NAME, PREFIX_HEADER + VALUE);
    final var credentials = (TokenCredentials) client.getCredentials(context, new MockSessionStore()).get();
    final var profile = (CommonProfile) client.getUserProfile(credentials, context, new MockSessionStore()).get();
    assertEquals(VALUE, profile.getId());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) CommonProfile(org.pac4j.core.profile.CommonProfile) SimpleTestTokenAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) Test(org.junit.Test)

Example 93 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class ParameterClientTests method testMissingProfileCreator.

@Test
public void testMissingProfileCreator() {
    final var client = new ParameterClient(PARAMETER_NAME, new SimpleTestTokenAuthenticator(), null);
    TestsHelper.expectException(() -> client.getUserProfile(new TokenCredentials(TOKEN), MockWebContext.create(), new MockSessionStore()), TechnicalException.class, "profileCreator cannot be null");
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) SimpleTestTokenAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) Test(org.junit.Test)

Example 94 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class ParameterClientTests method testAuthentication.

@Test
public void testAuthentication() {
    final var client = new ParameterClient(PARAMETER_NAME, new SimpleTestTokenAuthenticator());
    client.setSupportGetRequest(SUPPORT_GET);
    client.setSupportPostRequest(SUPPORT_POST);
    final var context = MockWebContext.create();
    context.addRequestParameter(PARAMETER_NAME, VALUE);
    context.setRequestMethod(HttpConstants.HTTP_METHOD.GET.name());
    final var credentials = (TokenCredentials) client.getCredentials(context, new MockSessionStore()).get();
    final var profile = (CommonProfile) client.getUserProfile(credentials, context, new MockSessionStore()).get();
    assertEquals(VALUE, profile.getId());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) CommonProfile(org.pac4j.core.profile.CommonProfile) SimpleTestTokenAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) Test(org.junit.Test)

Example 95 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class IndirectBasicAuthClientTests method testMissingProfileCreator.

@Test
public void testMissingProfileCreator() {
    final var basicAuthClient = new IndirectBasicAuthClient(NAME, new SimpleTestUsernamePasswordAuthenticator());
    basicAuthClient.setCallbackUrl(CALLBACK_URL);
    basicAuthClient.setProfileCreator(null);
    TestsHelper.expectException(() -> basicAuthClient.getUserProfile(new UsernamePasswordCredentials(USERNAME, PASSWORD), MockWebContext.create(), new MockSessionStore()), TechnicalException.class, "profileCreator cannot be null");
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) SimpleTestUsernamePasswordAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Test(org.junit.Test)

Aggregations

MockSessionStore (org.pac4j.core.context.session.MockSessionStore)164 Test (org.junit.Test)151 FoundAction (org.pac4j.core.exception.http.FoundAction)29 SessionStore (org.pac4j.core.context.session.SessionStore)22 CommonProfile (org.pac4j.core.profile.CommonProfile)20 TokenCredentials (org.pac4j.core.credentials.TokenCredentials)19 UsernamePasswordCredentials (org.pac4j.core.credentials.UsernamePasswordCredentials)17 MockWebContext (org.pac4j.core.context.MockWebContext)15 WebContext (org.pac4j.core.context.WebContext)15 CasConfiguration (org.pac4j.cas.config.CasConfiguration)14 HttpAction (org.pac4j.core.exception.http.HttpAction)12 SimpleTestTokenAuthenticator (org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator)11 AnonymousProfile (org.pac4j.core.profile.AnonymousProfile)9 SimpleTestUsernamePasswordAuthenticator (org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator)7 CasProfile (org.pac4j.cas.profile.CasProfile)6 HashMap (java.util.HashMap)5 Authorizer (org.pac4j.core.authorization.authorizer.Authorizer)5 RequireAnyRoleAuthorizer (org.pac4j.core.authorization.authorizer.RequireAnyRoleAuthorizer)5 OkAction (org.pac4j.core.exception.http.OkAction)5 URL (java.net.URL)4