Skip to content

Commit

Permalink
Merge pull request #271 from sadilchamishka/resolve-user-id
Browse files Browse the repository at this point in the history
Fix NPE
  • Loading branch information
sadilchamishka authored Oct 25, 2023
2 parents 58cd12a + cdfeac6 commit 31004a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ private String getUserId(User user, String orgId) throws OrganizationManagementA
try {
AbstractUserStoreManager userStoreManager = (AbstractUserStoreManager) getUserStoreManager(user);
String userId = userStoreManager.getUser(null, user.getUserName()).getUserID();
// Retrieve the user ID of the shared user if an user association exists.
Optional<String> optionalUserId =
OrganizationSharedUserUtil.getUserIdOfAssociatedUserByOrgId(userId, orgId);
return optionalUserId.orElse(userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.wso2.carbon.identity.organization.management.organization.user.sharing.util;

import org.wso2.carbon.identity.organization.management.organization.user.sharing.internal.OrganizationUserSharingDataHolder;
import org.wso2.carbon.identity.organization.management.organization.user.sharing.models.UserAssociation;
import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException;
import org.wso2.carbon.user.core.UserStoreException;
import org.wso2.carbon.user.core.common.AbstractUserStoreManager;
Expand Down Expand Up @@ -49,7 +50,12 @@ public static String getUserManagedOrganizationClaim(AbstractUserStoreManager us
public static Optional<String> getUserIdOfAssociatedUserByOrgId(String associatedUserId, String orgId)
throws OrganizationManagementException {

return Optional.ofNullable(OrganizationUserSharingDataHolder.getInstance().getOrganizationUserSharingService()
.getUserAssociationOfAssociatedUserByOrgId(associatedUserId, orgId).getUserId());
UserAssociation userAssociation = OrganizationUserSharingDataHolder.getInstance()
.getOrganizationUserSharingService()
.getUserAssociationOfAssociatedUserByOrgId(associatedUserId, orgId);
if (userAssociation == null) {
return Optional.empty();
}
return Optional.of(userAssociation.getUserId());
}
}

0 comments on commit 31004a3

Please sign in to comment.