代码之家  ›  专栏  ›  技术社区  ›  Aybek Kokanbekov

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

  •  2
  • Aybek Kokanbekov  · 技术社区  · 7 年前

    我已经在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)
    
    1 回复  |  直到 7 年前
        1
  •  3
  •   Aybek Kokanbekov    7 年前

    收到同事的回复。现在它开始工作了。 将guest的“自定义权限”字段设置为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();
    }