gpt4 book ai didi

java - Liferay 7 : PermissionChecker not initialized while getting Organization custom field

转载 作者:行者123 更新时间:2023-11-30 02:19:02 28 4
gpt4 key购买 nike

我已经在 Liferay 7 门户中为组织创建了自定义字段。现在我想获取自定义字段的值并获取 PrimaryException - 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"));
}

异常(exception):

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

关于java - Liferay 7 : PermissionChecker not initialized while getting Organization custom field,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47386081/

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