我正在动态创建一个新的liferay页面(在Liferay中称为布局)。但是,它是使用默认用户权限创建的。
我需要设置新页面的权限:高级用户只有权限VIEW,但我想添加权限DELETE,UPDATE和PERMISSIONS。
我在互联网上查看的一种方法是:
long userRoleId = RoleLocalServiceUtil.getRole(companyId,
RoleConstants.POWER_USER).getRoleId();
ResourcePermissionLocalServiceUtil.addResourcePermission (
CompanyID,
layout.getModelClassName ().
ResourceConstants.SCOPE_INDIVIDUAL,
String.valueOf (layout.getPrimaryKey ()) userRoleId,
ActionKeys.DELETE);
另一个是:
ResourcePermissionServiceUtil.setIndividualResourcePermissions(groupId,
companyId, layout.getName(Locale.FRANCE),
String.valueOf(layout.getPrimaryKey()), userRoleId,
new String[] { ActionKeys.DELETE });
由于我的liferay版本是6.0.6,布局对象没有方法layout.getModelClassName(),所以我尝试使用方法layout.getClass()。getName()和layout.getName(Locale.FRANCE),以及结果是:
NoSuchResourceException
所以,如果有人知道如何以编程方式更改页面的权限,我将非常感激。
这是我用来创建新页面的代码(没有添加权限的代码):
private void createPage(ThemeDisplay themeDisplay, String name)
throws Exception {
_log.info("createPage:" + name);
long userId = themeDisplay.getUserId();
long groupId = themeDisplay.getScopeGroupId();
long companyId = themeDisplay.getCompanyId();
boolean privateLayout = false;
long parentLayoutId = 0;
String title = null;
String description = null;
String type = LayoutConstants.TYPE_PORTLET;
boolean hidden = true;
String friendlyURL = "/cngwallboard/" + name;
ServiceContext serviceContext = new ServiceContext();
serviceContext.setScopeGroupId(groupId);
Layout layout = LayoutLocalServiceUtil.addLayout(userId, groupId,
privateLayout, parentLayoutId, name, title, description, type,
hidden, friendlyURL, serviceContext);
LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout
.getLayoutType();
layoutTypePortlet.setLayoutTemplateId(userId, "3_pages2");
_log.info("setThemeId");
layout.setThemeId("wallboardconfiguration_WAR_wallboardconfigurationtheme");
LayoutSetLocalServiceUtil.updateLookAndFeel(layout.getGroupId(), false,
"wallboardconfiguration_WAR_wallboardconfigurationtheme", "01",
"", false);
PortletPreferences prefs = PortletPreferencesFactoryUtil
.getPortletSetup(layout, "118_INSTANCE_pg01", "");
prefs.setValue("layout-template-id", "2_windows_model_1");
prefs.setValue("portlet-setup-show-borders", "true");
prefs.store();
LayoutLocalServiceUtil.updateLayout(layout);
}
答案 0 :(得分:2)
您可以使用此代码分配权限
Role userRole = RoleLocalServiceUtil.getRole(companyId, "POWER USER");
ResourcePermissionServiceUtil.setIndividualResourcePermissions(themeDisplay.getScopeGroupId(),
themeDisplay.getCompanyId(), Layout.class.getName(), "primKey",
userRole.getRoleId(), new String[] { ActionKeys.VIEW });
HTH