Search in sources :

Example 1 with SeeOtherAction

use of org.pac4j.core.exception.http.SeeOtherAction in project pac4j by pac4j.

the class DefaultCallbackLogicTests method internalTestCallbackWithOriginallyRequestedUrl.

private void internalTestCallbackWithOriginallyRequestedUrl(final int code) {
    final var originalSessionId = sessionStore.getSessionId(context, false);
    sessionStore.set(context, Pac4jConstants.REQUESTED_URL, new FoundAction(PAC4J_URL));
    context.addRequestParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, NAME);
    final var profile = new CommonProfile();
    final IndirectClient indirectClient = new MockIndirectClient(NAME, null, Optional.of(new MockCredentials()), profile);
    config.setClients(new Clients(CALLBACK_URL, indirectClient));
    call();
    final var newSessionId = sessionStore.getSessionId(context, false);
    final var profiles = (LinkedHashMap<String, CommonProfile>) sessionStore.get(context, Pac4jConstants.USER_PROFILES).get();
    assertTrue(profiles.containsValue(profile));
    assertEquals(1, profiles.size());
    assertNotEquals(newSessionId, originalSessionId);
    assertEquals(code, action.getCode());
    if (action instanceof SeeOtherAction) {
        assertEquals(PAC4J_URL, ((SeeOtherAction) action).getLocation());
    } else {
        assertEquals(PAC4J_URL, ((FoundAction) action).getLocation());
    }
}
Also used : FoundAction(org.pac4j.core.exception.http.FoundAction) CommonProfile(org.pac4j.core.profile.CommonProfile) MockIndirectClient(org.pac4j.core.client.MockIndirectClient) MockCredentials(org.pac4j.core.credentials.MockCredentials) IndirectClient(org.pac4j.core.client.IndirectClient) MockIndirectClient(org.pac4j.core.client.MockIndirectClient) SeeOtherAction(org.pac4j.core.exception.http.SeeOtherAction) Clients(org.pac4j.core.client.Clients) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)1 Clients (org.pac4j.core.client.Clients)1 IndirectClient (org.pac4j.core.client.IndirectClient)1 MockIndirectClient (org.pac4j.core.client.MockIndirectClient)1 MockCredentials (org.pac4j.core.credentials.MockCredentials)1 FoundAction (org.pac4j.core.exception.http.FoundAction)1 SeeOtherAction (org.pac4j.core.exception.http.SeeOtherAction)1 CommonProfile (org.pac4j.core.profile.CommonProfile)1