2amigos / yii2-usuario

Highly customizable and extensible user management, authentication, and authorization Yii2 extension
https://github.com/2amigos/yii2-usuario
Other
292 stars 140 forks source link

Enabling AuthManager cache causes error in finding rules #516

Closed maxxer closed 1 year ago

maxxer commented 1 year ago

What steps will reproduce the problem?

    'authManager' => [
        'class' => 'Da\User\Component\AuthDbManagerComponent',
        'cache' => 'cache',
    ],

What do you get instead?

2023-04-24 16:04:31 [188.2.2.6][12][9c081te88kqc8beff79jatv2pb][error][yii\base\InvalidConfigException] yii\base\InvalidConfigException: Rule not found: SedeRule in /dati/www/app/pubblica/vendor/yiisoft/yii2/rbac/BaseManager.php:278
Stack trace:
#0 /dati/www/app/pubblica/vendor/yiisoft/yii2/rbac/DbManager.php(170): yii\rbac\BaseManager->executeRule(12, Object(yii\rbac\Permission), Array)
#1 /dati/www/app/pubblica/vendor/yiisoft/yii2/rbac/DbManager.php(180): yii\rbac\DbManager->checkAccessFromCache(12, 'gestioneSede', Array, Array)
#2 /dati/www/app/pubblica/vendor/yiisoft/yii2/rbac/DbManager.php(180): yii\rbac\DbManager->checkAccessFromCache(12, 'accessoSede', Array, Array)
#3 /dati/www/app/pubblica/vendor/yiisoft/yii2/rbac/DbManager.php(180): yii\rbac\DbManager->checkAccessFromCache(12, 'accessoStruttur...', Array, Array)
#4 /dati/www/app/pubblica/vendor/yiisoft/yii2/rbac/DbManager.php(141): yii\rbac\DbManager->checkAccessFromCache(12, 'accessoA', Array, Array)
#5 /dati/www/app/pubblica/vendor/yiisoft/yii2/web/User.php(759): yii\rbac\DbManager->checkAccess(12, 'accessoA', Array)
#6 /dati/www/app/pubblica/vendor/esempla/yii2-dynamic-menu/src/widgets/DynamicMenuWidget.php(193): yii\web\User->can('accessoA')
#7 /dati/www/app/pubblica/vendor/esempla/yii2-dynamic-menu/src/widgets/DynamicMenuWidget.php(243): esempla\dynamicmenu\widgets\DynamicMenuWidget->_checkItemVisiblity(Array)
#8 /dati/www/app/pubblica/vendor/esempla/yii2-dynamic-menu/src/widgets/DynamicMenuWidget.php(70): esempla\dynamicmenu\widgets\DynamicMenuWidget->normalizeItems(Array, NULL)
#9 /dati/www/app/pubblica/vendor/yiisoft/yii2/base/Widget.php(146): esempla\dynamicmenu\widgets\DynamicMenuWidget->run()
#10 /dati/www/app/pubblica/views/layouts/left.php(26): yii\base\Widget::widget(Array)

Switching from AuthDbManagerComponent to yii's yii\rbac\DbManager doesn't trigger the error

maxxer commented 1 year ago

Not actually an issue, but a behavioral difference: while (most? default?) db component is case insensitive, caching is not because stored items are saved in array keys, which are case sensitive.

So, a rule saved as rule01, declared in auth item as Rule01, works when checked via MariaDB/MySQL but not from array.