Skip to content

Commit

Permalink
Improve federated idp initiated logout for multiple IDP sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
sadilchamishka committed Apr 24, 2024
1 parent 834a8d7 commit 726ea86
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,25 @@ protected LogoutResponse.LogoutResponseBuilder logoutUsingSid(String sid)
if (log.isDebugEnabled()) {
log.debug(String.format("Trying federated IdP initiated logout using sid: %s.", sid));
}
FederatedUserSession federatedUserSession = getFederatedUserSessionFromSid(sid);
List<FederatedUserSession> federatedUserSessionList = getFederatedUserSessionsFromSid(sid);
String sessionId = null;
if (federatedUserSession != null) {
sessionId = federatedUserSession.getSessionId();
}
if (StringUtils.isBlank(sessionId)) {
return new LogoutResponse.LogoutResponseBuilder(HttpServletResponse.SC_OK, StringUtils.EMPTY);
}
for (FederatedUserSession federatedUserSession: federatedUserSessionList) {
if (federatedUserSession != null) {
sessionId = federatedUserSession.getSessionId();
}
if (StringUtils.isBlank(sessionId)) {
return new LogoutResponse.LogoutResponseBuilder(HttpServletResponse.SC_OK, StringUtils.EMPTY);
}

ServerSessionManagementService serverSessionManagementService =
OpenIDConnectAuthenticatorDataHolder.getInstance().getServerSessionManagementService();
serverSessionManagementService.removeSession(sessionId);
if (log.isDebugEnabled()) {
log.debug("Session terminated for session Id: " + sessionId);
ServerSessionManagementService serverSessionManagementService =
OpenIDConnectAuthenticatorDataHolder.getInstance().getServerSessionManagementService();
serverSessionManagementService.removeSession(sessionId);
if (log.isDebugEnabled()) {
log.debug("Session terminated for session Id: " + sessionId);
}
}


return new LogoutResponse.LogoutResponseBuilder(HttpServletResponse.SC_OK,
OIDCAuthenticatorConstants.BackchannelLogout.LOGOUT_SUCCESS);
}
Expand Down Expand Up @@ -220,6 +223,24 @@ protected FederatedUserSession getFederatedUserSessionFromSid(String sid) throws
}
}

protected List<FederatedUserSession> getFederatedUserSessionsFromSid(String sid) throws LogoutServerException {

try {
UserSessionDAO userSessionDAO = new UserSessionDAOImpl();
List<FederatedUserSession> federatedUserSession = userSessionDAO.getFederatedAuthSessionsDetails(sid);
if (federatedUserSession == null) {
if (log.isDebugEnabled()) {
log.debug(String.format("No session information found for the sid: %s. ", sid) + "Probably the " +
"session was cleared by another mechanism.");
}
return null;
}
return federatedUserSession;
} catch (SessionManagementServerException e) {
throw handleLogoutServerException(ErrorMessages.RETRIEVING_SESSION_ID_MAPPING_FAILED, e, sid);
}
}

/**
* Terminate all the sessions of the user related sub claim.
*
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
<identity.application.auth.oidc.package.export.version>${project.version}
</identity.application.auth.oidc.package.export.version>

<carbon.identity.framework.version>7.0.93</carbon.identity.framework.version>
<carbon.identity.framework.version>7.1.33</carbon.identity.framework.version>
<oltu.version>1.0.0.wso2v3</oltu.version>
<json-smart.version>2.4.7</json-smart.version>
<json.wso2.version>3.0.0.wso2v4</json.wso2.version>
Expand Down

0 comments on commit 726ea86

Please sign in to comment.