Skip to content

Commit 31d7053

Browse files
committed
Issue #26: Added support for laminas/laminas-servicemanager:4.x
Signed-off-by: alexmerlin <[email protected]>
1 parent 1bf7e94 commit 31d7053

20 files changed

+273
-58
lines changed

Diff for: .laminas-ci.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ignore_php_platform_requirements": {
3+
"8.4": true
4+
},
5+
"backwardCompatibilityCheck": true
6+
}

Diff for: README.md

+33-20
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,40 @@
11
# dot-rbac
22

3-
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.
3+
Rbac authorization model implements [dot-authorization](https://github.com/dotkernel/dot-authorization)'s `AuthorizationInterface`.
4+
An authorization service is responsible for deciding if the authenticated identity or guest has access to certain parts of the application.
45

5-
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.
6+
The RBAC model defines roles that can be assigned to users.
7+
The authorization is done on a role basis, not user basis as in ACL.
8+
Each role can have one or multiple permissions/privileges assigned.
9+
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.
610

711
![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-rbac)
8-
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-rbac/3.5.2)
12+
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-rbac/4.0.0)
913

1014
[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-rbac)](https://github.com/dotkernel/dot-rbac/issues)
1115
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-rbac)](https://github.com/dotkernel/dot-rbac/network)
1216
[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-rbac)](https://github.com/dotkernel/dot-rbac/stargazers)
13-
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-rbac)](https://github.com/dotkernel/dot-rbac/blob/3.0/LICENSE.md)
17+
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-rbac)](https://github.com/dotkernel/dot-rbac/blob/4.0/LICENSE.md)
1418

15-
[![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)
19+
[![Build Static](https://github.com/dotkernel/dot-rbac/actions/workflows/continuous-integration.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/dot-rbac/actions/workflows/continuous-integration.yml)
1620
[![codecov](https://codecov.io/gh/dotkernel/dot-rbac/graph/badge.svg?token=GCK6C92N83)](https://codecov.io/gh/dotkernel/dot-rbac)
1721

18-
[![SymfonyInsight](https://insight.symfony.com/projects/ce0cfbb2-7e97-427b-b394-531ff5be13d6/big.svg)](https://insight.symfony.com/projects/ce0cfbb2-7e97-427b-b394-531ff5be13d6)
19-
2022
## Installation
2123

22-
Run the following command in your project root directory
24+
Run the following command in your project root directory:
2325

24-
```bash
25-
$ composer require dotkernel/dot-rbac
26+
```shell
27+
composer require dotkernel/dot-rbac
2628
```
2729

2830
## Configuration
2931

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

32-
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.
35+
First of all, you should enable the module in your application by merging this package's `ConfigProvider` with your application's config.
36+
This ensures that all dependencies required by this module are registered in the service manager.
37+
It also defines default config values for this module.
3338

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

@@ -101,19 +106,21 @@ Create a configuration file in your `config/autoload` folder and change the modu
101106

102107
## Usage
103108

104-
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.
109+
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.
110+
There are 2 ways to call the isGranted method.
105111

106-
### First Method
112+
### First method
107113

108114
Specify which roles you want to check.
109115

110116
```php
111117
$isGranted = $this->authorizationService->isGranted($permission, $roles);
112118
```
113119

114-
### Second Method
120+
### Second method
115121

116-
Do not specify the roles or send an empty array as the second parameter. This will check if the authenticated identity has permission.
122+
Do not specify the roles or send an empty array as the second parameter.
123+
This will check if the authenticated identity has permission.
117124

118125
```php
119126
$isGranted = $this->authorizationService->isGranted($permission);
@@ -123,15 +130,20 @@ $isGranted = $this->authorizationService->isGranted($permission);
123130

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

126-
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.
133+
This is because identity is authentication dependent, so the module lets you overwrite this service, depending on your needs.
134+
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.
127135

128136
## Custom role providers
129137

130-
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.
138+
Write your own role provider by implementing the `RoleProviderInterface` and register it in the `RoleProviderPluginManager`.
139+
After that, you can use them in the configuration file, as described above.
131140

132141
## Creating assertions
133142

134-
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.
143+
Assertions are checked after permission granting, right before returning the authorization result.
144+
Assertions can have a last word in deciding if someone is authorized for the requested action.
145+
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`.
146+
It is up to you to write the logic inside an assertion.
135147

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

@@ -141,4 +153,5 @@ This interface defines the following method
141153
public function assert(AuthorizationInterface $authorization, $context = null);
142154
```
143155

144-
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.
156+
The context variable can be any external data that an assertion needs in order to decide the authorization status.
157+
The assertion must return a boolean value, reflecting the assertion pass or failure status.

Diff for: SECURITY.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
## Supported Versions
44

55

6-
| Version | Supported | PHP Version |
7-
|---------|--------------------|------------------------------------------------------------------------------------------------------------------|
8-
| 3.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-rbac/3.5.2) |
9-
| <= 2.x | :x: | |
6+
| Version | Supported | PHP Version |
7+
|---------|--------------------|----------------------------------------------------------------------------------------------------------|
8+
| 4.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-rbac/4.0.0) |
9+
| 3.x | :x: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-rbac/3.5.2) |
10+
| <= 2.x | :x: | |
1011

1112

1213
## Reporting Potential Security Issues

Diff for: authorization.global.php.dist

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
return [
46
'dot_authorization' => [
57
//name of the guest role to use if no identity is provided

Diff for: composer.json

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"name": "dotkernel/dot-rbac",
33
"type": "library",
4-
"description": "DotKernel RBAC authorization component",
4+
"description": "Dotkernel RBAC authorization component",
55
"license": "MIT",
66
"homepage": "https://github.com/dotkernel/dot-rbac",
77
"keywords": [
8+
"authorization",
89
"laminas",
9-
"mezzio",
1010
"rbac"
1111
],
1212
"authors": [
1313
{
14-
"name": "DotKernel Team",
14+
"name": "Dotkernel Team",
1515
"email": "[email protected]"
1616
}
1717
],
@@ -22,16 +22,16 @@
2222
}
2323
},
2424
"require": {
25-
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
26-
"laminas/laminas-servicemanager": "^3.11",
27-
"dotkernel/dot-authorization": "^3.4.1",
28-
"laminas/laminas-stdlib": "^3.7",
29-
"laminas/laminas-authentication": "2.16.0"
25+
"php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0",
26+
"dotkernel/dot-authorization": "^3.6.0",
27+
"laminas/laminas-authentication": "^2.16.0",
28+
"laminas/laminas-servicemanager": "^4.0",
29+
"laminas/laminas-stdlib": "^3.7"
3030
},
3131
"require-dev": {
32+
"laminas/laminas-coding-standard": "^3.0",
3233
"phpunit/phpunit": "^10.2",
33-
"vimeo/psalm": "^5.13",
34-
"laminas/laminas-coding-standard": "^2.5"
34+
"vimeo/psalm": "^5.13"
3535
},
3636
"autoload": {
3737
"psr-4": {
@@ -46,7 +46,8 @@
4646
"scripts": {
4747
"check": [
4848
"@cs-check",
49-
"@test"
49+
"@test",
50+
"@static-analysis"
5051
],
5152
"cs-check": "phpcs",
5253
"cs-fix": "phpcbf",

Diff for: docs/book/index.md

-1
This file was deleted.

Diff for: docs/book/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../README.md

Diff for: docs/book/v3/configuration.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
Even if the authorization service can be programmatically configured, we recommend using the configuration based approach.
44
We further describe how to configure the module, using the configuration file.
55

6-
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.
6+
First of all, you should enable the module in your application by merging this package's `ConfigProvider` with your application's config.
7+
This ensures that all dependencies required by this module are registered in the service manager.
8+
It also defines default config values for this module.
79

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

Diff for: docs/book/v3/customization.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@
44

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

7-
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.
7+
This is because identity is authentication dependent, so the module lets you overwrite this service, depending on your needs.
8+
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.
89

910
## Custom role providers
1011

11-
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.
12+
Write your own role provider by implementing the `RoleProviderInterface` and register it in the `RoleProviderPluginManager`.
13+
After that, you can use them in the configuration file, as described above.
1214

1315
## Creating assertions
1416

15-
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.
17+
Assertions are checked after permission granting, right before returning the authorization result.
18+
Assertions can have a last word in deciding if someone is authorized for the requested action.
19+
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`.
20+
It is up to you to write the logic inside an assertion.
1621

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

@@ -22,4 +27,5 @@ This interface defines the following method
2227
public function assert(AuthorizationInterface $authorization, $context = null);
2328
```
2429

25-
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.
30+
The context variable can be any external data that an assertion needs in order to decide the authorization status.
31+
The assertion must return a boolean value, reflecting the assertion pass or failure status.

Diff for: docs/book/v3/installation.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Installation
22

3-
Run the following command in your project root directory
3+
Run the following command in your project root directory:
44

5-
composer require dotkernel/dot-rbac
5+
```shell
6+
composer require dotkernel/dot-rbac
7+
```

Diff for: docs/book/v3/usage.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# Usage
22

3-
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.
3+
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.
4+
There are 2 ways to call the isGranted method.
45

5-
## First Method
6+
## First method
67

78
Specify which roles you want to check.
89

910
```php
1011
$isGranted = $this->authorizationService->isGranted($permission, $roles);
1112
```
1213

13-
## Second Method
14+
## Second method
1415

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

Diff for: docs/book/v4/configuration.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Configuration
2+
3+
Even if the authorization service can be programmatically configured, we recommend using the configuration based approach.
4+
We further describe how to configure the module, using the configuration file.
5+
6+
First of all, you should enable the module in your application by merging this package's `ConfigProvider` with your application's config.
7+
This ensures that all dependencies required by this module are registered in the service manager.
8+
It also defines default config values for this module.
9+
10+
Create a configuration file in your `config/autoload` folder and change the module options as needed.
11+
12+
## authorization.global.php
13+
14+
```php
15+
'dot_authorization' => [
16+
//name of the guest role to use if no identity is provided
17+
'guest_role' => 'guest',
18+
19+
'role_provider_manager' => [],
20+
21+
//example for a flat RBAC model using the InMemoryRoleProvider
22+
'role_provider' => [
23+
'type' => 'InMemory',
24+
'options' => [
25+
'roles' => [
26+
'admin' => [
27+
'permissions' => [
28+
'edit',
29+
'delete',
30+
//etc..
31+
]
32+
],
33+
'user' => [
34+
'permissions' => [
35+
//...
36+
]
37+
]
38+
]
39+
],
40+
],
41+
42+
//example for a hierarchical model, less to write but it can be confusing sometimes
43+
/*'role_provider' => [
44+
'type' => 'InMemory',
45+
'options' => [
46+
'roles' => [
47+
'admin' => [
48+
'children' => ['user'],
49+
'permissions' => ['create', 'delete']
50+
],
51+
'user' => [
52+
'children' => ['guest']
53+
'permissions' => ['edit']
54+
]
55+
'guest' => [
56+
'permissions' => ['view']
57+
]
58+
]
59+
]
60+
],*/
61+
62+
'assertion_manager' => [
63+
'factories' => [
64+
//EditAssertion::class => InvokableFactory::class,
65+
],
66+
],
67+
68+
'assertions' => [
69+
[
70+
'type' => EditAssertion::class,
71+
'permissions' => ['edit'],
72+
'options' => []
73+
]
74+
]
75+
]
76+
```

0 commit comments

Comments
 (0)