Liferay 7:获取组织自定义字段时未初始化 PermissionChecker

Posted

技术标签:

【中文标题】Liferay 7:获取组织自定义字段时未初始化 PermissionChecker【英文标题】:Liferay 7 : PermissionChecker not initialized while getting Organization custom field 【发布时间】:2018-05-03 07:43:41 【问题描述】:

我在 Liferay 7 门户中为组织创建了自定义字段。现在我想获取自定义字段的值并获取 PrincipalException - PermissionChecker 未初始化:

    Long userId = (Long) req.getSession().getAttribute(WebKeys.USER_ID);
    List<Organization> mylist = OrganizationLocalServiceUtil.getUserOrganizations(userId);
    if (!mylist.isEmpty()) 

        Organization organization = mylist.get(0);

        String orgUrl = group.getFriendlyURL();

>>>     ExpandoBridge expandoBridge = organization.getExpandoBridge();
        System.out.println(expandoBridge.getAttribute("custom_field"));
    

例外:

Caused by: com.liferay.portal.kernel.security.auth.PrincipalException: PermissionChecker not initialized
at com.liferay.portal.kernel.service.BaseServiceImpl.getPermissionChecker(BaseServiceImpl.java:81)
at com.liferay.portlet.expando.service.impl.ExpandoValueServiceImpl.getData(ExpandoValueServiceImpl.java:122)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:163)

【问题讨论】:

我将 security-manager-expando-bridge=com.liferay.portal.kernel.model.Organization 添加到 liferay-plugin-package.properties,但 PermissionChecker 仍有问题 【参考方案1】:

收到同事的答复。现在它正在工作。 为来宾将自定义字段的权限设置为 true 并添加此代码

try 
            User user = (User) req.getAttribute(WebKeys.USER);
            PrincipalThreadLocal.setName(userId);
            PermissionChecker permissionChecker;

            permissionChecker = PermissionCheckerFactoryUtil.create(user);
            PermissionThreadLocal.setPermissionChecker(permissionChecker);

            Organization organization = mylist.get(0);

            ExpandoBridge expandoBridge = organization.getExpandoBridge();
            System.out.println(expandoBridge.getAttribute("custom_field"));
 catch (Exception e) 
            // TODO Auto-generated catch block
            e.printStackTrace();

【讨论】:

以上是关于Liferay 7:获取组织自定义字段时未初始化 PermissionChecker的主要内容,如果未能解决你的问题,请参考以下文章

获取 ADT Liferay 7 的小图像 url

Liferay 7.1.3 GA4 自定义 Portlet 与番石榴依赖于部署:灾难性初始化失败! TypeNotPresentExceptionProxy

Liferay 7.3.5GA6 自定义索引搜索和ddmFieldArray

Liferay 7.2 自定义文档和媒体 Portlet

Liferay 7 - 博客聚合器的自定义样式

在 Liferay 7 中创建自定义标签库