Skip to content

Commit

Permalink
Add role properties to the SCIM2 Role response
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanChathusanda93 committed Dec 12, 2024
1 parent af6e5f2 commit c3eaa5f
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
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.RoleProperty;
import org.wso2.carbon.identity.role.v2.mgt.core.model.UserBasicInfo;
import org.wso2.carbon.identity.role.v2.mgt.core.util.RoleManagementUtils;
import org.wso2.carbon.identity.role.v2.mgt.core.util.UserIDResolver;
Expand Down Expand Up @@ -101,6 +102,7 @@ public class SCIMRoleManagerV2 implements RoleV2Manager {
private final String GROUPS = "groups";
private final String PERMISSIONS = "permissions";
private final String ASSOCIATED_APPLICATIONS = "associatedApplications";
private final String PROPERTIES = "properties";
private RoleManagementService roleManagementService;
private String tenantDomain;
private Set<String> systemRoles;
Expand Down Expand Up @@ -211,6 +213,9 @@ public RoleV2 getRole(String roleID, Map<String, Boolean> requiredAttributes)
if (systemRoles.contains(role.getName())) {
scimRole.setSystemRole(true);
}
List<MultiValuedComplexType> roleProperties =
convertRolePropertiesToMultiValuedComplexType(role.getRoleProperties());
scimRole.setRoleProperties(roleProperties);
// Set permissions.
List<MultiValuedComplexType> permissions =
convertPermissionsToMultiValuedComplexType(role.getPermissions());
Expand Down Expand Up @@ -307,6 +312,20 @@ private List<MultiValuedComplexType> convertPermissionsToMultiValuedComplexType(
return permissionValues;
}

private List<MultiValuedComplexType> convertRolePropertiesToMultiValuedComplexType(List<RoleProperty> roleProperties) {

List<MultiValuedComplexType> rolePropertyValues = new ArrayList<>();
if (roleProperties != null) {
for (RoleProperty roleProperty : roleProperties) {
MultiValuedComplexType rolePropertyComplexObject = new MultiValuedComplexType();
rolePropertyComplexObject.setValue(roleProperty.getValue());
rolePropertyComplexObject.setDisplay(roleProperty.getName());
rolePropertyValues.add(rolePropertyComplexObject);
}
}
return rolePropertyValues;
}

public void deleteRole(String roleID) throws CharonException, NotFoundException, BadRequestException {

try {
Expand Down Expand Up @@ -673,6 +692,14 @@ private List<RoleV2> getScimRolesList(List<Role> roles, List<String> requiredAtt
scimRole.setAssociatedApplications(associatedApps);
}
}
if (requiredAttributes.contains(PROPERTIES)) {
// Set role properties.
List<MultiValuedComplexType> roleProperties =
convertRolePropertiesToMultiValuedComplexType(role.getRoleProperties());
if (CollectionUtils.isNotEmpty(roleProperties)) {
scimRole.setRoleProperties(roleProperties);
}
}
}
scimRoles.add(scimRole);
}
Expand Down

0 comments on commit c3eaa5f

Please sign in to comment.