Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add base for fidp groups to role assignment #501

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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;
Expand Down Expand Up @@ -136,10 +137,16 @@ public RoleV2 createRole(RoleV2 role)
LOG.debug("Creating role: " + role.getDisplayName() + " for organization.");
}
}
// TODO: separate the groups into idp groups and userstore groups, and pass them separately.
RoleBasicInfo roleBasicInfo =
roleManagementService.addRole(role.getDisplayName(), role.getUsers(), role.getGroups(),
permissionList, audienceType, role.getAudienceValue(), tenantDomain);

// Set added groups as idp groups list.
List<IdpGroup> idpGroupList = role.getGroups().stream()
.map(IdpGroup::new)
.collect(Collectors.toList());
roleManagementService.updateIdpGroupListOfRole(roleBasicInfo.getId(), idpGroupList, new ArrayList<>(),
tenantDomain);
RoleV2 createdRole = new RoleV2();
createdRole.setId(roleBasicInfo.getId());
String locationURI = SCIMCommonUtils.getSCIMRoleV2URL(roleBasicInfo.getId());
Expand Down Expand Up @@ -202,20 +209,34 @@ public RoleV2 getRole(String roleID, Map<String, Boolean> requiredAttributes)
}
}

// Set role's assigned groups.
List<GroupBasicInfo> 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<GroupBasicInfo> 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<IdpGroup> 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<MultiValuedComplexType> associatedApps =
convertAssociatedAppsToMultivaluedComplexType(role.getAssociatedApplications());
Expand Down Expand Up @@ -875,7 +896,7 @@ private void updateGroups(String roleId, List<PatchOperation> groupOperations)
Set<String> replaceGroupsIds = new HashSet<>();

List<GroupBasicInfo> groupListOfRole = roleManagementService.getGroupListOfRole(roleId, tenantDomain);

List<IdpGroup> idpGroupListOfRole = roleManagementService.getIdpGroupListOfRole(roleId, tenantDomain);
for (PatchOperation groupOperation : groupOperations) {
if (groupOperation.getValues() instanceof Map) {
Map<String, String> groupObject = (Map<String, String>) groupOperation.getValues();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,29 @@ public static String getApplicationRefURL(String id) {
}
}

public static String getIdpGroupURL(String idpId, String groupId) {

String idpGroupURL;
String path = "/api/server/v1/identity-providers";
try {
if (IdentityTenantUtil.isTenantQualifiedUrlsEnabled()) {
idpGroupURL = ServiceURLBuilder.create().addPath(path).build()
.getAbsolutePublicURL();
} else {
idpGroupURL = getURLIfTenantQualifiedURLDisabled(path);
}
return StringUtils.isNotBlank(idpId) && StringUtils.isNotBlank(groupId) ?
new StringBuilder().append(idpGroupURL).append(SCIMCommonConstants.URL_SEPERATOR).append(idpId)
.append(SCIMCommonConstants.URL_SEPERATOR).append(groupId).toString() : null;
} catch (URLBuilderException e) {
if (log.isDebugEnabled()) {
log.debug("Error occurred while building the identity provider's group endpoint with " +
"tenant/organization qualified URL.", e);
}
return null;
}
}

public static String getPermissionRefURL(String apiId, String permissionName) {

String apiResourceURL;
Expand Down
Loading