CakeDC / users

Users Plugin for CakePHP
https://www.cakedc.com
Other
520 stars 296 forks source link

IsAuthorizedTrait - Class "Zend\Diactoros\Uri" not found #997

Closed Maxime-Vacossin closed 2 years ago

Maxime-Vacossin commented 2 years ago

Hi !

I'm facing an issue with class Zend\Diactoros\Uri inside CakeDc/Auth. I'm maybe in the wrong repo for this issue.

I'm using : "cakedc/users": "^11.1", "cakephp/cakephp": "^4.3",

2022-03-30 14:46:50 error: [Error] Class "Zend\Diactoros\Uri" not found in /app/vendor/cakedc/auth/src/Traits/IsAuthorizedTrait.php on line 74
Stack Trace:
- /app/vendor/cakedc/auth/src/Traits/IsAuthorizedTrait.php:61
- /app/vendor/cakedc/auth/src/Traits/IsAuthorizedTrait.php:40
- /app/vendor/cakedc/users/src/Controller/Component/LoginComponent.php:168
- /app/vendor/cakedc/users/src/Controller/Component/LoginComponent.php:75
- /app/vendor/cakedc/users/src/Controller/Traits/LoginTrait.php:54
- /app/vendor/cakephp/cakephp/src/Controller/Controller.php:539
- /app/vendor/cakephp/cakephp/src/Controller/ControllerFactory.php:140
- /app/vendor/cakephp/cakephp/src/Controller/ControllerFactory.php:115
- /app/vendor/cakephp/cakephp/src/Http/BaseApplication.php:317
- /app/vendor/cakephp/cakephp/src/Http/Runner.php:77
- /app/vendor/cakephp/authorization/src/Middleware/RequestAuthorizationMiddleware.php:102
- /app/vendor/cakephp/cakephp/src/Http/Runner.php:73
- /app/vendor/cakephp/authorization/src/Middleware/AuthorizationMiddleware.php:129
- /app/vendor/cakephp/cakephp/src/Http/Runner.php:73
- /app/vendor/cakephp/authentication/src/Middleware/AuthenticationMiddleware.php:124
- /app/vendor/cakephp/cakephp/src/Http/Runner.php:73
- /app/vendor/cakephp/cakephp/src/Http/Middleware/BodyParserMiddleware.php:162
- /app/vendor/cakephp/cakephp/src/Http/Runner.php:73
- /app/vendor/cakephp/cakephp/src/Routing/Middleware/RoutingMiddleware.php:161
- /app/vendor/cakephp/cakephp/src/Http/Runner.php:73
- /app/vendor/cakephp/cakephp/src/Routing/Middleware/AssetMiddleware.php:68
- /app/vendor/cakephp/cakephp/src/Http/Runner.php:73
- /app/vendor/cakephp/cakephp/src/Error/Middleware/ErrorHandlerMiddleware.php:126
- /app/vendor/cakephp/cakephp/src/Http/Runner.php:73
- /app/vendor/cakephp/cakephp/src/Http/Runner.php:58
- /app/vendor/cakephp/cakephp/src/Http/Server.php:90
- /app/webroot/index.php:40

This error is generated with the following code in my template :

<?= $this->AuthLink->link('This link is visible', ['controller' => 'Something', 'action' => 'yes'], ['class' => 'btn btn-success']); ?>
<?= $this->AuthLink->link('AuthLink must hide this link', ['controller' => 'Something', 'action' => 'no'], ['class' => 'btn btn-danger']); ?>

Whith the following permissions :

        [
            'role' => '*',
            'controller' => 'Something',
            'action' => 'yes',
            'allowed' => true,
        ],
        [
            'role' => '*',
            'controller' => 'Something',
            'action' => 'no',
            'allowed' => false,
        ],

Actually, I have this error on the test serveur (Digital Ocean > Dokku app). And I'm not able to reproduce inside my VM locally.

Zend\Diactoros\Uri is used inside the cakedc/auth/src/Traits/IsAuthorizedTrait.php but is not required by the composer file. CakePhp use laminas/laminas-diactoros/ and 7 month ago, a conflict line was add to the project between Zend and Laminas. https://github.com/laminas/laminas-diactoros/blame/954e2dcfb1607681be44599faac10fc63bb6925a/composer.json#L57

I do not know if this is the reason .. If you have any idea to fix this, i'll take it !

rochamarcelo commented 2 years ago

Hi @maxime-vacossin

I could not reproduce the isse in my localhost. I suspect you are having issue with composer because it was suppose to alias (map) Zend\Diactoros\Uri to Laminas\Diactoros\Uri .

I would sugest you to remove vendor folder and run composer again.

We're going to analyse the option to rename the namespace in the plugin code.

Maxime-Vacossin commented 2 years ago

Hi @rochamarcelo , Thanks for this answer !

I've try to remove the vendor/ folder and process a clean install. No changes.

I have some other apps who are working perfectly .. We try some downgrades on the differents plugins.

From CakeDc/Users 9.2.1 to 11.1, we are facing the same issue.

So ... We took the problem from an other side. Actually, we use Digital Ocean (dokku) for hosting our applications.

We deploy our application on a brand new Clerver-Cloud server. And .. This is working good.

The problem is maybe related to Php extensions or something like this .. Reason why we where not able to reproduce this locally.

Conclusion : This is not an issue. Just server configuration. We can close this issue.

If you have any idea on any specific configuration for this issue, i'll take it again :)

rochamarcelo commented 2 years ago

Sorry, I don't know a configuration but in the meantime we are going to analyse the option to rename the related class to use the newer namespace.

fabiofdsantos commented 2 years ago

We are facing the same issue in production environment (Heroku). Can you check the PR https://github.com/CakeDC/auth/pull/70 ?