Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ jobs:
- ubuntu-latest

php:
- "8.1"
- "8.2"
- "8.3"
- "8.4"
- "8.5"

steps:
- name: Checkout
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ jobs:
- ubuntu-latest

php:
- "8.1"
- "8.2"
- "8.3"
- "8.4"
- "8.5"

steps:
- name: Checkout
Expand Down
45 changes: 30 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# dot-rbac

Rbac 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.
Rbac 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.

The 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.
The RBAC model defines roles that can be assigned to users.
The authorization is done on a role basis, not a 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.

## Documentation

Documentation is available at: https://docs.dotkernel.org/dot-rbac/.
Documentation is available at: https://docs.dotkernel.org/dot-rbac/v3/overview/.

## Badges

![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-rbac)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-rbac/3.7.0)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-rbac/3.8.0)

[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-rbac)](https://github.com/dotkernel/dot-rbac/issues)
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-rbac)](https://github.com/dotkernel/dot-rbac/network)
Expand All @@ -24,17 +28,20 @@ Documentation is available at: https://docs.dotkernel.org/dot-rbac/.

## Installation

Run the following command in your project root directory
Run the following command in your project root directory:

```bash
$ composer require dotkernel/dot-rbac
```

## Configuration

Even 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.
Even if the authorization service can be programmatically configured, we recommend using the configuration-based approach.
We further describe how to configure the module, using a configuration file.

First 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.
First, 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.

Create a configuration file in your `config/autoload` folder and change the module options as needed.

Expand Down Expand Up @@ -68,7 +75,7 @@ Create a configuration file in your `config/autoload` folder and change the modu
],
],

//example for a hierarchical model, less to write but it can be confusing sometimes
//example for a hierarchical model, less to write, but it can be confusing sometimes
/*'role_provider' => [
'type' => 'InMemory',
'options' => [
Expand Down Expand Up @@ -106,7 +113,8 @@ Create a configuration file in your `config/autoload` folder and change the modu

## Usage

Whenever 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.
Whenever 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 two ways to call the isGranted method.

### First Method

Expand All @@ -118,7 +126,8 @@ $isGranted = $this->authorizationService->isGranted($permission, $roles);

### Second Method

Do not specify the roles or send an empty array as the second parameter. This will check if the authenticated identity has permission.
Do not specify the roles or send an empty array as the second parameter.
This will check if the authenticated identity has permission.

```php
$isGranted = $this->authorizationService->isGranted($permission);
Expand All @@ -128,22 +137,28 @@ $isGranted = $this->authorizationService->isGranted($permission);

Whenever you request an authorization check on the authenticated identity, the identity will be provided to the `AuthorizationService` through a registered `IdentityProviderInterface` service.

This 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.
This 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, overwrite the `IdentityProviderInterface::class` service in the service manager with your own implementation of this interface.

## Custom role providers

Write 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.
Write 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.

## Creating assertions

Assertions 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.
Assertions are checked after permission is granted, right before returning the authorization result.
Assertions can have the 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.

An assertion has to implement the `AssertionInterface` and be registered in the `AssertionPluginManager`.

This interface defines the following method
This interface defines the following method:

```php
public function assert(AuthorizationInterface $authorization, $context = null);
```

The 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.
The context variable can be any external data that an assertion needs to decide the authorization status.
The assertion must return a boolean value, reflecting the assertion pass or failure status.
13 changes: 5 additions & 8 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

## Supported Versions


| Version | Supported | PHP Version |
|---------|--------------------|------------------------------------------------------------------------------------------------------------------|
| 3.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-rbac/3.5.2) |
| <= 2.x | :x: | |

| Version | Supported | PHP Version |
|---------|--------------------|----------------------------------------------------------------------------------------------------------|
| 3.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-rbac/3.8.0) |
| <= 2.x | :x: | |

## Reporting Potential Security Issues

Expand All @@ -24,10 +22,9 @@ When reporting issues, please provide the following information:
We request that you contact us via the email address above and give the
project contributors a chance to resolve the vulnerability and issue a new
release prior to any public exposure; this helps protect the project's
users, and provides them with a chance to upgrade and/or update in order to
users and provides them with a chance to upgrade and/or update to
protect their applications.


## Policy

If we verify a reported security vulnerability, our policy is:
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
}
},
"require": {
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"laminas/laminas-servicemanager": "^3.11",
"php": "~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0",
"laminas/laminas-servicemanager": "^3.11",
"dotkernel/dot-authorization": "^3.4.1",
"laminas/laminas-stdlib": "^3.7",
"laminas/laminas-authentication": "2.16.0"
"laminas/laminas-authentication": "2.19.0"
},
"require-dev": {
"laminas/laminas-coding-standard": "^3.0",
Expand All @@ -52,7 +52,7 @@
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"test": "phpunit --colors=always",
"static-analysis": "phpstan analyse --memory-limit 1G"
"static-analysis": "phpstan analyse --memory-limit 1G",
"test": "phpunit --colors=always"
}
}
1 change: 0 additions & 1 deletion docs/book/index.md

This file was deleted.

74 changes: 0 additions & 74 deletions docs/book/v3/configuration.md

This file was deleted.

25 changes: 0 additions & 25 deletions docs/book/v3/customization.md

This file was deleted.

5 changes: 0 additions & 5 deletions docs/book/v3/installation.md

This file was deleted.

17 changes: 0 additions & 17 deletions docs/book/v3/overview.md

This file was deleted.

19 changes: 0 additions & 19 deletions docs/book/v3/usage.md

This file was deleted.

19 changes: 0 additions & 19 deletions mkdocs.yml

This file was deleted.