prooph/service-bus-zfc-rbac-bridge

将服务总线与 ZfcRbac 结合使用

v1.1 2015-11-23 16:06 UTC

This package is auto-updated.

Last update: 2024-09-17 01:59:19 UTC


README

将服务总线与 ZfcRbac 结合使用

Build Status Coverage Status Gitter

重要

此库将支持到 2019 年 12 月 31 日,之后将弃用。

有关更多信息,请参阅官方公告:[https://www.sasaprolic.com/2018/08/the-future-of-prooph-components.html](https://www.sasaprolic.com/2018/08/the-future-of-prooph-components.html)

安装

  1. "prooph/service-bus-zfc-rbac-bridge": "~1.0" 添加到您的 composer.json 文件的要求中。
  2. config 文件夹中,您将找到一个 配置框架。该配置是一个简单的 PHP 数组,并带有一些注释以帮助您理解结构。

要求

  1. 您的 Inversion of Control 容器必须实现 interop-container 接口
  2. ZfcRbac 的授权服务应在容器中注册为 ZfcRbac\Service\AuthorizationService 键。

注意:如果您的外部环境不提供这些要求,请不要担心。您始终可以手动引导授权服务。在这种情况下,只需查看工厂以获取灵感即可。

示例

假设有一个名为 test 的消息名称为 TestQuery,并且您想使用路由守卫和最终守卫以及一个断言(TestAssertion),则您的配置应如下所示

return [
    'prooph' => [
        'service_bus' => [
            'query_bus' => [
                'plugins' => [
                    \Prooph\ServiceBus\RouteGuard::class,
                    \Prooph\ServiceBus\FinalizeGuard::class,
                ]
            ]
        ]
    ],
    'zfc_rbac' => [
        'assertion_manager' => [
            'TestAssertion' => 'TestAssertion',
        ],
        'assertion_map' => [
            'test' => 'TestAssertion'
        ],
        'role_provider' => [
            'ZfcRbac\Role\InMemoryRoleProvider' => [
                'user' => [
                    'permissions' => [
                        'test'
                    ]
                ]
            ]
        ]
    ]
];

您的 TestAssertion 应该看起来像这样

class TestAssertion implements \ZfcRbac\Assertion\AssertionInterface
{
    public function assert(AuthorizationService $authorizationService, $context = null)
    {
        // return true, if no context present, otherwise your route guard will always fail, because the result is not yet known.
        if (null === $context) {
            return true;
        }

        return ($context['owner'] == $authorizationService->getIdentity());
    }
}

支持

贡献

请随意fork并扩展现有功能或添加新功能,并带有您更改的拉取请求!为了建立一致的代码质量,请为所有更改提供单元测试,并可能调整文档。

许可

New BSD 许可证 下发布。