public static void propagatePermissions( long companyId, long groupId, long parentMessageId, ServiceContext serviceContext) throws PortalException { MBMessage parentMessage = MBMessageLocalServiceUtil.getMBMessage(parentMessageId); Role defaultGroupRole = RoleLocalServiceUtil.getDefaultGroupRole(groupId); Role guestRole = RoleLocalServiceUtil.getRole(companyId, RoleConstants.GUEST); long[] roleIds = {defaultGroupRole.getRoleId(), guestRole.getRoleId()}; List<String> actionIds = ResourceActionsUtil.getModelResourceActions(MBMessage.class.getName()); Map<Long, Set<String>> roleIdsToActionIds = ResourcePermissionLocalServiceUtil.getAvailableResourcePermissionActionIds( companyId, MBMessage.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(parentMessage.getMessageId()), roleIds, actionIds); Set<String> defaultGroupActionIds = roleIdsToActionIds.get(defaultGroupRole.getRoleId()); if (defaultGroupActionIds == null) { serviceContext.setGroupPermissions(new String[] {}); } else { serviceContext.setGroupPermissions( defaultGroupActionIds.toArray(new String[defaultGroupActionIds.size()])); } Set<String> guestActionIds = roleIdsToActionIds.get(guestRole.getRoleId()); if (guestActionIds == null) { serviceContext.setGuestPermissions(new String[] {}); } else { serviceContext.setGuestPermissions(guestActionIds.toArray(new String[guestActionIds.size()])); } }
/** * Returns a new service context object identical to this service context object. * * @return a new service context object */ @Override public Object clone() { ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(isAddGroupPermissions()); serviceContext.setAddGuestPermissions(isAddGuestPermissions()); serviceContext.setAssetCategoryIds(getAssetCategoryIds()); serviceContext.setAssetEntryVisible(isAssetEntryVisible()); serviceContext.setAssetLinkEntryIds(getAssetLinkEntryIds()); serviceContext.setAssetTagNames(getAssetTagNames()); serviceContext.setAttributes(getAttributes()); serviceContext.setCommand(getCommand()); serviceContext.setCompanyId(getCompanyId()); serviceContext.setCreateDate(getCreateDate()); serviceContext.setCurrentURL(getCurrentURL()); serviceContext.setExpandoBridgeAttributes(getExpandoBridgeAttributes()); serviceContext.setFailOnPortalException(isFailOnPortalException()); serviceContext.setGroupPermissions(getGroupPermissions()); serviceContext.setGuestPermissions(getGuestPermissions()); serviceContext.setHeaders(getHeaders()); serviceContext.setIndexingEnabled(isIndexingEnabled()); serviceContext.setLanguageId(getLanguageId()); serviceContext.setLayoutFullURL(getLayoutFullURL()); serviceContext.setLayoutURL(getLayoutURL()); serviceContext.setModifiedDate(getModifiedDate()); serviceContext.setPathFriendlyURLPrivateGroup(getPathFriendlyURLPrivateGroup()); serviceContext.setPathFriendlyURLPrivateUser(getPathFriendlyURLPrivateUser()); serviceContext.setPathFriendlyURLPublic(getPathFriendlyURLPublic()); serviceContext.setPathMain(getPathMain()); serviceContext.setPlid(getPlid()); serviceContext.setPortalURL(getPortalURL()); serviceContext.setPortletPreferencesIds(getPortletPreferencesIds()); serviceContext.setRemoteAddr(getRemoteAddr()); serviceContext.setRemoteHost(getRemoteHost()); serviceContext.setRequest(getRequest()); serviceContext.setScopeGroupId(getScopeGroupId()); serviceContext.setSignedIn(isSignedIn()); serviceContext.setUserDisplayURL(getUserDisplayURL()); serviceContext.setUserId(getUserId()); serviceContext.setUuid(getUuid()); serviceContext.setWorkflowAction(getWorkflowAction()); return serviceContext; }
/** * Derive default permissions based on the logic found in * portal-web/docroot/html/taglib/ui/input_permissions/page.jsp. Do not update this logic updating * the logic in the JSP. */ public void deriveDefaultPermissions(long repositoryId, String modelName) throws PortalException { long siteGroupId = PortalUtil.getSiteGroupId(repositoryId); Group siteGroup = GroupLocalServiceUtil.getGroup(siteGroupId); Role defaultGroupRole = RoleLocalServiceUtil.getDefaultGroupRole(siteGroupId); List<String> groupPermissions = new ArrayList<String>(); List<String> guestPermissions = new ArrayList<String>(); String[] roleNames = {RoleConstants.GUEST, defaultGroupRole.getName()}; List<String> supportedActions = ResourceActionsUtil.getModelResourceActions(modelName); List<String> groupDefaultActions = ResourceActionsUtil.getModelResourceGroupDefaultActions(modelName); List<String> guestDefaultActions = ResourceActionsUtil.getModelResourceGuestDefaultActions(modelName); List<String> guestUnsupportedActions = ResourceActionsUtil.getModelResourceGuestUnsupportedActions(modelName); for (String roleName : roleNames) { for (String action : supportedActions) { if (roleName.equals(RoleConstants.GUEST) && !guestUnsupportedActions.contains(action) && guestDefaultActions.contains(action) && siteGroup.hasPublicLayouts()) { guestPermissions.add(action); } else if (roleName.equals(defaultGroupRole.getName()) && groupDefaultActions.contains(action)) { groupPermissions.add(action); } } } setGroupPermissions(groupPermissions.toArray(new String[groupPermissions.size()])); setGuestPermissions(guestPermissions.toArray(new String[guestPermissions.size()])); }
public void merge(ServiceContext serviceContext) { setAddGroupPermissions(serviceContext.isAddGroupPermissions()); setAddGuestPermissions(serviceContext.isAddGuestPermissions()); if (serviceContext.getAssetCategoryIds() != null) { setAssetCategoryIds(serviceContext.getAssetCategoryIds()); } if (serviceContext.getAssetLinkEntryIds() != null) { setAssetLinkEntryIds(serviceContext.getAssetLinkEntryIds()); } if (serviceContext.getAssetTagNames() != null) { setAssetTagNames(serviceContext.getAssetTagNames()); } if (serviceContext.getAttributes() != null) { setAttributes(serviceContext.getAttributes()); } if (Validator.isNotNull(serviceContext.getCommand())) { setCommand(serviceContext.getCommand()); } if (serviceContext.getCompanyId() > 0) { setCompanyId(serviceContext.getCompanyId()); } if (serviceContext.getCreateDate() != null) { setCreateDate(serviceContext.getCreateDate()); } if (Validator.isNotNull(serviceContext.getCurrentURL())) { setCurrentURL(serviceContext.getCurrentURL()); } if (serviceContext.getExpandoBridgeAttributes() != null) { setExpandoBridgeAttributes(serviceContext.getExpandoBridgeAttributes()); } if (serviceContext.getGroupPermissions() != null) { setGroupPermissions(serviceContext.getGroupPermissions()); } if (serviceContext.getGuestPermissions() != null) { setGuestPermissions(serviceContext.getGuestPermissions()); } if (serviceContext.getHeaders() != null) { setHeaders(serviceContext.getHeaders()); } setFailOnPortalException(serviceContext.isFailOnPortalException()); setLanguageId(serviceContext.getLanguageId()); if (Validator.isNotNull(serviceContext.getLayoutFullURL())) { setLayoutFullURL(serviceContext.getLayoutFullURL()); } if (Validator.isNotNull(serviceContext.getLayoutURL())) { setLayoutURL(serviceContext.getLayoutURL()); } if (serviceContext.getModifiedDate() != null) { setModifiedDate(serviceContext.getModifiedDate()); } if (Validator.isNotNull(serviceContext.getPathMain())) { setPathMain(serviceContext.getPathMain()); } if (serviceContext.getPlid() > 0) { setPlid(serviceContext.getPlid()); } if (Validator.isNotNull(serviceContext.getPortalURL())) { setPortalURL(serviceContext.getPortalURL()); } if (serviceContext.getPortletPreferencesIds() != null) { setPortletPreferencesIds(serviceContext.getPortletPreferencesIds()); } if (Validator.isNotNull(serviceContext.getRemoteAddr())) { setRemoteAddr(serviceContext.getRemoteAddr()); } if (Validator.isNotNull(serviceContext.getRemoteHost())) { setRemoteHost(serviceContext.getRemoteHost()); } if (serviceContext.getScopeGroupId() > 0) { setScopeGroupId(serviceContext.getScopeGroupId()); } setSignedIn(serviceContext.isSignedIn()); if (Validator.isNotNull(serviceContext.getUserDisplayURL())) { setUserDisplayURL(serviceContext.getUserDisplayURL()); } if (serviceContext.getUserId() > 0) { setUserId(serviceContext.getUserId()); } if (Validator.isNotNull(serviceContext.getUuid())) { setUuid(serviceContext.getUuid()); } if (serviceContext.getWorkflowAction() > 0) { setWorkflowAction(serviceContext.getWorkflowAction()); } }