use of org.pac4j.core.context.session.SessionStore in project pac4j by pac4j.
the class DefaultCasLogoutHandler method destroySessionFront.
@Override
public void destroySessionFront(final C context, final String ticket) {
store.remove(ticket);
final SessionStore sessionStore = context.getSessionStore();
if (sessionStore == null) {
logger.error("No session store available for this web context");
} else {
final String currentSessionId = sessionStore.getOrCreateSessionId(context);
logger.debug("currentSessionId: {}", currentSessionId);
final String sessionToTicket = (String) store.get(currentSessionId);
logger.debug("-> ticket: {}", ticket);
store.remove(currentSessionId);
if (CommonHelper.areEquals(ticket, sessionToTicket)) {
destroy(context, sessionStore, "front");
} else {
logger.error("The user profiles (and session) can not be destroyed for CAS front channel logout because the provided " + "ticket is not the same as the one linked to the current session");
}
}
}
use of org.pac4j.core.context.session.SessionStore in project ddf by codice.
the class OidcTokenValidatorTest method getWebContext.
private WebContext getWebContext() {
WebContext context = mock(WebContext.class);
SessionStore sessionStore = mock(SessionStore.class);
when(sessionStore.get(context, NONCE_SESSION_ATTRIBUTE)).thenReturn(Optional.of("myNonce"));
when(context.getSessionStore()).thenReturn(sessionStore);
return context;
}
use of org.pac4j.core.context.session.SessionStore in project cas by apereo.
the class OidcAuthenticationAuthorizeSecurityLogic method loadProfiles.
@Override
protected List<UserProfile> loadProfiles(final ProfileManager manager, final WebContext context, final SessionStore sessionStore, final List<Client> clients) {
val prompts = OidcRequestSupport.getOidcPromptFromAuthorizationRequest(context);
LOGGER.debug("Located OpenID Connect prompts from request as [{}]", prompts);
val tooOld = OidcRequestSupport.getOidcMaxAgeFromAuthorizationRequest(context).map(maxAge -> manager.getProfile(BasicUserProfile.class).stream().anyMatch(profile -> OidcRequestSupport.isCasAuthenticationOldForMaxAgeAuthorizationRequest(context, profile))).orElse(Boolean.FALSE);
return tooOld || prompts.contains(OidcConstants.PROMPT_LOGIN) ? new ArrayList<>(0) : super.loadProfiles(manager, context, sessionStore, clients);
}
use of org.pac4j.core.context.session.SessionStore in project pac4j by pac4j.
the class DefaultMatchingCheckerTests method testCsrfTokenDefaultButSessionAlreadyExists.
@Test
public void testCsrfTokenDefaultButSessionAlreadyExists() {
final var context = MockWebContext.create();
final SessionStore sessionStore = new MockSessionStore();
sessionStore.getSessionId(context, true);
assertTrue(checker.matches(context, sessionStore, "", new HashMap<>(), new ArrayList<>()));
assertTrue(context.getRequestAttribute(Pac4jConstants.CSRF_TOKEN).isPresent());
assertNotNull(WebContextHelper.getCookie(context.getResponseCookies(), Pac4jConstants.CSRF_TOKEN));
}
use of org.pac4j.core.context.session.SessionStore in project pac4j by pac4j.
the class RunClient method run.
public void run() {
final var client = getClient();
final var context = MockWebContext.create();
final SessionStore sessionStore = new MockSessionStore();
final var url = ((FoundAction) client.getRedirectionAction(context, sessionStore).get()).getLocation();
logger.warn("Redirect to: \n{}", url);
if (CommonHelper.isNotBlank(getLogin()) && CommonHelper.isNotBlank(getPassword())) {
logger.warn("Use credentials: {} / {}", getLogin(), getPassword());
} else {
logger.warn("Use your own personal credentials");
}
if (canCancel()) {
logger.warn("You can CANCEL the authentication.");
}
logger.warn("Returned url (copy/paste the fragment starting before the question mark of the query string):");
final var scanner = new Scanner(System.in, StandardCharsets.UTF_8.name());
final var returnedUrl = scanner.nextLine().trim();
populateContextWithUrl(context, returnedUrl);
final var credentials = client.getCredentials(context, sessionStore);
if (credentials.isPresent()) {
final var profile = client.getUserProfile(credentials.get(), context, sessionStore);
logger.debug("userProfile: {}", profile);
if (profile.isPresent() || !canCancel()) {
verifyProfile((CommonProfile) profile.get());
logger.warn("## Java serialization");
final var javaSerializer = new JavaSerializer();
var bytes = javaSerializer.serializeToBytes(profile.get());
final var profile2 = (CommonProfile) javaSerializer.deserializeFromBytes(bytes);
verifyProfile(profile2);
}
}
logger.warn("################");
logger.warn("Test successful!");
}
Aggregations