Liferay 7:获得组织自定义字段时未初始化的许可检查



我已经在Liferay 7 Portal中为组织创建了自定义字段。现在,我想获得自定义字段的价值并获得princionalexception-请参差不多:

    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)

从同事那里收到答案。现在正在工作。将自定义字段的权限设置为true for Guest并添加此代码

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();
}

相关内容

  • 没有找到相关文章