{"action":"created","issue":{"url":"https://api.github.com/repos/zendframework/zend-expressive-authorization-acl/issues/15","repository_url":"https://api.github.com/repos/zendframework/zend-expressive-authorization-acl","labels_url":"https://api.github.com/repos/zendframework/zend-expressive-authorization-acl/issues/15/labels{/name}","comments_url":"https://api.github.com/repos/zendframework/zend-expressive-authorization-acl/issues/15/comments","events_url":"https://api.github.com/repos/zendframework/zend-expressive-authorization-acl/issues/15/events","html_url":"https://github.com/zendframework/zend-expressive-authorization-acl/issues/15","id":318244837,"node_id":"MDU6SXNzdWUzMTgyNDQ4Mzc=","number":15,"title":"Suggestion on ZendAcl->isGranted(string $role, ServerRequestInterface $request)","user":{"login":"augusito","id":1794947,"node_id":"MDQ6VXNlcjE3OTQ5NDc=","avatar_url":"https://avatars2.githubusercontent.com/u/1794947?v=4","gravatar_id":"","url":"https://api.github.com/users/augusito","html_url":"https://github.com/augusito","followers_url":"https://api.github.com/users/augusito/followers","following_url":"https://api.github.com/users/augusito/following{/other_user}","gists_url":"https://api.github.com/users/augusito/gists{/gist_id}","starred_url":"https://api.github.com/users/augusito/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/augusito/subscriptions","organizations_url":"https://api.github.com/users/augusito/orgs","repos_url":"https://api.github.com/users/augusito/repos","events_url":"https://api.github.com/users/augusito/events{/privacy}","received_events_url":"https://api.github.com/users/augusito/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-04-27T01:03:05Z","updated_at":"2018-09-18T13:56:31Z","closed_at":"2018-09-18T13:56:31Z","author_association":"NONE","body":"Hey. I have a suggestion on the second argument of ZendAcl->isGranted(string $role, **ServerRequestInterface $request**). \r\nThe argument can be revised to make it more open. \r\nThis will allow the method to be used in various scenarios where we may not have **Psr\\Http\\Message\\ServerRequestInterface** instance, but may still want to pass a resource as either a **sting** or as an instance of **Zend\\Permissions\\Acl\\Resource\\ResourceInterface**. \r\nOne such scenario is where I may need to filter navigation items based on the permissions of a role and the resource is provided as a **string** or as an instance of **Zend\\Permissions\\Acl\\Resource\\ResourceInterface**. \r\nIn this case, I don't need to have **Psr\\Http\\Message\\ServerRequestInterface** instance or a **route name** for that matter.\r\nI suggest revision on the method as follows:\r\n\r\n\t/**\r\n     * Check if a role is granted for the resource\r\n     *\r\n     * @param string $role            \r\n     * @param string|\\Zend\\Permissions\\Acl\\Resource\\ResourceInterface|\\Psr\\Http\\Message\\ServerRequestInterface|null $resource            \r\n     * @return bool\r\n     */\r\n    public function isGranted(string $role, $resource): bool\r\n    {\r\n        if (null === $resource \r\n            || is_string($resource) \r\n                || $resource instanceof ResourceInterface) {\r\n            $this->resource = $resource;\r\n        } elseif ($resource instanceof ServerRequestInterface) {\r\n            $routeResult = $resource->getAttribute(RouteResult::class, false);\r\n            if (false === $routeResult) {\r\n                throw new Exception\\RuntimeException(sprintf(\r\n                    'The %s attribute is missing in the request; cannot perform ACL authorization checks', \r\n                    RouteResult::class\r\n                    ));\r\n            }\r\n            $this->resource = $routeResult->getMatchedRouteName();\r\n        } else {\r\n            throw new Exception\\InvalidArgumentException(sprintf(\r\n                'Invalid argument: $resource must be null, a string, an instance of %, or an instance of %', \r\n                ResourceInterface::class, ServerRequestInterface::class\r\n                ));\r\n        }\r\n        \r\n        return $this->acl->isAllowed($role, $this->resource);\r\n    }\r\n\r\nPS, The revision does not break usage by **\\Zend\\Expressive\\Authorization\\AuthorizationMiddleware**"},"comment":{"url":"https://api.github.com/repos/zendframework/zend-expressive-authorization-acl/issues/comments/422403145","html_url":"https://github.com/zendframework/zend-expressive-authorization-acl/issues/15#issuecomment-422403145","issue_url":"https://api.github.com/repos/zendframework/zend-expressive-authorization-acl/issues/15","id":422403145,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMjQwMzE0NQ==","user":{"login":"ezimuel","id":475967,"node_id":"MDQ6VXNlcjQ3NTk2Nw==","avatar_url":"https://avatars2.githubusercontent.com/u/475967?v=4","gravatar_id":"","url":"https://api.github.com/users/ezimuel","html_url":"https://github.com/ezimuel","followers_url":"https://api.github.com/users/ezimuel/followers","following_url":"https://api.github.com/users/ezimuel/following{/other_user}","gists_url":"https://api.github.com/users/ezimuel/gists{/gist_id}","starred_url":"https://api.github.com/users/ezimuel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ezimuel/subscriptions","organizations_url":"https://api.github.com/users/ezimuel/orgs","repos_url":"https://api.github.com/users/ezimuel/repos","events_url":"https://api.github.com/users/ezimuel/events{/privacy}","received_events_url":"https://api.github.com/users/ezimuel/received_events","type":"User","site_admin":false},"created_at":"2018-09-18T13:56:31Z","updated_at":"2018-09-18T13:56:31Z","author_association":"MEMBER","body":"We cannot provide this change because the ACL adapter needs to implement an [AuthorizationInterface](https://github.com/zendframework/zend-expressive-authorization/blob/master/src/AuthorizationInterface.php) that requires `ServerRequestInterface`.\r\n\r\nIf you need, you can implement a custom class for the authorization, passing the dependecies in the constructor (with a [Factory Service](https://zendframework.github.io/zend-servicemanager/configuring-the-service-manager/#factories)) and use it inside the `isGranted(string $role, ServerRequestInterface $request)`function."}}
{"actor":{"display_login":"ezimuel"}}