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

Restrict roles created in sub orgs to be associated with the shared apps #593

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -25,7 +25,11 @@
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException;
import org.wso2.carbon.identity.application.common.model.IdPGroup;
import org.wso2.carbon.identity.application.common.model.ServiceProvider;
import org.wso2.carbon.identity.application.mgt.ApplicationConstants;
import org.wso2.carbon.identity.application.mgt.ApplicationManagementService;
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;
Expand Down Expand Up @@ -86,7 +90,6 @@
import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.INVALID_REQUEST;
import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.OPERATION_FORBIDDEN;
import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.ROLE_ALREADY_EXISTS;
import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.ROLE_MANAGEMENT_ERROR_CODE_PREFIX;
import static org.wso2.carbon.identity.role.v2.mgt.core.RoleConstants.Error.ROLE_NOT_FOUND;

/**
Expand All @@ -98,6 +101,7 @@ public class SCIMRoleManagerV2 implements RoleV2Manager {
private static final String ROLE_NAME_FILTER_ATTRIBUTE = "name";
private static final String ROLE_AUDIENCE_TYPE_FILTER_ATTRIBUTE = "audience";
private static final String ROLE_AUDIENCE_ID_FILTER_ATTRIBUTE = "audienceId";
private static final String APPLICATION_ROLE_AUDIENCE = "APPLICATION";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private final String USERS = "users";
private final String GROUPS = "groups";
private final String PERMISSIONS = "permissions";
Expand Down Expand Up @@ -126,6 +130,23 @@ public RoleV2 createRole(RoleV2 role)
+ tenantDomain;
throw new ConflictException(error);
}

if (OrganizationManagementUtil.isOrganization(tenantDomain) && APPLICATION_ROLE_AUDIENCE.equals(role.
getAudienceType())) {
ServiceProvider app = ApplicationManagementService.getInstance().getApplicationByResourceId(
role.getAudienceValue(), tenantDomain);
if (app == null) {
throw new BadRequestException("Invalid audience value. Audience value should be a valid service " +
"provider resource ID.");
}

if (app.getSpProperties() != null && Arrays.stream(app.getSpProperties())
.anyMatch(property -> ApplicationConstants.IS_FRAGMENT_APP.equals(property.getName())
&& Boolean.parseBoolean(property.getValue()))) {
throw new BadRequestException("Sub organization role association is not allowed with fragment " +
"applications.");
}
}
List<String> permissionValues = role.getPermissionValues();
List<Permission> permissionList = new ArrayList<>();
if (permissionValues != null) {
Expand Down Expand Up @@ -190,6 +211,14 @@ public RoleV2 createRole(RoleV2 role)
throw new CharonException(
String.format("Error occurred while retrieving IdP groups for role: %s", role.getDisplayName()),
e);
} catch (IdentityApplicationManagementException e) {
throw new CharonException(
String.format("Error occurred while retrieving service provider for role: %s", role.getDisplayName()),
e);
} catch (OrganizationManagementException e) {
throw new CharonException(
String.format("Error occurred while checking the organization status of the tenant: %s",
tenantDomain), e);
}
}

Expand Down
Loading