/** * Updates the role's permissions at the scope, setting the actions that can be performed on * resources of the type. Existing actions are replaced. * * <p>This method can be used to set permissions at any scope, but it is generally only used at * the individual scope. For example, it could be used to set the guest permissions on a blog * post. * * <p>Depending on the scope, the value of <code>primKey</code> will have different meanings. For * more information, see {@link com.liferay.portal.model.impl.ResourcePermissionImpl}. * * @param groupId the primary key of the group * @param companyId the primary key of the company * @param name the resource's name, which can be either a class name or a portlet ID * @param primKey the primary key * @param roleId the primary key of the role * @param actionIds the action IDs of the actions * @throws PortalException if the user did not have permission to set resource permissions, or if * a role with the primary key or a resource action with the name and action ID could not be * found * @throws SystemException if a system exception occurred */ public static void setIndividualResourcePermissions( long groupId, long companyId, java.lang.String name, java.lang.String primKey, long roleId, java.lang.String[] actionIds) throws RemoteException { try { ResourcePermissionServiceUtil.setIndividualResourcePermissions( groupId, companyId, name, primKey, roleId, actionIds); } catch (Exception e) { _log.error(e, e); throw new RemoteException(e.getMessage()); } }
protected void updateRolePermissions(ActionRequest actionRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); String portletResource = ParamUtil.getString(actionRequest, "portletResource"); String modelResource = ParamUtil.getString(actionRequest, "modelResource"); long[] roleIds = StringUtil.split(ParamUtil.getString(actionRequest, "rolesSearchContainerPrimaryKeys"), 0L); String selResource = PortletConstants.getRootPortletId(portletResource); if (Validator.isNotNull(modelResource)) { selResource = modelResource; } long resourceGroupId = ParamUtil.getLong(actionRequest, "resourceGroupId", themeDisplay.getScopeGroupId()); String resourcePrimKey = ParamUtil.getString(actionRequest, "resourcePrimKey"); Map<Long, String[]> roleIdsToActionIds = new HashMap<Long, String[]>(); if (ResourceBlockLocalServiceUtil.isSupported(selResource)) { for (long roleId : roleIds) { List<String> actionIds = getActionIdsList(actionRequest, roleId, true); roleIdsToActionIds.put(roleId, actionIds.toArray(new String[actionIds.size()])); } ResourceBlockServiceUtil.setIndividualScopePermissions( themeDisplay.getCompanyId(), resourceGroupId, selResource, GetterUtil.getLong(resourcePrimKey), roleIdsToActionIds); } else { for (long roleId : roleIds) { String[] actionIds = getActionIds(actionRequest, roleId, false); roleIdsToActionIds.put(roleId, actionIds); } ResourcePermissionServiceUtil.setIndividualResourcePermissions( resourceGroupId, themeDisplay.getCompanyId(), selResource, resourcePrimKey, roleIdsToActionIds); } int pos = resourcePrimKey.indexOf(PortletConstants.LAYOUT_SEPARATOR); if (pos != -1) { long plid = GetterUtil.getLong(resourcePrimKey.substring(0, pos)); Layout layout = LayoutLocalServiceUtil.fetchLayout(plid); if (layout != null) { layout.setModifiedDate(new Date()); LayoutLocalServiceUtil.updateLayout(layout); CacheUtil.clearCache(layout.getCompanyId()); } } if (PropsValues.PERMISSIONS_PROPAGATION_ENABLED) { Portlet portlet = PortletLocalServiceUtil.getPortletById(themeDisplay.getCompanyId(), portletResource); PermissionPropagator permissionPropagator = portlet.getPermissionPropagatorInstance(); if (permissionPropagator != null) { permissionPropagator.propagateRolePermissions( actionRequest, modelResource, resourcePrimKey, roleIds); } } }