定制 gtt/reverse-search-acl 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gtt/reverse-search-acl

Composer 安装命令:

composer require gtt/reverse-search-acl

包简介

Provides a way for Symfony's ACL infrastructure to find object identities that are accessible (with specified permission like VIEW, EDIT, etc) by specified security identity

README 文档

README

Build Status Latest Stable Version Latest Unstable Version License

This library extends base Symfony's MutableAclProvider with ability to find accessible object identities for specified security identity. You can also specify permission Ace was granted for target security identity with.

This library provides convenient way create admin interfaces for ACL-based systems where you need to show assigned domain objects and permissions for fetched for requested single user in the system

Requirements

Library requires Symfony's security-acl package and doctrine/dbal component to interact with acl database

How it works?

As was said above the library contains extended acl provider - ReverseSearchAclProvider. Basically there is nothing more inside. The main goal of this provider being is to do reverse action against PermissionGrantingStrategy does when it checks whether specified SecurityIdentity has access (the type of access is restricted by permission: VIEW, EDIT, etc) to specified ObjectIdentity or not. Due to performance reasons (which were actually kept in mind during Symfony's ACL system designing) ReverseSearchAclProvider solves this task by constructing and executing PDO statement similar to the other ones in AclProvider.

Installation

Library can by installed with composer quite easy:

composer require gtt/reverse-search-acl

Usage

In order to create instance of ReverseSearchAclProvider you need to specify the same constructor parameters that are required for MutableAclProvider and prepend this list with the instance of PermissionMapInterface (since ReverseSearchAclProvider needs to translate specified permission to masks):

use Gtt\Acl\Dbal\ReverseSearchAclProvider;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Permission\BasicPermissionMap;
use Symfony\Component\Security\Acl\Permission\BasicPermissionMap;
use Doctrine\DBAL\DriverManager;

$provider = new ReverseSearchAclProvider(
    new BasicPermissionMap()
    DriverManager::getConnection(['driver' => 'pdo_sqlite','memory' => true],
    new PermissionGrantingStrategy(),
    [] // list of base acl provider options
);

Now you are ready to find which domain objects (or classes itself or class/object fields) can see (permission VIEW) some user or role:

$sid = UserSecurityIdentity::fromAccount(new User('jimmy', 'jimmypass'));
// you can also analyse roles
// $sid = new RoleSecurityIdentity('ROLE_ADMIN');

$allowed = $provider->findAllowedEntries($sid, "VIEW")

The returned result will be an array with the following structure

[
    // the key is FQCN of the class of the object that can be accessed by specified Security Identity instance (SID)
    '\F\Q\C\N' => [
        // if this flag is presented class ace was inserted for current SID
        'class_access'        => true,
        // list of class field's granted to current SID
        'class_field_access'  => ['field1', 'field2', 'field3'],
        // id of the domain objects accessible by current SID
        'object_access'       => ['id1', 'id2', 'id3', 'id4'],
        // list of domain object fields (grouped by object id) granted to current SID
        'object_field_access' => [
           'id2' => ['field1', 'field2'],
           'id5' => ['field3']
        ]
    ]
]

You can also restrict the search by specifying class and/or field of the allowed object identities to fetch:

$allowed = $provider->findObjectIdentities(
    $sid,
    "VIEW",
    ['class' => \My\Domain\Object\Class]
);

Restrictions

  • Note that library reverse work of PermissionGrantingStrategy. Use it with the other ones only if you know exactly what are you doing.

  • If you use the both object and class aces (or object field and class field aces) you should note the PermissionGrantingStrategy during access decisions consequentially checks object-level and then class-level ACE's to grant or deny access. Object and class access information returned by provider separately so to be sure that current SID has (or doesn't have) access to current object you should take in account the both class and object access info (ie object_access/class_access or object_field_access/class_field_access).

  • Be careful if you are using PermissionMapInterface instances that are really take in account specified object (second parameter in PermissionMapInterface::getMasks method) during retrieving masks process (there are no such PermissionMapInterface implementations in Symfony for now, but anyway).

gtt/reverse-search-acl 适用场景与选型建议

gtt/reverse-search-acl 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26 次下载、GitHub Stars 达 4, 最近一次更新时间为 2015 年 09 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「search」 「acl」 「reverse」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 gtt/reverse-search-acl 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 gtt/reverse-search-acl 我们能提供哪些服务?
定制开发 / 二次开发

基于 gtt/reverse-search-acl 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 26
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-03