Skip to content

Commit

Permalink
resolve NPE and malfunctioning shared role creation
Browse files Browse the repository at this point in the history
  • Loading branch information
AnuradhaSK committed Oct 20, 2023
1 parent c5581d6 commit d823ff1
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.wso2.carbon.identity.organization.management.service.OrganizationManager;
import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException;
import org.wso2.carbon.identity.organization.management.service.util.OrganizationManagementUtil;
import org.wso2.carbon.identity.role.v2.mgt.core.AssociatedApplication;
import org.wso2.carbon.identity.role.v2.mgt.core.IdentityRoleManagementException;
import org.wso2.carbon.identity.role.v2.mgt.core.RoleBasicInfo;
import org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants;
Expand All @@ -45,6 +44,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -201,7 +201,26 @@ public boolean doPostUpdateApplication(ServiceProvider serviceProvider, String t
Object addedOrgRoles = IdentityUtil.threadLocalProperties.get().get(ADDED_ORGANIZATION_AUDIENCE_ROLES);
if (addedOrgRoles != null) {
List<RoleV2> addedOrgRolesList = (List<RoleV2>) addedOrgRoles;
handleAddedOrganizationAudienceRolesOnAppUpdate(addedOrgRolesList, serviceProvider, tenantDomain);
List<RoleV2> namesResolvedAddedRolesList = addedOrgRolesList.stream()
.map(role -> {
try {
String roleName =
getRoleManagementServiceV2().getRoleNameByRoleId(role.getId(), tenantDomain);
if (roleName != null) {
return new RoleV2(role.getId(), roleName);
} else {
return null;
}
} catch (Exception e) {
LOG.error("Failed to resolve role name of role id: " + role.getId());
return null;
}
})
.filter(Objects::nonNull) // Filter out null values (roles that couldn't be resolved)
.collect(Collectors.toList());

handleAddedOrganizationAudienceRolesOnAppUpdate(namesResolvedAddedRolesList, serviceProvider,
tenantDomain);
}

Object removedOrgRoles = IdentityUtil.threadLocalProperties.get().get(REMOVED_ORGANIZATION_AUDIENCE_ROLES);
Expand Down Expand Up @@ -455,7 +474,6 @@ private void handleOrganizationAudiencedSharedRoleDeletion(List<RoleV2> rolesLis
if (associatedApplicationsIds.size() == 1 && mainApplicationId.equals(associatedApplicationsIds.get(0))) {
// Delete the role in org.
getRoleManagementServiceV2().deleteRole(sharedRoleId, sharedAppTenantDomain);
break;
} else if (associatedApplicationsIds.size() > 1) {
boolean isRoleUsedByAnotherSharedApp = false;
for (String associatedApplicationId : associatedApplicationsIds) {
Expand Down

0 comments on commit d823ff1

Please sign in to comment.