gpt4 book ai didi

java - Liferay 6.0.5 - 以编程方式在新页面中设置权限

转载 作者:行者123 更新时间:2023-11-30 09:19:59 25 4
gpt4 key购买 nike

我正在动态创建一个新的 liferay 页面(在 Liferay 中称为布局)。但是,它是使用默认用户权限创建的。

我需要的是为新页面设置权限:Power User只有权限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);

}

最佳答案

您可以使用此代码分配权限

Role userRole = RoleLocalServiceUtil.getRole(companyId, "POWER USER");

ResourcePermissionServiceUtil.setIndividualResourcePermissions(themeDisplay.getScopeGroupId(),
themeDisplay.getCompanyId(), Layout.class.getName(), "primKey",
userRole.getRoleId(), new String[] { ActionKeys.VIEW });

HTH

关于java - Liferay 6.0.5 - 以编程方式在新页面中设置权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17671689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com