diff --git a/components/org.wso2.carbon.identity.scim2.common/pom.xml b/components/org.wso2.carbon.identity.scim2.common/pom.xml
index 84e19c1fd..4be83fd9d 100644
--- a/components/org.wso2.carbon.identity.scim2.common/pom.xml
+++ b/components/org.wso2.carbon.identity.scim2.common/pom.xml
@@ -131,6 +131,10 @@
org.wso2.carbon.identity.framework
org.wso2.carbon.identity.application.authentication.framework
+
+ org.wso2.carbon.identity.framework
+ org.wso2.carbon.idp.mgt
+
org.wso2.carbon.identity.governance
org.wso2.carbon.identity.password.policy
@@ -244,6 +248,7 @@
version="${org.wso2.carbon.identity.organization.management.core.version.range}",
org.wso2.carbon.identity.handler.event.account.lock.*;
version="${carbon.identity.account.lock.handler.imp.pkg.version.range}",
+ org.wso2.carbon.idp.mgt.*;version="${carbon.identity.framework.imp.pkg.version.range}",
!org.wso2.carbon.identity.scim2.common.internal,
diff --git a/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManagerV2.java b/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManagerV2.java
index 0dfa1834f..1f34f36b3 100644
--- a/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManagerV2.java
+++ b/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMRoleManagerV2.java
@@ -25,6 +25,7 @@
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.identity.application.common.model.IdPGroup;
import org.wso2.carbon.identity.core.util.IdentityUtil;
import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException;
import org.wso2.carbon.identity.organization.management.service.util.OrganizationManagementUtil;
@@ -33,13 +34,16 @@
import org.wso2.carbon.identity.role.v2.mgt.core.exception.IdentityRoleManagementException;
import org.wso2.carbon.identity.role.v2.mgt.core.model.AssociatedApplication;
import org.wso2.carbon.identity.role.v2.mgt.core.model.GroupBasicInfo;
+import org.wso2.carbon.identity.role.v2.mgt.core.model.IdpGroup;
import org.wso2.carbon.identity.role.v2.mgt.core.model.Permission;
import org.wso2.carbon.identity.role.v2.mgt.core.model.Role;
import org.wso2.carbon.identity.role.v2.mgt.core.model.RoleBasicInfo;
import org.wso2.carbon.identity.role.v2.mgt.core.model.UserBasicInfo;
import org.wso2.carbon.identity.role.v2.mgt.core.util.UserIDResolver;
+import org.wso2.carbon.identity.scim2.common.internal.SCIMCommonComponentHolder;
import org.wso2.carbon.identity.scim2.common.utils.SCIMCommonConstants;
import org.wso2.carbon.identity.scim2.common.utils.SCIMCommonUtils;
+import org.wso2.carbon.idp.mgt.IdentityProviderManagementException;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.core.UserCoreConstants;
import org.wso2.carbon.user.core.common.AbstractUserStoreManager;
@@ -71,6 +75,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.function.Function;
import java.util.stream.Collectors;
import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
@@ -136,10 +141,26 @@ public RoleV2 createRole(RoleV2 role)
LOG.debug("Creating role: " + role.getDisplayName() + " for organization.");
}
}
+
+ List groupIds = role.getGroups();
+ // Get valid IdP groups from the given group IDs.
+ List idpGroups = SCIMCommonComponentHolder.getIdpManagerService().getValidIdPGroupsByIdPGroupIds(
+ groupIds, tenantDomain);
+ List idpGroupList = idpGroups.stream()
+ .map(this::convertToIdpGroup)
+ .collect(Collectors.toList());
+ List validIdpGroupIds = idpGroupList.stream()
+ .map(IdpGroup::getGroupId)
+ .collect(Collectors.toList());
+ // Exclude the valid Idp groups from the given group IDs for role creation.
+ List localGroupIds = groupIds.stream()
+ .filter(groupId -> !validIdpGroupIds.contains(groupId))
+ .collect(Collectors.toList());
RoleBasicInfo roleBasicInfo =
- roleManagementService.addRole(role.getDisplayName(), role.getUsers(), role.getGroups(),
+ roleManagementService.addRole(role.getDisplayName(), role.getUsers(), localGroupIds,
permissionList, audienceType, role.getAudienceValue(), tenantDomain);
-
+ roleManagementService.updateIdpGroupListOfRole(roleBasicInfo.getId(), idpGroupList, new ArrayList<>(),
+ tenantDomain);
RoleV2 createdRole = new RoleV2();
createdRole.setId(roleBasicInfo.getId());
String locationURI = SCIMCommonUtils.getSCIMRoleV2URL(roleBasicInfo.getId());
@@ -160,6 +181,10 @@ public RoleV2 createRole(RoleV2 role)
}
throw new CharonException(
String.format("Error occurred while adding a new role: %s", role.getDisplayName()), e);
+ } catch (IdentityProviderManagementException e) {
+ throw new CharonException(
+ String.format("Error occurred while retrieving IdP groups for role: %s", role.getDisplayName()),
+ e);
}
}
@@ -202,20 +227,34 @@ public RoleV2 getRole(String roleID, Map requiredAttributes)
}
}
- // Set role's assigned groups.
- List assignedGroups = role.getGroups();
- if (assignedGroups != null) {
- for (GroupBasicInfo groupInfo : assignedGroups) {
- groupInfo.getId();
- String groupLocationURI = SCIMCommonUtils.getSCIMGroupURL(groupInfo.getId());
+ // Set role's assigned userstore groups.
+ List assignedUserstoreGroups = role.getGroups();
+ if (assignedUserstoreGroups != null) {
+ for (GroupBasicInfo groupInfo : assignedUserstoreGroups) {
+ String groupId = groupInfo.getId();
+ String groupLocationURI = SCIMCommonUtils.getSCIMGroupURL(groupId);
Group group = new Group();
group.setDisplayName(groupInfo.getName());
- group.setId(groupInfo.getId());
+ group.setId(groupId);
group.setLocation(groupLocationURI);
scimRole.setGroup(group);
}
}
+ // Set role's assigned idp groups.
+ List assignedIdpGroups = role.getIdpGroups();
+ if (assignedIdpGroups != null) {
+ for (IdpGroup idpGroup : assignedIdpGroups) {
+ String idpGroupId = idpGroup.getGroupId();
+ String idpGroupLocationURI = SCIMCommonUtils.getIdpGroupURL(idpGroup.getIdpId(), idpGroupId);
+ Group group = new Group();
+ group.setDisplayName(idpGroup.getGroupName());
+ group.setId(idpGroupId);
+ group.setLocation(idpGroupLocationURI);
+ scimRole.setGroup(group);
+ }
+ }
+
// Set associated applications.
List associatedApps =
convertAssociatedAppsToMultivaluedComplexType(role.getAssociatedApplications());
@@ -866,17 +905,25 @@ private void updateGroups(String roleId, List groupOperations)
try {
Collections.sort(groupOperations);
+
+ Set givenAddedGroupIds = new HashSet<>();
+ Set givenDeletedGroupIds = new HashSet<>();
+ Set givenReplaceGroupsIds = new HashSet<>();
+
Set addedGroupIds = new HashSet<>();
Set deletedGroupIds = new HashSet<>();
- Set replaceGroupsIds = new HashSet<>();
+ Set replaceGroupIds = new HashSet<>();
- List groupListOfRole = roleManagementService.getGroupListOfRole(roleId, tenantDomain);
+ Set addedIdpGroupIds = new HashSet<>();
+ Set deletedIdpGroupIds = new HashSet<>();
+ Set replaceIdpGroupIds = new HashSet<>();
+ List groupListOfRole = roleManagementService.getGroupListOfRole(roleId, tenantDomain);
for (PatchOperation groupOperation : groupOperations) {
if (groupOperation.getValues() instanceof Map) {
Map groupObject = (Map) groupOperation.getValues();
- prepareAddedRemovedGroupLists(addedGroupIds, deletedGroupIds, replaceGroupsIds,
- groupOperation, groupObject, groupListOfRole);
+ prepareInitialGroupLists(givenAddedGroupIds, givenDeletedGroupIds, givenReplaceGroupsIds,
+ groupOperation, groupObject);
} else if (groupOperation.getValues() instanceof List) {
List
+
+ org.wso2.carbon.identity.framework
+ org.wso2.carbon.idp.mgt
+ ${identity.framework.version}
+ provided
+
org.wso2.carbon.identity.organization.management.core
org.wso2.carbon.identity.organization.management.service
@@ -279,7 +285,7 @@
6.5.3
3.2.0.wso2v1
4.9.15
- 5.25.462
+ 5.25.509
4.13.1
20030203.000129
1.8.12