{"id":20103131,"url":"https://github.com/dotkernel/dot-rbac","last_synced_at":"2025-05-06T08:31:06.430Z","repository":{"id":11252317,"uuid":"68401285","full_name":"dotkernel/dot-rbac","owner":"dotkernel","description":"DotKernel RBAC implementation","archived":false,"fork":false,"pushed_at":"2025-03-14T15:14:50.000Z","size":185,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"3.0","last_synced_at":"2025-04-28T11:19:01.242Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://docs.dotkernel.org/dot-rbac/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dotkernel.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-16T17:38:56.000Z","updated_at":"2025-03-11T06:03:39.000Z","dependencies_parsed_at":"2024-04-11T19:55:44.243Z","dependency_job_id":"296b4f2a-3b6c-41eb-ab57-673834a0384b","html_url":"https://github.com/dotkernel/dot-rbac","commit_stats":{"total_commits":29,"total_committers":7,"mean_commits":4.142857142857143,"dds":0.4137931034482759,"last_synced_commit":"2237b358b612096731edbacf67bc417a2dab4c31"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotkernel%2Fdot-rbac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotkernel%2Fdot-rbac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotkernel%2Fdot-rbac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotkernel%2Fdot-rbac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dotkernel","download_url":"https://codeload.github.com/dotkernel/dot-rbac/tar.gz/refs/heads/3.0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252648511,"owners_count":21782401,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T17:34:23.782Z","updated_at":"2025-05-06T08:31:06.416Z","avatar_url":"https://github.com/dotkernel.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dot-rbac\n\nRbac authorization model implements [dot-authorization](https://github.com/dotkernel/dot-authorization)'s `AuthorizationInterface`. An authorization service is responsible for deciding if the authenticated identity or guest has access to certain parts of the application.\n\nThe RBAC model defines roles that can be assigned to users. The authorization is done on a role basis, not user basis as in ACL. Each role can have one or multiple permissions/privileges assigned. When deciding if a user is authorized, the requested permission is checked in all user roles and if at least one role has that permission, access is granted.\n\n## Documentation\n\nDocumentation is available at: https://docs.dotkernel.org/dot-rbac/.\n\n## Badges\n\n![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-rbac)\n![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-rbac/3.7.0)\n\n[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-rbac)](https://github.com/dotkernel/dot-rbac/issues)\n[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-rbac)](https://github.com/dotkernel/dot-rbac/network)\n[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-rbac)](https://github.com/dotkernel/dot-rbac/stargazers)\n[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-rbac)](https://github.com/dotkernel/dot-rbac/blob/3.0/LICENSE.md)\n\n[![Build Static](https://github.com/dotkernel/dot-rbac/actions/workflows/continuous-integration.yml/badge.svg?branch=3.0)](https://github.com/dotkernel/dot-rbac/actions/workflows/continuous-integration.yml)\n[![codecov](https://codecov.io/gh/dotkernel/dot-rbac/graph/badge.svg?token=GCK6C92N83)](https://codecov.io/gh/dotkernel/dot-rbac)\n[![PHPStan](https://github.com/dotkernel/dot-rbac/actions/workflows/static-analysis.yml/badge.svg?branch=3.0)](https://github.com/dotkernel/dot-rbac/actions/workflows/static-analysis.yml)\n\n## Installation\n\nRun the following command in your project root directory\n\n```bash\n$ composer require dotkernel/dot-rbac\n```\n\n## Configuration\n\nEven if the authorization service can be programmatically configured, we recommend using the configuration based approach. We further describe how to configure the module, using configuration file.\n\nFirst of all, you should enable the module in your application by merging this package's `ConfigProvider` with your application's config. This ensures that all dependencies required by this module are registered in the service manager. It also defines default config values for this module.\n\nCreate a configuration file in your `config/autoload` folder and change the module options as needed.\n\n### authorization.global.php\n\n```php\n'dot_authorization' =\u003e [\n    //name of the guest role to use if no identity is provided\n    'guest_role' =\u003e 'guest',\n    \n    'role_provider_manager' =\u003e [],\n    \n    //example for a flat RBAC model using the InMemoryRoleProvider\n    'role_provider' =\u003e [\n        'type' =\u003e 'InMemory',\n        'options' =\u003e [\n            'roles' =\u003e [\n                'admin' =\u003e [\n                    'permissions' =\u003e [\n                        'edit',\n                        'delete',\n                        //etc..\n                    ]\n                ],\n                'user' =\u003e [\n                    'permissions' =\u003e [\n                        //...\n                    ]\n                ]\n            ]\n        ],\n    ],\n    \n    //example for a hierarchical model, less to write but it can be confusing sometimes\n    /*'role_provider' =\u003e [\n        'type' =\u003e 'InMemory',\n        'options' =\u003e [\n            'roles' =\u003e [\n                'admin' =\u003e [\n                    'children' =\u003e ['user'],\n                    'permissions' =\u003e ['create', 'delete']\n                ],\n                'user' =\u003e [\n                    'children' =\u003e ['guest']\n                    'permissions' =\u003e ['edit']\n                ]\n                'guest' =\u003e [\n                    'permissions' =\u003e ['view']\n                ]\n            ]\n        ]\n    ],*/\n    \n    'assertion_manager' =\u003e [\n        'factories' =\u003e [\n            //EditAssertion::class =\u003e InvokableFactory::class,\n        ],\n    ],\n    \n    'assertions' =\u003e [\n        [\n            'type' =\u003e EditAssertion::class,\n            'permissions' =\u003e ['edit'],\n            'options' =\u003e []\n        ]\n    ]\n]\n```\n\n## Usage\n\nWhenever you need to check if someone is authorized to take some actions, inject the `AuthorizationInterface::class` service into your class, then call the `isGranted` method with the correct parameters. There are 2 ways to call the isGranted method.\n\n### First Method\n\nSpecify which roles you want to check.\n\n```php\n$isGranted = $this-\u003eauthorizationService-\u003eisGranted($permission, $roles);\n```\n\n### Second Method\n\nDo not specify the roles or send an empty array as the second parameter. This will check if the authenticated identity has permission.\n\n```php\n$isGranted = $this-\u003eauthorizationService-\u003eisGranted($permission);\n```\n\n## Customize the IdentityProvider\n\nWhenever you request an authorization check on the authenticated identity, the identity will be provided to the `AuthorizationService` through a registered `IdentityProviderInterface` service.\n\nThis is because identity is authentication dependent, so the module lets you overwrite this service, depending on your needs. If you want to get the identity from other sources instead of the dot-authentication service, just overwrite the `IdentityProviderInterface::class` service in the service manager with your own implementation of this interface.\n\n## Custom role providers\n\nWrite your own role provider by implementing the `RoleProviderInterface` and register it in the `RoleProviderPluginManager`. After that, you can use them in the configuration file, as described above.\n\n## Creating assertions\n\nAssertions are checked after permission granting, right before returning the authorization result. Assertions can have a last word in deciding if someone is authorized for the requested action. A good assertion example could be an edit permission, but with the restriction that it should be able to edit the item just if the `user id` matches the item's `owner id`. It is up to you to write the logic inside an assertion.\n\nAn assertion has to implement the `AssertionInterface` and be registered in the `AssertionPluginManager`.\n\nThis interface defines the following method\n\n```php\npublic function assert(AuthorizationInterface $authorization, $context = null);\n```\n\nThe context variable can be any external data that an assertion needs in order to decide the authorization status. The assertion must return a boolean value, reflecting the assertion pass or failure status.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotkernel%2Fdot-rbac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdotkernel%2Fdot-rbac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotkernel%2Fdot-rbac/lists"}