Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch KC proposal for issue 17539 : recreate the missing AUT_SESSION_… #17662

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public UserSessionModel getUserSessionWithClient(RealmModel realm, String id, St
public UserSessionModel getUserSessionIfExistsRemotely(AuthenticationSessionManager asm, RealmModel realm) {
List<String> sessionCookies = asm.getAuthSessionCookies(realm);

boolean noAuthCookie = false;
if (sessionCookies.isEmpty()) {
noAuthCookie=true;
// ideally, we should not rely on auth session id to retrieve user sessions
// in case the auth session was removed, we fall back to the identity cookie
// we are here doing the user session lookup twice, however the second lookup is going to make sure the
Expand All @@ -79,6 +81,7 @@ public UserSessionModel getUserSessionIfExistsRemotely(AuthenticationSessionMana
}
}

boolean finalNoAuthCookie = noAuthCookie;
return sessionCookies.stream().map(oldEncodedId -> {
AuthSessionId authSessionId = asm.decodeAuthSessionId(oldEncodedId);
String sessionId = authSessionId.getDecodedId();
Expand All @@ -89,7 +92,11 @@ public UserSessionModel getUserSessionIfExistsRemotely(AuthenticationSessionMana
UserSessionModel userSession = lockUserSessionsForModification(kcSession, () -> kcSession.sessions().getUserSession(realm, sessionId));

if (userSession != null) {
asm.reencodeAuthSessionCookie(oldEncodedId, authSessionId, realm);
if (finalNoAuthCookie)
// In then fallback, we recreate the auth Session Id cookie
asm.setAuthSessionCookie(authSessionId.getDecodedId(), realm);
else
asm.reencodeAuthSessionCookie(oldEncodedId, authSessionId, realm);
return userSession;
}

Expand Down