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

Liferay 7 : PermissionChecker not initialized while getting Organization custom field

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

    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 并添加此代码

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