use of org.pac4j.core.context.session.SessionStore in project pac4j by pac4j.
the class BaseClientTests method testDirectClient.
@Test
public void testDirectClient() {
final var client = new MockIndirectClient(TYPE, new FoundAction(LOGIN_URL), Optional.empty(), new CommonProfile());
client.setCallbackUrl(CALLBACK_URL);
final var context = MockWebContext.create();
final SessionStore sessionStore = new MockSessionStore();
final var action = (FoundAction) client.getRedirectionAction(context, sessionStore).get();
final var redirectionUrl = action.getLocation();
assertEquals(LOGIN_URL, redirectionUrl);
final var credentials = client.getCredentials(context, sessionStore);
assertFalse(credentials.isPresent());
}
use of org.pac4j.core.context.session.SessionStore in project pac4j by pac4j.
the class BaseClientTests method testAlreadyTried.
@Test
public void testAlreadyTried() {
final var client = new MockIndirectClient(TYPE, new FoundAction(LOGIN_URL), Optional.empty(), new CommonProfile());
client.setCallbackUrl(CALLBACK_URL);
final var context = MockWebContext.create();
final SessionStore sessionStore = new MockSessionStore();
sessionStore.set(context, client.getName() + IndirectClient.ATTEMPTED_AUTHENTICATION_SUFFIX, "true");
final var e = (HttpAction) TestsHelper.expectException(() -> client.getRedirectionAction(context, sessionStore));
assertEquals(401, e.getCode());
}
use of org.pac4j.core.context.session.SessionStore in project pac4j by pac4j.
the class PostSAML2ClientTests method testRelayState.
@Test
public void testRelayState() {
final var client = getClient();
final WebContext context = MockWebContext.create();
final SessionStore sessionStore = new MockSessionStore();
sessionStore.set(context, SAML2StateGenerator.SAML_RELAY_STATE_ATTRIBUTE, "relayState");
final var action = (OkAction) client.getRedirectionAction(context, sessionStore).get();
assertTrue(action.getContent().contains("<input type=\"hidden\" name=\"RelayState\" value=\"relayState\"/>"));
}
use of org.pac4j.core.context.session.SessionStore in project pac4j by pac4j.
the class OidcRedirectTests method testAjaxRequestAfterStandardRequestShouldNotOverrideState.
@Test
public void testAjaxRequestAfterStandardRequestShouldNotOverrideState() throws MalformedURLException, URISyntaxException {
var client = getClient();
client.setCallbackUrl(CALLBACK_URL);
client.setAjaxRequestResolver(new AjaxRequestResolver() {
boolean first = true;
@Override
public boolean isAjax(final WebContext context, final SessionStore sessionStore) {
/*
* Considers that the first request is not ajax, all the subsequent ones are
*/
if (first) {
first = false;
return false;
} else {
return true;
}
}
@Override
public HttpAction buildAjaxResponse(final WebContext context, final SessionStore sessionStore, final RedirectionActionBuilder redirectionActionBuilder) {
return new StatusAction(401);
}
});
var context = MockWebContext.create();
final SessionStore sessionStore = new MockSessionStore();
final var firstRequestAction = (FoundAction) client.getRedirectionAction(context, sessionStore).orElse(null);
var state = TestsHelper.splitQuery(new URL(firstRequestAction.getLocation())).get("state");
try {
// noinspection ThrowableNotThrown
client.getRedirectionAction(context, sessionStore);
fail("Ajax request should throw exception");
} catch (Exception e) {
var stateAfterAjax = (State) sessionStore.get(context, client.getStateSessionAttributeName()).orElse(null);
assertEquals("subsequent ajax request should not override the state in the session store", state, stateAfterAjax.toString());
}
}
use of org.pac4j.core.context.session.SessionStore in project pac4j by pac4j.
the class DefaultCasLogoutHandler method destroySessionBack.
@Override
public void destroySessionBack(final C context, final String ticket) {
final Object trackableSession = store.get(ticket);
logger.debug("ticket: {} -> trackableSession: {}", ticket, trackableSession);
if (trackableSession == null) {
logger.error("No trackable session found for back channel logout. Either the session store does not support to track session " + "or it has expired from the store and the store settings must be updated (expired data)");
} else {
store.remove(ticket);
// renew context with the original session store
final SessionStore sessionStore = context.getSessionStore();
if (sessionStore == null) {
logger.error("No session store available for this web context");
} else {
final SessionStore<C> newSessionStore = sessionStore.buildFromTrackableSession(context, trackableSession);
if (newSessionStore != null) {
logger.debug("newSesionStore: {}", newSessionStore);
final String sessionId = newSessionStore.getOrCreateSessionId(context);
logger.debug("remove sessionId: {}", sessionId);
store.remove(sessionId);
destroy(context, newSessionStore, "back");
} else {
logger.error("The session store should be able to build a new session store from the tracked session");
}
}
}
}
Aggregations