Skip to content

Commit b2d4c6e

Browse files
fjumarsearls
authored andcommitted
[ELY-2534] Fix back-channel logout by moving the isSessionMarkedForInvalidation 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
1 parent 07e6d41 commit b2d4c6e

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

http/oidc/src/main/java/org/wildfly/security/http/oidc/LogoutHandler.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import org.apache.http.client.utils.URIBuilder;
3030
import org.jose4j.jwt.JwtClaims;
3131
import org.wildfly.security.http.HttpConstants;
32+
import org.wildfly.security.http.HttpScope;
33+
import org.wildfly.security.http.Scope;
3234
import org.wildfly.security.http.oidc.OidcHttpFacade.Request;
3335

3436
/**
@@ -66,13 +68,6 @@ boolean tryLogout(OidcHttpFacade facade) {
6668
return false;
6769
}
6870

69-
if (isSessionMarkedForInvalidation(facade)) {
70-
// session marked for invalidation, invalidate it
71-
log.debug("Invalidating pending logout session");
72-
facade.getTokenStore().logout(false);
73-
return true;
74-
}
75-
7671
if (isRpInitiatedLogoutPath(facade)) {
7772
redirectEndSessionEndpoint(facade);
7873
return true;
@@ -92,15 +87,19 @@ boolean tryLogout(OidcHttpFacade facade) {
9287
return false;
9388
}
9489

95-
private boolean isSessionMarkedForInvalidation(OidcHttpFacade facade) {
96-
RefreshableOidcSecurityContext securityContext = getSecurityContext(facade);
97-
90+
boolean isSessionMarkedForInvalidation(OidcHttpFacade facade) {
91+
HttpScope session = facade.getScope(Scope.SESSION);
92+
if (session == null || ! session.exists()) return false;
93+
RefreshableOidcSecurityContext securityContext = (RefreshableOidcSecurityContext) session.getAttachment(OidcSecurityContext.class.getName());
94+
if (securityContext == null) {
95+
return false;
96+
}
9897
IDToken idToken = securityContext.getIDToken();
9998

10099
if (idToken == null) {
101100
return false;
102101
}
103-
return sessionsMarkedForInvalidation.remove(idToken.getSid()) != null;
102+
return sessionsMarkedForInvalidation.containsKey(idToken.getSid());
104103
}
105104

106105
private void redirectEndSessionEndpoint(OidcHttpFacade facade) {

http/oidc/src/main/java/org/wildfly/security/http/oidc/OidcAuthenticationMechanism.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public void evaluateRequest(HttpServerRequest request) throws HttpAuthentication
7676
}
7777

7878
RequestAuthenticator authenticator = createRequestAuthenticator(httpFacade, oidcClientConfiguration);
79+
if (logoutHandler.isSessionMarkedForInvalidation(httpFacade)) {
80+
// session marked for invalidation, invalidate it
81+
log.debug("Invalidating pending logout session");
82+
httpFacade.getTokenStore().logout(false);
83+
}
7984
httpFacade.getTokenStore().checkCurrentToken();
8085
if ((oidcClientConfiguration.getAuthServerBaseUrl() != null && keycloakPreActions(httpFacade, oidcClientConfiguration))
8186
|| preflightCors(httpFacade, oidcClientConfiguration)) {

0 commit comments

Comments
 (0)