Liferay向DLFolder添加资源权限

时间:2017-03-02 06:15:49

标签: liferay directory actionlistener liferay-6

我尝试为使用自定义侦听器在门户中创建的每个文件夹添加资源权限,对角色“Guest”具有ACCESS权限但在数据库表中未成功注册, 仅注册具有操作ID 0的角色的权限,我尝试使用此:

public void onAfterCreate(DLFolder folder) throws ModelListenerException {
    super.onAfterCreate(folder);
    long folderId = folder.getFolderId();
    primFOLDER = folderId;
    try {
        long guestId = RoleServiceUtil.getRole(companyId, RoleConstants.GUEST).getRoleId();
        ResourcePermission resourcePermission = ResourcePermissionLocalServiceUtil
                .createResourcePermission(CounterLocalServiceUtil.increment());
        resourcePermission.setCompanyId(companyId);
        resourcePermission.setName(folderClass);
        resourcePermission.setScope(ResourceConstants.SCOPE_INDIVIDUAL);
        resourcePermission.setPrimKey(String.valueOf(folderId));
        resourcePermission.setRoleId(guestId);
        resourcePermission.setActionIds(2);
        ResourcePermissionLocalServiceUtil.addResourcePermission(resourcePermission);
        ResourcePermission resourcePermissionRecover = ResourcePermissionLocalServiceUtil.getResourcePermission(
                companyId, folderClass, ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(folderId), guestId);
        if (resourcePermissionRecover != null) {
            resourcePermissionRecover.setActionIds(2);
            ResourcePermissionLocalServiceUtil.updateResourcePermission(resourcePermissionRecover);
        }
    } catch (PortalException | SystemException e) {
        e.printStackTrace();
    }
}

我不知道哪个是我的错误。谢谢。

1 个答案:

答案 0 :(得分:0)