gpt4 book ai didi

java - 如何在 Liferay 中为自定义角色的布局添加 VIEW 权限

转载 作者:行者123 更新时间:2023-11-30 06:55:03 27 4
gpt4 key购买 nike

我一直在尝试传播自定义角色的布局的“查看”权限,但该布局和该自定义角色的资源权限表中不存在该条目。如下面的代码所示,布局权限最好使用

设置
ResourcePermissionServiceUtil.setIndividualResourcePermissions(groupId, companyId, layout.getModelClassName(),
"primkey", roleIdsToActionIds);

但是,这里第一次调用有效,但第二次调用设置当前布局的父布局权限,它会给出错误日志中所示的错误。有人可以指导我如何实现这一目标吗?

    // Propagete VIEW access to Page, on which Portlet is added - START
long plid = LayoutLocalServiceUtil.getDefaultPlid(groupId, false, portletId);
if(plid!=0){
Layout layout = LayoutLocalServiceUtil.getLayout(plid);
if(layout!=null){
_log.info("Adding permission for layout: "+layout+", layout model class name:"+layout.getModelClassName()+", scope:"+ResourceConstants.SCOPE_INDIVIDUAL
+", primkey:"+String.valueOf(plid)+", roleid:"+customRoleId+", actionid:"+ ActionKeys.VIEW);

Map<Long, String[]> roleIdsToActionIds = new HashMap<Long, String[]>();
List<String> actionIds = new ArrayList<String>();
actionIds.add(ActionKeys.VIEW);

roleIdsToActionIds.put(customRoleId, actionIds.toArray(new String[actionIds.size()]));

ResourcePermissionServiceUtil.setIndividualResourcePermissions(groupId, companyId, layout.getModelClassName(),
String.valueOf(plid), roleIdsToActionIds);


// TODO: give view permission to all its parent layouts as well
while(layout.getParentLayoutId()!=0){
layout = LayoutLocalServiceUtil.getParentLayout(layout);
_log.info("Adding permission for parent layout: "+layout+", layout model class name:"+layout.getModelClassName()+", scope:"+ResourceConstants.SCOPE_INDIVIDUAL
+", primkey:"+String.valueOf(layout.getPlid())+", roleid:"+customRoleId+", actionid:"+ ActionKeys.VIEW);

ResourcePermissionServiceUtil.setIndividualResourcePermissions(groupId, companyId, layout.getModelClassName(),
String.valueOf(layout.getPlid()), roleIdsToActionIds);
}

_log.debug("Added view permission for page of portlet:"+portletId);

}
} // Propagete VIEW access to Page, on which Portlet is added - END

错误日志:

    ...


Adding permission for layout: {uuid=e3d30768-8025-494b-b651-aa12e34baa45, plid=100207, groupId=AAA, companyId=XXX, userId=20199, userName=Liferay Admin, createDate=Sat Jan 14 00:56:55 GMT 2017, modifiedDate=Sat Jan 14 00:58:48 GMT 2017, privateLayout=false, layoutId=89, parentLayoutId=30, name=<?xml version='1.0' encoding='UTF-8'?><root available-locales="en_US" default-locale="en_US"><Name language-id="en_US">Notifications</Name></root>, title=, description=, keywords=, robots=, type=portlet, typeSettings=column-1=XXX_WAR_YYY,
column-2=XXXZZZ_WAR_XXXWWW
layout-template-id=my_custom_layout
, hidden=false, friendlyURL=/notifications, iconImage=false, iconImageId=0, themeId=, colorSchemeId=, wapThemeId=, wapColorSchemeId=, css=, priority=4, layoutPrototypeUuid=, layoutPrototypeLinkEnabled=false, sourcePrototypeLayoutUuid=}, layout model class name:com.liferay.portal.model.Layout, scope:4, primkey:100207, roleid:73933, actionid:VIEW
02:01:14,465 INFO [http-bio-443-exec-46][setupServiceImpl:955] layout.getParentLayoutId():30
02:01:14,466 INFO [http-bio-443-exec-46][setupServiceImpl:958] Adding permission for parent layout: {uuid=f7202f94-3660-426f-bd18-7e083668d5ac, plid=26752, groupId=AAA, companyId=XXX, userId=XXX, userName=XXX Admin, createDate=Thu Apr 14 15:59:06 GMT 2016, modifiedDate=Wed Dec 07 20:33:22 GMT 2016, privateLayout=false, layoutId=30, parentLayoutId=3, name=<?xml version='1.0' encoding='UTF-8'?><root available-locales="en_US" default-locale="en_US"><Name language-id="en_US">Users</Name></root>, title=, description=, keywords=, robots=, type=link_to_layout, typeSettings=column-1-customizable=false
column-2-customizable=false
groupId=AAA
layout-template-id=my_custom_layout
layoutUpdateable=true
linkToLayoutId=31
privateLayout=false
sitemap-changefreq=daily
sitemap-include=1
, hidden=false, friendlyURL=/users, iconImage=false, iconImageId=0, themeId=classic, colorSchemeId=, wapThemeId=, wapColorSchemeId=, css=, priority=9, layoutPrototypeUuid=, layoutPrototypeLinkEnabled=false, sourcePrototypeLayoutUuid=}, layout model class name:com.liferay.portal.model.Layout, scope:4, primkey:26752, roleid:73933, actionid:VIEW
java.lang.NullPointerException
at com.liferay.portal.service.impl.ResourcePermissionLocalServiceImpl.doUpdateResourcePermission(ResourcePermissionLocalServiceImpl.java:1200)
at com.liferay.portal.service.impl.ResourcePermissionLocalServiceImpl.doUpdateResourcePermission(ResourcePermissionLocalServiceImpl.java:1253)
at com.liferay.portal.service.impl.ResourcePermissionLocalServiceImpl.updateResourcePermission(ResourcePermissionLocalServiceImpl.java:1407)
at com.liferay.portal.service.impl.ResourcePermissionLocalServiceImpl.setResourcePermissions(ResourcePermissionLocalServiceImpl.java:1134)
at sun.reflect.GeneratedMethodAccessor1164.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:115)
at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:62)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:51)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:111)
at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:175)
at com.sun.proxy.$Proxy152.setResourcePermissions(Unknown Source)
at com.liferay.portal.service.impl.ResourcePermissionServiceImpl.setIndividualResourcePermissions(ResourcePermissionServiceImpl.java:238)
at sun.reflect.GeneratedMethodAccessor1163.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:115)
at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:62)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:51)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:111)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:56)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:111)
at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:175)
at com.sun.proxy.$Proxy153.setIndividualResourcePermissions(Unknown Source)
at com.liferay.portal.service.ResourcePermissionServiceUtil.setIndividualResourcePermissions(ResourcePermissionServiceUtil.java:245)

最佳答案

看来这个 API 调用终于解决了我的问题。

ResourcePermissionLocalServiceUtil.setResourcePermissions(
companyId, Layout.class.getName(),
ResourceConstants.SCOPE_INDIVIDUAL,
String.valueOf(layout.getPlid()), customRoleId,
new String[] {
ActionKeys.VIEW
});

在尝试这个之前,我还尝试了下面两个其他 Liferay API,但没有成功。

ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId, layout.getModelClassName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(layout.getPlid()), roleIdsToActionIds);

ResourcePermissionServiceUtil.addResourcePermission(groupId, companyId, layout.getModelClassName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(layout.getPlid()), customRoleId, ActionKeys.VIEW);

都失败了,但有异常(exception)。

java.lang.NullPointerException
at com.liferay.portal.service.impl.ResourcePermissionLocalServiceImpl.doUpdateResourcePermission(ResourcePermissionLocalServiceImpl.java:1200)
at com.liferay.portal.service.impl.ResourcePermissionLocalServiceImpl.doUpdateResourcePermission(ResourcePermissionLocalServiceImpl.java:1253)
at com.liferay.portal.service.impl.ResourcePermissionLocalServiceImpl.updateResourcePermission(ResourcePermissionLocalServiceImpl.java:1407)
at com.liferay.portal.service.impl.ResourcePermissionLocalServiceImpl.setResourcePermissions(ResourcePermissionLocalServiceImpl.java:1134)

关于java - 如何在 Liferay 中为自定义角色的布局添加 VIEW 权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42010063/

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