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

Ely 2534 OIDC logout support #2245

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
[ELY-2534] Fix back-channel logout by moving the isSessionMarkedForIn…
…validation check to before the authenticator#authenticate call and update the check to not remove the session from the map to ensure that the user gets logged out from any other apps too
  • Loading branch information
fjuma committed Dec 3, 2024
commit 77d49117816c6645645ada110313b22e594b5342
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.apache.http.client.utils.URIBuilder;
import org.jose4j.jwt.JwtClaims;
import org.wildfly.security.http.HttpConstants;
import org.wildfly.security.http.HttpScope;
import org.wildfly.security.http.Scope;
import org.wildfly.security.http.oidc.OidcHttpFacade.Request;

/**
Expand Down Expand Up @@ -66,13 +68,6 @@ boolean tryLogout(OidcHttpFacade facade) {
return false;
}

if (isSessionMarkedForInvalidation(facade)) {
// session marked for invalidation, invalidate it
log.debug("Invalidating pending logout session");
facade.getTokenStore().logout(false);
return true;
}

if (isRpInitiatedLogoutPath(facade)) {
redirectEndSessionEndpoint(facade);
return true;
Expand All @@ -92,15 +87,19 @@ boolean tryLogout(OidcHttpFacade facade) {
return false;
}

private boolean isSessionMarkedForInvalidation(OidcHttpFacade facade) {
RefreshableOidcSecurityContext securityContext = getSecurityContext(facade);

boolean isSessionMarkedForInvalidation(OidcHttpFacade facade) {
HttpScope session = facade.getScope(Scope.SESSION);
if (session == null || ! session.exists()) return false;
RefreshableOidcSecurityContext securityContext = (RefreshableOidcSecurityContext) session.getAttachment(OidcSecurityContext.class.getName());
if (securityContext == null) {
return false;
}
IDToken idToken = securityContext.getIDToken();

if (idToken == null) {
return false;
}
return sessionsMarkedForInvalidation.remove(idToken.getSid()) != null;
return sessionsMarkedForInvalidation.containsKey(idToken.getSid());
}

private void redirectEndSessionEndpoint(OidcHttpFacade facade) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public void evaluateRequest(HttpServerRequest request) throws HttpAuthentication
}

RequestAuthenticator authenticator = createRequestAuthenticator(httpFacade, oidcClientConfiguration);
if (logoutHandler.isSessionMarkedForInvalidation(httpFacade)) {
// session marked for invalidation, invalidate it
log.debug("Invalidating pending logout session");
httpFacade.getTokenStore().logout(false);
}
httpFacade.getTokenStore().checkCurrentToken();
if ((oidcClientConfiguration.getAuthServerBaseUrl() != null && keycloakPreActions(httpFacade, oidcClientConfiguration))
|| preflightCors(httpFacade, oidcClientConfiguration)) {
Expand Down