From 4450c6f6e5118abdd84624fe72dc10248b289c95 Mon Sep 17 00:00:00 2001 From: sadilchamishka Date: Sun, 19 Nov 2023 13:25:22 +0530 Subject: [PATCH 1/3] Fix active user sessions not retrieved for b2b users accessing MyAccount --- .../user/session/v1/core/SessionManagementService.java | 10 +++++++++- pom.xml | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.user.session/org.wso2.carbon.identity.api.user.session.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/session/v1/core/SessionManagementService.java b/components/org.wso2.carbon.identity.api.user.session/org.wso2.carbon.identity.api.user.session.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/session/v1/core/SessionManagementService.java index 6815fa344..f5e686bb3 100644 --- a/components/org.wso2.carbon.identity.api.user.session/org.wso2.carbon.identity.api.user.session.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/session/v1/core/SessionManagementService.java +++ b/components/org.wso2.carbon.identity.api.user.session/org.wso2.carbon.identity.api.user.session.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/session/v1/core/SessionManagementService.java @@ -21,6 +21,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.api.user.common.error.APIError; import org.wso2.carbon.identity.api.user.common.error.ErrorResponse; import org.wso2.carbon.identity.api.user.common.function.UserToUniqueId; @@ -53,6 +54,7 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; + import javax.ws.rs.core.Response; import static org.wso2.carbon.identity.api.user.common.Constants.ERROR_CODE_DELIMITER; @@ -92,7 +94,7 @@ public class SessionManagementService { public SessionsDTO getSessionsBySessionId(User user, Integer limit, Integer offset, String filter, String sort) { String userId; - if (isFederatedUser()) { + if (isFederatedUser() && !isOrganizationSsoUser()) { userId = getFederatedUserIdFromUser(user); } else { userId = getUserIdFromUser(user); @@ -400,6 +402,12 @@ private boolean isFederatedUser() { (boolean) IdentityUtil.threadLocalProperties.get().get(IS_FEDERATED_USER); } + private boolean isOrganizationSsoUser() { + + return isFederatedUser() && StringUtils.isNotEmpty(PrivilegedCarbonContext.getThreadLocalCarbonContext() + .getUserResidentOrganizationId()); + } + /** * Get the filter nodes as a list. * diff --git a/pom.xml b/pom.xml index 8119c1c96..89763ffe3 100644 --- a/pom.xml +++ b/pom.xml @@ -420,7 +420,7 @@ 2.3.1.wso2v1 1.4 1.2.4 - 4.9.0 + 4.9.17 1.8.73 5.25.380 5.3.7 From ffc340960d268f3d1eda3c6875e40386c6705b9b Mon Sep 17 00:00:00 2001 From: sadilchamishka Date: Mon, 20 Nov 2023 12:08:50 +0530 Subject: [PATCH 2/3] Address review comments --- .../session/v1/core/SessionManagementService.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.user.session/org.wso2.carbon.identity.api.user.session.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/session/v1/core/SessionManagementService.java b/components/org.wso2.carbon.identity.api.user.session/org.wso2.carbon.identity.api.user.session.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/session/v1/core/SessionManagementService.java index f5e686bb3..25ddeae05 100644 --- a/components/org.wso2.carbon.identity.api.user.session/org.wso2.carbon.identity.api.user.session.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/session/v1/core/SessionManagementService.java +++ b/components/org.wso2.carbon.identity.api.user.session/org.wso2.carbon.identity.api.user.session.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/session/v1/core/SessionManagementService.java @@ -94,7 +94,10 @@ public class SessionManagementService { public SessionsDTO getSessionsBySessionId(User user, Integer limit, Integer offset, String filter, String sort) { String userId; - if (isFederatedUser() && !isOrganizationSsoUser()) { + /* For organization SSO users, the user information is properly set. Hence, the user ID resolving logic for + local user can be used. */ + if (isFederatedUser() && !StringUtils.isNotEmpty(PrivilegedCarbonContext.getThreadLocalCarbonContext() + .getUserResidentOrganizationId())) { userId = getFederatedUserIdFromUser(user); } else { userId = getUserIdFromUser(user); @@ -402,12 +405,6 @@ private boolean isFederatedUser() { (boolean) IdentityUtil.threadLocalProperties.get().get(IS_FEDERATED_USER); } - private boolean isOrganizationSsoUser() { - - return isFederatedUser() && StringUtils.isNotEmpty(PrivilegedCarbonContext.getThreadLocalCarbonContext() - .getUserResidentOrganizationId()); - } - /** * Get the filter nodes as a list. * From 353acab904d5febd66ea4f586ecd81f12110af10 Mon Sep 17 00:00:00 2001 From: sadilchamishka Date: Mon, 20 Nov 2023 13:46:41 +0530 Subject: [PATCH 3/3] Address review comments --- .../session/v1/core/SessionManagementService.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.user.session/org.wso2.carbon.identity.api.user.session.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/session/v1/core/SessionManagementService.java b/components/org.wso2.carbon.identity.api.user.session/org.wso2.carbon.identity.api.user.session.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/session/v1/core/SessionManagementService.java index 25ddeae05..9f8287ca2 100644 --- a/components/org.wso2.carbon.identity.api.user.session/org.wso2.carbon.identity.api.user.session.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/session/v1/core/SessionManagementService.java +++ b/components/org.wso2.carbon.identity.api.user.session/org.wso2.carbon.identity.api.user.session.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/session/v1/core/SessionManagementService.java @@ -94,11 +94,15 @@ public class SessionManagementService { public SessionsDTO getSessionsBySessionId(User user, Integer limit, Integer offset, String filter, String sort) { String userId; - /* For organization SSO users, the user information is properly set. Hence, the user ID resolving logic for - local user can be used. */ - if (isFederatedUser() && !StringUtils.isNotEmpty(PrivilegedCarbonContext.getThreadLocalCarbonContext() - .getUserResidentOrganizationId())) { - userId = getFederatedUserIdFromUser(user); + if (isFederatedUser()) { + boolean isOrganizationSSOUser = StringUtils.isNotEmpty(PrivilegedCarbonContext.getThreadLocalCarbonContext() + .getUserResidentOrganizationId()); + // For organization SSO users, user ID resolve same as for a local user. + if (isOrganizationSSOUser) { + userId = getUserIdFromUser(user); + } else { + userId = getFederatedUserIdFromUser(user); + } } else { userId = getUserIdFromUser(user); }