GithubHelp home page GithubHelp logo

hyperf-casbin's People

Contributors

donjan-deng avatar dygin avatar mmfei avatar nashgao avatar onekb avatar yyy1000 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hyperf-casbin's Issues

composer update 后报错

在项目目录composer update后无法使用,报下列错误
PHP Fatal error: Class Donjan\Casbin\Adapters\Mysql\DatabaseAdapter contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Casbin\Persist\UpdatableAdapter::updateFilteredPolicies) in /Users/apple/work/etoup/hyperf-admin/service/vendor/donjan-deng/hyperf-casbin/src/Adapters/Mysql/DatabaseAdapter.php on line 25

Fatal error: Class Donjan\Casbin\Adapters\Mysql\DatabaseAdapter contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Casbin\Persist\UpdatableAdapter::updateFilteredPolicies) in /Users/apple/work/etoup/hyperf-admin/service/vendor/donjan-deng/hyperf-casbin/src/Adapters/Mysql/DatabaseAdapter.php on line 25
[2021-08-31 21:16:00 *13099.2] ERROR php_swoole_server_rshutdown (ERRNO 503): Fatal error: Class Donjan\Casbin\Adapters\Mysql\DatabaseAdapter contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Casbin\Persist\UpdatableAdapter::updateFilteredPolicies) in /Users/apple/work/etoup/hyperf-admin/service/vendor/donjan-deng/hyperf-casbin/src/Adapters/Mysql/DatabaseAdapter.php on line 25
[2021-08-31 21:16:00 $13096.0] WARNING check_worker_exit_status: worker#2[pid=13099] abnormal exit, status=255, signal=0

service composer update
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 32 updates, 0 removals

  • Upgrading casbin/casbin (v3.7.0 => v3.9.0)
  • Upgrading donjan-deng/hyperf-casbin (3.6.0 => 3.6.1)
  • Upgrading friendsofphp/php-cs-fixer (v3.0.2 => v3.1.0)
  • Upgrading graham-campbell/result-type (v1.0.1 => v1.0.2)
  • Upgrading hyperf/database (v2.2.0 => v2.2.5)
  • Upgrading hyperf/devtool (v2.2.0 => v2.2.5)
  • Upgrading hyperf/filesystem (v2.2.0 => v2.2.6)
  • Upgrading hyperf/ide-helper (v2.2.0 => v2.2.5)
  • Upgrading hyperf/translation (v2.2.0 => v2.2.5)
  • Upgrading hyperf/utils (v2.2.4 => v2.2.5)
  • Upgrading hyperf/validation (v2.2.0 => v2.2.6)
  • Upgrading hyperf/watcher (v2.2.2 => v2.2.6.1)
  • Upgrading illuminate/collections (v8.55.0 => v8.57.0)
  • Upgrading illuminate/contracts (v8.55.0 => v8.57.0)
  • Upgrading illuminate/hashing (v8.55.0 => v8.57.0)
  • Upgrading illuminate/macroable (v8.55.0 => v8.57.0)
  • Upgrading illuminate/support (v8.55.0 => v8.57.0)
  • Upgrading league/flysystem (2.2.1 => 2.2.3)
  • Upgrading nesbot/carbon (2.51.1 => 2.52.0)
  • Upgrading phpoption/phpoption (1.7.5 => 1.8.0)
  • Upgrading phpstan/phpstan (0.12.94 => 0.12.96)
  • Upgrading swoole/ide-helper (4.7.0 => 4.7.1)
  • Upgrading symfony/cache (v5.3.4 => v5.3.7)
  • Upgrading symfony/console (v5.3.6 => v5.3.7)
  • Upgrading symfony/event-dispatcher (v5.3.4 => v5.3.7)
  • Upgrading symfony/expression-language (v5.3.4 => v5.3.7)
  • Upgrading symfony/finder (v5.3.4 => v5.3.7)
  • Upgrading symfony/options-resolver (v5.3.4 => v5.3.7)
  • Locking symfony/polyfill-php81 (v1.23.0)
  • Upgrading symfony/process (v5.3.4 => v5.3.7)
  • Upgrading symfony/string (v5.3.3 => v5.3.7)
  • Upgrading symfony/translation (v5.3.4 => v5.3.7)
  • Upgrading symfony/var-exporter (v5.3.4 => v5.3.7)
    Writing lock file
    Installing dependencies from lock file (including require-dev)
    Package operations: 1 install, 32 updates, 0 removals
  • Upgrading hyperf/utils (v2.2.4 => v2.2.5): Extracting archive
  • Upgrading phpoption/phpoption (1.7.5 => 1.8.0): Extracting archive
  • Upgrading graham-campbell/result-type (v1.0.1 => v1.0.2): Extracting archive
  • Upgrading symfony/finder (v5.3.4 => v5.3.7): Extracting archive
  • Upgrading symfony/translation (v5.3.4 => v5.3.7): Extracting archive
  • Upgrading nesbot/carbon (2.51.1 => 2.52.0): Extracting archive
  • Upgrading hyperf/database (v2.2.0 => v2.2.5): Extracting archive
  • Upgrading symfony/string (v5.3.3 => v5.3.7): Extracting archive
  • Upgrading symfony/console (v5.3.6 => v5.3.7): Extracting archive
  • Upgrading symfony/var-exporter (v5.3.4 => v5.3.7): Extracting archive
  • Upgrading symfony/cache (v5.3.4 => v5.3.7): Extracting archive
  • Upgrading symfony/expression-language (v5.3.4 => v5.3.7): Extracting archive
  • Upgrading casbin/casbin (v3.7.0 => v3.9.0): Extracting archive
  • Upgrading donjan-deng/hyperf-casbin (3.6.0 => 3.6.1): Extracting archive
  • Upgrading hyperf/translation (v2.2.0 => v2.2.5): Extracting archive
  • Upgrading hyperf/validation (v2.2.0 => v2.2.6): Extracting archive
  • Upgrading symfony/process (v5.3.4 => v5.3.7): Extracting archive
  • Installing symfony/polyfill-php81 (v1.23.0): Extracting archive
  • Upgrading symfony/options-resolver (v5.3.4 => v5.3.7): Extracting archive
  • Upgrading symfony/event-dispatcher (v5.3.4 => v5.3.7): Extracting archive
  • Upgrading friendsofphp/php-cs-fixer (v3.0.2 => v3.1.0): Extracting archive
  • Upgrading hyperf/devtool (v2.2.0 => v2.2.5): Extracting archive
  • Upgrading league/flysystem (2.2.1 => 2.2.3): Extracting archive
  • Upgrading hyperf/filesystem (v2.2.0 => v2.2.6): Extracting archive
  • Upgrading hyperf/ide-helper (v2.2.0 => v2.2.5): Extracting archive
  • Upgrading hyperf/watcher (v2.2.2 => v2.2.6.1): Extracting archive
  • Upgrading illuminate/macroable (v8.55.0 => v8.57.0): Extracting archive
  • Upgrading illuminate/contracts (v8.55.0 => v8.57.0): Extracting archive
  • Upgrading illuminate/collections (v8.55.0 => v8.57.0): Extracting archive
  • Upgrading illuminate/support (v8.55.0 => v8.57.0): Extracting archive
  • Upgrading illuminate/hashing (v8.55.0 => v8.57.0): Extracting archive
  • Upgrading phpstan/phpstan (0.12.94 => 0.12.96): Extracting archive
  • Upgrading swoole/ide-helper (4.7.0 => 4.7.1): Extracting archive

hyperf3.0 删除全部权限 ErrorException: Undefined property: Swoole\Coroutine\Http\Server::$setting

//model
**
[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, obj, act

[role_definition]
g = _, _

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act
**
//调用接口
Enforcer::deletePermissionsForUser($id);
//报错
[ERROR] ErrorException: Undefined property: Swoole\Coroutine\Http\Server::$setting in /data/project/vendor/donjan-deng/hyperf-casbin/src/Process/CasbinProcess.php:34
Stack trace:
#0 /data/project/vendor/donjan-deng/hyperf-casbin/src/Process/CasbinProcess.php(34): Hyperf\ExceptionHandler\Listener\ErrorExceptionHandler::Hyperf\ExceptionHandler\Listener{closure}()
#1 [internal function]: Donjan\Casbin\Process\CasbinProcess->Donjan\Casbin\Process{closure}()
#2 /data/project/vendor/hyperf/redis/src/RedisConnection.php(197): Redis->subscribe()
#3 /data/project/vendor/hyperf/redis/src/RedisConnection.php(83): Hyperf\Redis\RedisConnection->retry()
#4 /data/project/vendor/hyperf/redis/src/Redis.php(40): Hyperf\Redis\RedisConnection->__call()
#5 /data/project/vendor/donjan-deng/hyperf-casbin/src/Process/CasbinProcess.php(38): Hyperf\Redis\Redis->__call()
#6 /data/project/vendor/hyperf/process/src/AbstractProcess.php(134): Donjan\Casbin\Process\CasbinProcess->handle()
#7 /data/project/vendor/hyperf/utils/src/Coroutine.php(67): Hyperf\Process\AbstractProcess->Hyperf\Process{closure}()
#8 {main}

wathcer不管用如何解决

先执行 Enforcer::addPermissionForUser 再执行Enforcer::deletePermissionForUser删除同样的权限,但是再次调用添加权限方法失败,追代码追到 InternalEnforcer类中addPolicyInternal方法中的$this->model->hasPolicy($sec, $ptype, $rule)判断返回true,前面删除了权限这里应该返回false啊,所以设置了watcher为true也没用,但是在hyperf启动命令行中看到执行deletePermissionForUser方法,有Event Donjan\Casbin\Event\PolicyChanged handled by Donjan\Casbin\Listener\OnPolicyChangedListener listener.策略更新监听触发了。但是hasPolicy方法和getPermissionsForUser方法得出来的结果还是未更新前的。所以请问这个watcher在常驻进程中没有效果

权限更新问题

首先执行addPermissionForUser ,再执行getPermissionsForUser 获取不到最新的权限,只有重启hyperf或者添加Enforcer::loadPolicy();才能获取最新的权限,这个请问是为什么呢

Enforcer::addRoleForUser 报错

报错内容如下:

[2021-03-14 17:40:25] hyperf.ERROR: Call to undefined method stdClass::buildRoleLinks() [] []
[2021-03-14 17:40:25] hyperf.ERROR: #0 /www/hyperf/vendor/casbin/casbin/src/Enforcer.php(507): Casbin\Model\Model->buildRoleLinks()
#1 /www/sublet-admin-api/vendor/casbin/casbin/src/ManagementApi.php(448): Casbin\Enforcer->buildRoleLinks()
#2 /www/sublet-admin-api/vendor/casbin/casbin/src/ManagementApi.php(412): Casbin\Enforcer->addNamedGroupingPolicy()
#3 /www/sublet-admin-api/vendor/casbin/casbin/src/RbacApi.php(68): Casbin\Enforcer->addGroupingPolicy()
#4 /www/sublet-admin-api/vendor/donjan-deng/hyperf-casbin/src/Enforcer.php(121): Casbin\Enforcer->addRoleForUser()
#5 /www/sublet-admin-api/runtime/container/proxy/App_Service_AuthService.proxy.php(79): Donjan\Casbin\Enforcer->__call()

采坑了:Enforcer 不能持久容器化,因为对应的数据也被持久化了

Enforcer 不能持久容器化,因为对应的数据也被持久化了,导致数据无法实时对权限数据更新

vendor/donjan-deng/hyperf-casbin/src/Enforcer.php
public static function __callStatic($method, $parameters) { return ApplicationContext::getContainer()->get(Enforcer::class)->{$method}(...$parameters); }

想了下解决办法有好几种方式:
第一种是把这个容器注入的方式改成make(类似new操作,但是依赖会继续注入)
第二种就是我PR的方式直接不给成员变量赋值,每次都会重新获取,如果觉得每次查询很麻烦,可以开启缓存,实际也是读取的实时的缓存数据
第三种就是在模型操作事件中 再调用一个处理清除clean的方法(目前只是清除了缓存的key)---- 这种方式只适合单机应用

完善注解

phpstan: Call to an undefined static method Donjan\Casbin\Enforcer::enforce().

src/Enforcer.php 新增

  • @method static bool enforce(...$rvals)

Hyperf 3.0 启动失败

PHP Version: 8.0
Hyperf/framework Version: 3.0.0
使用热更新命令启动项目,提示:
Fatal error: Type of Donjan\Casbin\Process\CasbinProcess::$name must be string (as in class Hyperf\Process\AbstractProcess) in ~/myProject/vendor/donjan-deng/hyperf-casbin/src/Process/CasbinProcess.php on line 12

性能改进建议

打印sql日志发现每次判断权限都需要查询全表,如果表数据很大这样查询效率非常低吧
image

[bug] 添加角色或者权限报错

使用方法

Enforcer::addRoleForUser('users','roles');
Enforcer::addPermissionForUser('user','per');

报错信息


PHP Fatal error:  Uncaught Error: Call to a member function getType() on null in /home/muxin/work/hyperf/hyperf-api/vendor/hyperf/server/src/ServerFactory.php:67
Stack trace:
#0 /home/muxin/work/hyperf/hyperf-api/vendor/hyperf/server/src/SwooleServerFactory.php(22): Hyperf\Server\ServerFactory->getServer()
#1 /home/muxin/work/hyperf/hyperf-api/vendor/hyperf/di/src/Resolver/FactoryResolver.php(56): Hyperf\Server\SwooleServerFactory->__invoke()
#2 /home/muxin/work/hyperf/hyperf-api/vendor/hyperf/di/src/Resolver/ResolverDispatcher.php(62): Hyperf\Di\Resolver\FactoryResolver->resolve()
#3 /home/muxin/work/hyperf/hyperf-api/vendor/hyperf/di/src/Resolver/DepthGuard.php(73): Hyperf\Di\Resolver\ResolverDispatcher->Hyperf\Di\Resolver\{closure}()
#4 /home/muxin/work/hyperf/hyperf-api/vendor/hyperf/di/src/Resolver/ResolverDispatcher.php(63): Hyperf\Di\Resolver\DepthGuard->call()
#5 /home/muxin/work/hyperf/hyperf-api/vendor/hyperf/di/src/Container.php(184): Hyperf\Di\Resolver\ResolverDispatcher->resolve()
#6 /home/muxin/work/hyperf/hyperf-api/vendor/hyperf/di/src/Container.php(82): Hyperf\Di\Container->resolveDefinition()
#7 /home/muxin/work/hyperf/hyperf-api/vendor/hyperf/di/src/Container.php(117): Hyperf\Di\Container->make()
#8 /home/muxin/work/hyperf/hyperf-api/vendor/donjan-deng/hyperf-casbin/src/Listener/OnPolicyChangedListener.php(35): Hyperf\Di\Container->get()
#9 /home/muxin/work/hyperf/hyperf-api/vendor/hyperf/event/src/EventDispatcher.php(48): Donjan\Casbin\Listener\OnPolicyChangedListener->process()
#10 /home/muxin/work/hyperf/hyperf-api/vendor/donjan-deng/hyperf-casbin/src/Adapters/Mysql/DatabaseAdapter.php(163): Hyperf\Event\EventDispatcher->dispatch()
#11 /home/muxin/work/hyperf/hyperf-api/vendor/casbin/casbin/src/InternalEnforcer.php(47): Donjan\Casbin\Adapters\Mysql\DatabaseAdapter->addPolicy()
#12 /home/muxin/work/hyperf/hyperf-api/vendor/casbin/casbin/src/ManagementEnforcer.php(520): Casbin\InternalEnforcer->addPolicyInternal()
#13 /home/muxin/work/hyperf/hyperf-api/vendor/casbin/casbin/src/ManagementEnforcer.php(487): Casbin\ManagementEnforcer->addNamedGroupingPolicy()
#14 /home/muxin/work/hyperf/hyperf-api/vendor/casbin/casbin/src/Enforcer.php(69): Casbin\ManagementEnforcer->addGroupingPolicy()
#15 /home/muxin/work/hyperf/hyperf-api/vendor/donjan-deng/hyperf-casbin/src/Enforcer.php(65): Casbin\Enforcer->addRoleForUser()
#16 /home/muxin/work/hyperf/hyperf-api/app/Command/InitCommand.php(116): Donjan\Casbin\Enforcer::__callStatic()
#17 /home/muxin/work/hyperf/hyperf-api/vendor/hyperf/utils/src/Functions.php(276): App\Command\InitCommand->handle()
#18 /home/muxin/work/hyperf/hyperf-api/vendor/hyperf/command/src/Command.php(437): call()
#19 {main}
  thrown in /home/muxin/work/hyperf/hyperf-api/vendor/hyperf/server/src/ServerFactory.php on line 67

报错文件:

<?php
// donjan-deng/hyperf-casbin/src/Listener/OnPolicyChangedListener.php
namespace Donjan\Casbin\Listener;

use Psr\Container\ContainerInterface;
use Hyperf\Event\Contract\ListenerInterface;
use Donjan\Casbin\Event\PolicyChanged;
use Donjan\Casbin\Event\PipeMessage;
use Swoole\Server;
use Hyperf\Process\ProcessCollector;

class OnPolicyChangedListener implements ListenerInterface
{

    /**
     * @var ContainerInterface
     */
    private $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    public function listen(): array
    {
        return [
            PolicyChanged::class,
        ];
    }

    public function process(object $event)
    {
        if ($event instanceof PolicyChanged) {
            // 这一行报错
            $server = $this->container->get(Server::class);
            $workerCount = $server->setting['worker_num'] + ($server->setting['task_worker_num'] ?? 0) - 1;
            if ($workerCount > 0) {
                for ($workerId = 0; $workerId <= $workerCount; ++$workerId) {
                    if ($server->worker_id != $workerId) {
                        $server->sendMessage(new PipeMessage(PipeMessage::LOAD_POLICY), $workerId);
                    }
                }
            }
            if (class_exists(ProcessCollector::class) && !ProcessCollector::isEmpty()) {
                $processes = ProcessCollector::all();
                if ($processes) {
                    $string = serialize(new PipeMessage(PipeMessage::LOAD_POLICY));
                    foreach ($processes as $process) {
                        $process->exportSocket()->send($string, 10);
                    }
                }
            }
        }
    }

}

php 信息

   PHP 8.0.10 (cli) (built: Aug 26 2021 15:50:07) ( NTS )
   Copyright (c) The PHP Group
    Zend Engine v4.0.10, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.10, Copyright (c), by Zend Technologies
    with Yasd v0.3.9-alpha, Our Copyright, by codinghuang

swoole 信息

swoole

Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 4.6.7
Built => Jul  5 2021 17:59:14
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.1.1f  31 Mar 2020
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
pcre => enabled
zlib => 1.2.11
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608


composers

aliyuncs/oss-sdk-php                 v2.4.3    Aliyun OSS SDK for PHP
casbin/casbin                        v3.9.0    a powerful and efficient open-source access control library for php projects.
casbin/psr3-bridge                   v1.3.0    This library provides a PSR-3 compliant bridge for Casbin Logger.
composer/package-versions-deprecated 1.11.99.3 Composer plugin that provides efficient querying for installed package versions (no runtime IO)
composer/semver                      3.2.5     Semver library that offers utilities, version constraint parsing and validation.
composer/xdebug-handler              2.0.2     Restarts a process without Xdebug.
doctrine/annotations                 1.13.2    Docblock Annotations Parser
doctrine/cache                       2.1.1     PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, ...
doctrine/dbal                        3.1.1     Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.
doctrine/deprecations                v0.5.3    A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selec...
doctrine/event-manager               1.1.1     The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.
doctrine/inflector                   2.0.3     PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular...
doctrine/instantiator                1.4.0     A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                       1.2.1     PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
donjan-deng/hyperf-casbin            3.9.0     An authorization library that supports access control models like ACL, RBAC, ABAC in hyperf. 
dragonmantank/cron-expression        v3.1.0    CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due
easyswoole/spl                       1.4.0     php stander lib
easyswoole/verifycode                3.0.2    
egulias/email-validator              3.1.1     A library for validating emails against several RFCs
fig/http-message-util                1.1.5     Utility classes and constants for use with PSR-7 (psr/http-message)
friendsofphp/php-cs-fixer            v3.1.0    A tool to automatically fix PHP code style
graham-campbell/result-type          v1.0.2    An Implementation Of The Result Type
guzzlehttp/guzzle                    7.3.0     Guzzle is a PHP HTTP client library
guzzlehttp/promises                  1.4.1     Guzzle promises library
guzzlehttp/psr7                      2.0.0     PSR-7 message implementation that also provides common utility methods
hamcrest/hamcrest-php                v2.0.1    This is the PHP port of Hamcrest Matchers
hyperf/async-queue                   v2.2.0    A async queue component for hyperf.
hyperf/cache                         v2.2.0    A cache component for hyperf.
hyperf/command                       v2.2.0    Command for hyperf
hyperf/config                        v2.2.0    An independent component that provides configuration container.
hyperf/constants                     v2.2.0    A constants component for hyperf.
hyperf/contract                      v2.2.0    The contracts of Hyperf.
hyperf/crontab                       v2.2.5    A crontab component for Hyperf.
hyperf/database                      v2.2.5    A flexible database library.
hyperf/db-connection                 v2.2.0    A hyperf db connection handler for hyperf/database.
hyperf/devtool                       v2.2.5    A Devtool for Hyperf.
hyperf/di                            v2.2.7    A DI for Hyperf.
hyperf/dispatcher                    v2.2.0    A HTTP Server for Hyperf.
hyperf/engine                        v1.1.6   
hyperf/event                         v2.2.0    an event manager that implements PSR-14.
hyperf/exception-handler             v2.2.0    Exception handler for hyperf
hyperf/filesystem                    v2.2.6    flysystem integration for hyperf
hyperf/framework                     v2.2.0    A coroutine framework that focuses on hyperspeed and flexible, specifically use for build microservices and middlewares.
hyperf/guzzle                        v2.2.0    Swoole coroutine handler for guzzle
hyperf/http-message                  v2.2.0    microservice framework base on swoole
hyperf/http-server                   v2.2.4    A HTTP Server for Hyperf.
hyperf/ide-helper                    v2.2.5    IDE help files for Hyperf.
hyperf/logger                        v2.2.0    A logger component for hyperf.
hyperf/memory                        v2.2.0    An independent component that use to operate and manage memory.
hyperf/model-listener                v2.2.0    A model listener for Hyperf.
hyperf/pool                          v2.2.0    An independent universal connection pool component.
hyperf/process                       v2.2.3    A process component for hyperf.
hyperf/redis                         v2.2.0    A redis component for hyperf.
hyperf/server                        v2.2.0    A base server library for Hyperf.
hyperf/task                          v2.2.0    A task library for Hyperf.
hyperf/testing                       v2.2.0    Testing for hyperf
hyperf/translation                   v2.2.5    An independent translation component, forked by illuminate/translation.
hyperf/utils                         v2.2.7    A tools package that could help developer solved the problem quickly.
hyperf/validation                    v2.2.7    hyperf validation
hyperf/view                          v2.2.0    A view library for Hyperf.
hyperf/websocket-server              v2.2.0    A websocket server library for Hyperf.
laminas/laminas-mime                 2.9.0     Create and parse MIME messages and parts
laminas/laminas-stdlib               3.6.0     SPL extensions, array utilities, error handlers, and more
lcobucci/jwt                         3.2.5     A simple library to work with JSON Web Token and JSON Web Signature
league/flysystem                     1.1.5     Filesystem abstraction: Many filesystems, one API.
league/mime-type-detection           1.7.0     Mime-type detection for Flysystem
mockery/mockery                      1.4.3     Mockery is a simple yet flexible PHP mock object framework
monolog/monolog                      2.3.2     Sends your logs to files, sockets, inboxes, databases and various web services
myclabs/deep-copy                    1.10.2    Create deep copies (clones) of your objects
nesbot/carbon                        2.53.1    An API extension for DateTime that supports 281 different languages.
nikic/fast-route                     v1.3.0    Fast request router for PHP
nikic/php-parser                     v4.12.0   A PHP parser written in PHP
phar-io/manifest                     2.0.3     Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                      3.1.0     Library for handling version information and constraints
php-cs-fixer/diff                    v2.0.2    sebastian/diff v3 backport support for PHP 5.6+
php-di/phpdoc-reader                 2.2.1     PhpDocReader parses @var and @param values in PHP docblocks (supports namespaced class names with the same resolution rules...
phpdocumentor/reflection-common      2.2.0     Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock    5.2.2     With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is ...
phpdocumentor/type-resolver          1.4.0     A PSR-5 based resolver of Class names, Types and Structural Element Names
phper666/jwt-auth                    v3.0.5    jwt-auth Component
phpoption/phpoption                  1.8.0     Option Type for PHP
phpspec/prophecy                     1.13.0    Highly opinionated mocking framework for PHP 5.3+
phpstan/phpstan                      0.12.98   PHPStan - PHP Static Analysis Tool
phpunit/php-code-coverage            9.2.6     Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator            3.0.5     FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-invoker                  3.1.1     Invoke callables with a timeout
phpunit/php-text-template            2.0.4     Simple template engine.
phpunit/php-timer                    5.0.3     Utility class for timing
phpunit/phpunit                      9.5.9     The PHP Unit Testing framework.
psr/cache                            2.0.0     Common interface for caching libraries
psr/container                        1.1.1     Common Container Interface (PHP FIG PSR-11)
psr/event-dispatcher                 1.0.0     Standard interfaces for event handling.
psr/http-client                      1.0.1     Common interface for HTTP clients
psr/http-factory                     1.0.1     Common interfaces for PSR-7 HTTP message factories
psr/http-message                     1.0.1     Common interface for HTTP messages
psr/http-server-handler              1.0.1     Common interface for HTTP server-side request handler
psr/http-server-middleware           1.0.1     Common interface for HTTP server-side middleware
psr/log                              1.1.4     Common interface for logging libraries
psr/simple-cache                     1.0.1     Common interfaces for simple caching
ralouphie/getallheaders              3.0.3     A polyfill for getallheaders.
s1lentium/iptools                    v1.1.1    PHP Library for manipulating network addresses (IPv4 and IPv6)
sebastian/cli-parser                 1.0.1     Library for parsing CLI options
sebastian/code-unit                  1.0.8     Collection of value objects that represent the PHP code units
sebastian/code-unit-reverse-lookup   2.0.3     Looks up which function or method a line of code belongs to
sebastian/comparator                 4.0.6     Provides the functionality to compare PHP values for equality
sebastian/complexity                 2.0.2     Library for calculating the complexity of PHP code units
sebastian/diff                       4.0.4     Diff implementation
sebastian/environment                5.1.3     Provides functionality to handle HHVM/PHP environments
sebastian/exporter                   4.0.3     Provides the functionality to export PHP variables for visualization
sebastian/global-state               5.0.3     Snapshotting of global state
sebastian/lines-of-code              1.0.3     Library for counting the lines of code in PHP source code
sebastian/object-enumerator          4.0.4     Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector           2.0.4     Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context          4.0.4     Provides functionality to recursively process PHP variables
sebastian/resource-operations        3.0.3     Provides a list of PHP built-in functions that operate on resources
sebastian/type                       2.3.4     Collection of value objects that represent the types of the PHP type system
sebastian/version                    3.0.2     Library that helps with managing the version number of Git-hosted PHP projects
swoole/ide-helper                    4.7.1     IDE help files for Swoole.
symfony/cache                        v5.3.7    Provides an extended PSR-6, PSR-16 (and tags) implementation
symfony/cache-contracts              v2.4.0    Generic abstractions related to caching
symfony/console                      v5.3.7    Eases the creation of beautiful and testable command line interfaces
symfony/deprecation-contracts        v2.4.0    A generic function and convention to trigger deprecation notices
symfony/event-dispatcher             v5.3.7    Provides tools that allow your application components to communicate with each other by dispatching events and listening to...
symfony/event-dispatcher-contracts   v2.4.0    Generic abstractions related to dispatching event
symfony/expression-language          v5.3.7    Provides an engine that can compile and evaluate expressions
symfony/filesystem                   v5.3.4    Provides basic utilities for the filesystem
symfony/finder                       v5.3.7    Finds files and directories via an intuitive fluent interface
symfony/options-resolver             v5.3.7    Provides an improved replacement for the array_replace PHP function
symfony/polyfill-ctype               v1.23.0   Symfony polyfill for ctype functions
symfony/polyfill-intl-grapheme       v1.23.1   Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-idn            v1.23.0   Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer     v1.23.0   Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring            v1.23.1   Symfony polyfill for the Mbstring extension
symfony/polyfill-php72               v1.23.0   Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73               v1.23.0   Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/polyfill-php80               v1.23.1   Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/polyfill-php81               v1.23.0   Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions
symfony/process                      v5.3.7    Executes commands in sub-processes
symfony/property-access              v5.3.7    Provides functions to read and write from/to an object or array using a simple string notation
symfony/property-info                v5.3.7    Extracts information about PHP class' properties using metadata of popular sources
symfony/serializer                   v5.3.4    Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like...
symfony/service-contracts            v2.4.0    Generic abstractions related to writing services
symfony/stopwatch                    v5.3.4    Provides a way to profile code
symfony/string                       v5.3.7    Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way
symfony/translation                  v5.3.7    Provides tools to internationalize your application
symfony/translation-contracts        v2.4.0    Generic abstractions related to translation
symfony/var-exporter                 v5.3.7    Allows exporting any serializable PHP data structure to plain PHP code
theseer/tokenizer                    1.2.1     A small library for converting tokenized PHP source code into XML and potentially other formats
vlucas/phpdotenv                     v5.3.0    Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.
webmozart/assert                     1.10.0    Assertions to validate method input/output with nice error messages.
xxtime/flysystem-aliyun-oss          1.5.0     AliYun OSS adapter for flysystem. aliyuncs/oss-sdk-php ~2.3

配置文件修改了matchers不生效

[matchers] m = g(r.sub, p.sub) && r.obj == p.obj && (r.act == p.act || p.act == '*')

加了p.act == '*'

不知道有没有其他注意事项,还是我姿势有问题

检查用户权限的时候没有正确返回

检查用户权限的时候没有正确返回

var_dump(Enforcer::getRolesForUser('user1'),Enforcer::getUsersForRole('总检医生'),Enforcer::hasRoleForUser('use1', '总检医生'));

array(1) {
  [0]=>
  string(12) "总检医生"
}
array(1) {
  [0]=>
  string(5) "user1"
}
bool(false)

多进程下,hyperf有bug!

hyperf开启多进程时,每次修改(添加角色权限)只更新当前进程的model属性值,别的进程没有更新。Enforcer::enforce() 这个方法还是获取进程启动时加载的mode值。

添加或删除用户角色权限后,Enforcer::enforce检查部分错误

hyperf环境下

A用户在浏览器a对B用户修改角色权限
Enforcer::addRoleForUser("user{$userId}", "role{$roleId}");
Enforcer::addRoleForUser("user{$userId}", "role{$roleId}", '*');

Enforcer::deleteRoleForUser("user{$userId}", "role{$roleId}");
Enforcer::deleteRoleForUser("user{$userId}", "role{$roleId}", '*');

A用户修改B用户是,通过Enforcer::getRolesForUser查询的角色信息

string(54) "这是修改前前前前前前的权限信息 == 27381"
array(0) {
}
string(54) "这是修改后后后后后后的权限信息 == 27381"
array(1) {
  [0]=>
  string(6) "role22"
}

B用户在浏览器b登录
通过 Enforcer::enforce("user{$adminId}", $obj, $act); 获取部分权限时正常,部分权限不正常

B用户请求,通过Enforcer::getRolesForUser查询的角色信息

string(36) "这是查询的权限信息 == 27381"
array(1) {
  [0]=>
  string(6) "role22"
}
string(36) "这是查询的权限信息 == 27381"
array(1) {
  [0]=>
  string(6) "role22"
}
string(36) "这是查询的权限信息 == 27381"
array(0) {
}
string(36) "这是查询的权限信息 == 27381"
array(0) {
}
string(36) "这是查询的权限信息 == 27381"
array(0) {
}

请问是否是内存更新不及时导致的?

在Event::ON_START阶段,处理角色与权限时遇到这个异常

/config/autoload/server.php
... 'callbacks' => [ // 在里面重载所有角色的权限 Event::ON_START=> [App\Controller\IndexController::class, 'onInit'], Event::ON_WORKER_START => [Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'], Event::ON_PIPE_MESSAGE => [Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'], Event::ON_WORKER_EXIT => [Hyperf\Framework\Bootstrap\WorkerExitCallback::class, 'onWorkerExit'], ],

异常内容
PHP Warning: Swoole\Server::sendMessage(): can't send messages to self in /www/wwwroot/test/vendor/donjan-deng/hyperf-casbin/src/Listener/OnPolicyChangedListener.php on line 42

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.