wwwision/assetconstraints

此包已被 弃用 并不再维护。未建议替代包。

一个简单的包,可以根据标签、内容类型或资产集合来限制对 Neos.Media 资源的访问

v0.5.0 2017-10-17 09:56 UTC

This package is auto-updated.

Last update: 2020-01-31 00:36:42 UTC


README

一个简单的包,可以根据标签、内容类型或资产集合来限制对 Neos.Media 资源的访问

注意: 此包的功能已在 Neos Core 3.3 中移植

使用方法

  1. 将包放入您的 (Neos) 安装中
  2. 将策略添加到您的主包 Policy.yaml
  3. 调整 SettingsNodeTypes 配置以符合您的需求

特性

新的资产权限

此包包含实体权限,允许根据多个属性限制对 Assets 的读取

根据资产的 媒体类型 限制对 Assets 的读取访问

Policy.yaml

privilegeTargets:
  'Wwwision\AssetConstraints\Security\Authorization\Privilege\ReadAssetPrivilege':
    'Some.Package:ReadAllPDFs':
      matcher: 'hasMediaType("application/pdf")'

根据 标签 限制对 Assets 的读取访问

Policy.yaml

privilegeTargets:
  'Wwwision\AssetConstraints\Security\Authorization\Privilege\ReadAssetPrivilege':
    'Some.Package:ReadConfidentialAssets':
      matcher: 'isTagged("confidential")'

根据 资产集合 限制对 Assets 的读取访问

Policy.yaml

privilegeTargets:
  'Wwwision\AssetConstraints\Security\Authorization\Privilege\ReadAssetPrivilege':
    'Some.Package:ReadSpecialAssets':
      matcher: 'isInCollection("some-collection")'

当然,您可以组合这三个匹配器,例如

privilegeTargets:
  'Wwwision\AssetConstraints\Security\Authorization\Privilege\ReadAssetPrivilege':
    'Some.Package:ReadConfidentialPdfs':
      matcher: 'hasMediaType("application/pdf") && isTagged("confidential")'

根据 标签标签 限制对 Tags 的读取访问

Policy.yaml

privilegeTargets:
  'Wwwision\AssetConstraints\Security\Authorization\Privilege\ReadTagPrivilege':
    'Some.Package:ReadConfidentialTags':
      matcher: 'isLabeled("confidential")'

根据 集合标题 限制对 Asset Collections 的读取访问

Policy.yaml

privilegeTargets:
  'Wwwision\AssetConstraints\Security\Authorization\Privilege\ReadAssetCollectionPrivilege':
    'Some.Package:ReadSpecialAssetCollection':
      matcher: 'isTitled("some-collection")'

自定义编辑器根据节点属性设置资产集合

当使用 Neos 检查器上传新的 Assets 时,如果已配置 站点管理模块,则它们将被添加到当前站点的默认 Asset Collection

不幸的是,此机制(尚未)足够灵活,可以根据其他特征(例如当前选定的节点)设置集合。

因此,此包添加了两个专门的 Inspector 编辑器,用于上传资产/图像,这些编辑器将当前节点和上传数据一起发送到服务器。此外,它通过 AOP 钩入资产创建过程,根据当前节点将上传的 Asset 添加到 Asset Collection

默认行为是获取最近的文档节点,评估其 "assetCollection",如果成功,则将资产添加到该集合。

此包还附带一个 DataSource,允许选择 AssetCollection

将 "assetCollection" 属性添加到所有文档节点

NodeTypes.yaml

'Neos.Neos:Document':
  ui:
    inspector:
      groups:
        'assets':
          label: 'Assets'
  properties:
    'assetCollection':
      ui:
        label: 'Asset Collection'
        inspector:
          group: 'assets'
          editor: 'Content/Inspector/Editors/SelectBoxEditor'
          editorOptions:
            dataSourceIdentifier: 'wwwision-assetconstraints-assetcollections'
            allowEmpty: true
            placeholder: 'Asset Collection for uploads'

注意: 通常您 不需要 将属性添加到 所有 文档节点(包括快捷方式等),而是添加到更具体的节点类型,例如 Your.Package:Page

调整AOP方面的行为

如上所述,AOP方面的默认行为是在节点上传的节点最近的Neos.Neos:Document节点中检查名为"assetCollection"的属性。

这可以通过设置进行调整。假设您有一个自定义节点类型Your.Package:MainPage,它在一个名为"collection"的属性中包含目标assetCollection。

Settings.yaml

Wwwision:
  AssetConstraints:
    nodeLookup:
      nodeFilter: '[instanceof Your.Package:MainPage]'
      propertyName: 'collection'

示例策略

假设您有三个"组"以及相应的角色Some.Package:Group1EditorSome.Package:Group2EditorSome.Package:Group3Editor,还有一个管理员角色Some.Package:Administrator`。

现在,如果您有三个名为group1group2group3的"资产集合",以下Policy.yaml将限制编辑者只能看到与其角色对应的集合和资产

privilegeTargets:

  'Wwwision\AssetConstraints\Security\Authorization\Privilege\ReadAssetPrivilege':

    'Some.Package:Group1.ReadAssets':
      matcher: 'isInCollection("group1")'
    'Some.Package:Group2.ReadAssets':
      matcher: 'isInCollection("group2")'
    'Some.Package:Group3.ReadAssets':
      matcher: 'isInCollection("group3")'

  'Wwwision\AssetConstraints\Security\Authorization\Privilege\ReadAssetCollectionPrivilege':

    'Some.Package:Group1.ReadCollections':
      matcher: 'isTitled("group1")'
    'Some.Package:Group2.ReadCollections':
      matcher: 'isTitled("group2")'
    'Some.Package:Group3.ReadCollections':
      matcher: 'isTitled("group3")'

roles:

  'Your.Package:Administrator':
    privileges:
      -
        privilegeTarget: 'Some.Package:Group1.ReadAssets'
        permission: GRANT
      -
        privilegeTarget: 'Some.Package:Group1.ReadCollections'
        permission: GRANT
      -
        privilegeTarget: 'Some.Package:Group2.ReadAssets'
        permission: GRANT
      -
        privilegeTarget: 'Some.Package:Group2.ReadCollections'
        permission: GRANT
      -
        privilegeTarget: 'Some.Package:Group3.ReadAssets'
        permission: GRANT
      -
        privilegeTarget: 'Some.Package:Group3.ReadCollections'
        permission: GRANT

  'Your.Package:Group1Editor':
    privileges:
      -
        privilegeTarget: 'Some.Package:Group1.ReadAssets'
        permission: GRANT
      -
        privilegeTarget: 'Some.Package:Group1.ReadCollections'
        permission: GRANT

  'Your.Package:Group2Editor':
    privileges:
      -
        privilegeTarget: 'Some.Package:Group2.ReadAssets'
        permission: GRANT
      -
        privilegeTarget: 'Some.Package:Group2.ReadCollections'
        permission: GRANT

  'Your.Package:Group3Editor':
    privileges:
      -
        privilegeTarget: 'Some.Package:Group3.ReadAssets'
        permission: GRANT
      -
        privilegeTarget: 'Some.Package:Group3.ReadCollections'
        permission: GRANT

致谢

此包的开发得到了Web Essentials的慷慨赞助!