Search in sources :

Example 61 with MockSessionStore

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

the class IndirectBasicAuthClientTests method testGetCredentialsGoodCredentials.

@Test
public void testGetCredentialsGoodCredentials() {
    final var basicAuthClient = getBasicAuthClient();
    final var header = USERNAME + ":" + USERNAME;
    final var credentials = (UsernamePasswordCredentials) basicAuthClient.getCredentials(getContextWithAuthorizationHeader("Basic " + Base64.getEncoder().encodeToString(header.getBytes(StandardCharsets.UTF_8))), new MockSessionStore()).get();
    assertEquals(USERNAME, credentials.getUsername());
    assertEquals(USERNAME, credentials.getPassword());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Test(org.junit.Test)

Example 62 with MockSessionStore

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

the class IpExtractorTests method testRetrieveIpOk.

@Test
public void testRetrieveIpOk() {
    final var context = MockWebContext.create().setRemoteAddress(GOOD_IP);
    final var credentials = (TokenCredentials) extractor.extract(context, new MockSessionStore()).get();
    assertEquals(GOOD_IP, credentials.getToken());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) Test(org.junit.Test)

Example 63 with MockSessionStore

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

the class FormClientTests method testRedirectionUrl.

@Test
public void testRedirectionUrl() {
    final var formClient = getFormClient();
    var context = MockWebContext.create();
    final var action = (FoundAction) formClient.getRedirectionAction(context, new MockSessionStore()).get();
    assertEquals(LOGIN_URL, action.getLocation());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) FoundAction(org.pac4j.core.exception.http.FoundAction) Test(org.junit.Test)

Example 64 with MockSessionStore

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

the class CookieClientTests method testAuthentication.

@Test
public void testAuthentication() {
    final var client = new CookieClient(USERNAME, new SimpleTestTokenAuthenticator());
    final var context = MockWebContext.create();
    final var c = new Cookie(USERNAME, Base64.getEncoder().encodeToString(getClass().getName().getBytes(StandardCharsets.UTF_8)));
    context.getRequestCookies().add(c);
    final var credentials = (TokenCredentials) client.getCredentials(context, new MockSessionStore()).get();
    final var profile = (CommonProfile) client.getUserProfile(credentials, context, new MockSessionStore()).get();
    assertEquals(c.getValue(), profile.getId());
}
Also used : Cookie(org.pac4j.core.context.Cookie) 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 65 with MockSessionStore

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

the class DirectBearerAuthClientTests method testAuthentication.

@Test
public void testAuthentication() {
    final var client = new DirectBearerAuthClient(new SimpleTestTokenAuthenticator());
    final var context = MockWebContext.create();
    context.addRequestHeader(HttpConstants.AUTHORIZATION_HEADER, HttpConstants.BEARER_HEADER_PREFIX + TOKEN);
    final var credentials = (TokenCredentials) client.getCredentials(context, new MockSessionStore()).get();
    final var profile = (CommonProfile) client.getUserProfile(credentials, context, new MockSessionStore()).get();
    assertEquals(TOKEN, 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)

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