Skip to content

Commit

Permalink
Merge pull request #12 from basz/laminas-commons-migration
Browse files Browse the repository at this point in the history
Laminas commons migration
  • Loading branch information
basz authored Jul 2, 2020
2 parents 3bd3fdb + e7d086d commit 63a3d7a
Show file tree
Hide file tree
Showing 74 changed files with 457 additions and 444 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# CHANGELOG

For changelog, please refer to the [releases](https://github.com/ZF-Commons/ZfcRbac/releases) page.
For changelog, please refer to the [releases](https://github.com/Laminas-Commons/LmcRbac/releases) page.
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
# ZfcRbac
# LmcRbac

[![Develop Branch Build Status](https://travis-ci.org/ZF-Commons/zfc-rbac.svg?branch=develop)](http://travis-ci.org/ZF-Commons/zfc-rbac)
[![Coverage Status](https://coveralls.io/repos/github/ZF-Commons/zfc-rbac/badge.svg?branch=develop)](https://coveralls.io/github/ZF-Commons/zfc-rbac?branch=develop)
[![Latest Stable Version](https://poser.pugx.org/zf-commons/zfc-rbac/v/stable)](https://packagist.org/packages/zf-commons/zfc-rbac)
[![Total Downloads](https://poser.pugx.org/zf-commons/zfc-rbac/downloads)](https://packagist.org/packages/zf-commons/zfc-rbac)
[![Latest Unstable Version](https://poser.pugx.org/zf-commons/zfc-rbac/v/unstable)](https://packagist.org/packages/zf-commons/zfc-rbac)
[![License](https://poser.pugx.org/zf-commons/zfc-rbac/license)](https://packagist.org/packages/zf-commons/zfc-rbac)
[![Join the chat at https://gitter.im/ZFCommons/zfc-rbac](https://badges.gitter.im/ZFCommons/zfc-rbac.svg)](https://gitter.im/ZFCommons/zfc-rbac?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Version](https://poser.pugx.org/laminas-commons/lmc-rbac/version)](//packagist.org/packages/laminas-commons/lmc-rbac)
[![Total Downloads](https://poser.pugx.org/laminas-commons/lmc-rbac/downloads)](//packagist.org/packages/laminas-commons/lmc-rbac)
[![License](https://poser.pugx.org/laminas-commons/lmc-rbac/license)](//packagist.org/packages/laminas-commons/lmc-rbac)
[![Master Branch Build Status](https://travis-ci.org/Laminas-Commons/LmcRbac.svg?branch=master)](http://travis-ci.org/Laminas-Commons/LmcRbac)
[![Gitter](https://badges.gitter.im/LaminasCommons/community.svg)](https://gitter.im/LaminasCommons/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![Coverage Status](https://coveralls.io/repos/github/Laminas-Commons/LmcRbac/badge.svg?branch=master)](https://coveralls.io/github/Laminas-Commons/LmcRbac?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Laminas-Commons/LmcRbac/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Laminas-Commons/LmcRbac/?branch=master)

ZfcRbac is an access control library based on the RBAC permission model.
Role-based access control module to provide additional features on top of Zend\Permissions\Rbac

**Work In Progress**; *you are looking at the next version, for stable visit the master branch.*
Based on [ZF-Commons/zfc-rbac](https://github.com/ZF-Commons/zfc-rbac) v3.x. If you are looking for the Laminas version
of zfc-rbac v2, please use [Laminas-Commons/LmcRbacMvc](https://github.com/Laminas-Commons/LmcRbacMvc).

## Requirements
**Work In Progress**

- PHP 7.1 or higher
## Requirements

> If you are looking for older version of ZfcRbac, please refer to the 2.x branch.
> If you are using ZfcRbac 2.0, please upgrade to 3.0.
- PHP 7.2 or higher

## Optional

- [DoctrineModule](https://github.com/doctrine/DoctrineModule): if you want to use some built-in role and permission providers.
- [ZendDeveloperTools](https://github.com/zendframework/ZendDeveloperTools): if you want to have useful stats added to
- [Laminas\DeveloperTools](https://github.com/zendframework/Laminas\DeveloperTools): if you want to have useful stats added to
the Zend Developer toolbar.

## Upgrade

You can find an [upgrade guide](UPGRADE.md) to quickly upgrade your application from major versions of ZfcRbac.
You can find an [upgrade guide](UPGRADE.md) to quickly upgrade your application from major versions of LmcRbac.

## Installation

ZfcRbac only officially supports installation through Composer. For Composer documentation, please refer to
LmcRbac only officially supports installation through Composer. For Composer documentation, please refer to
[getcomposer.org](http://getcomposer.org/).

Install the module:

```sh
$ php composer.phar require zf-commons/zfc-rbac:^3.0
$ php composer.phar require laminas-commons/lmc-rbac:^1.0
```

Enable the module by adding `ZfcRbac` key to your `application.config.php` file. Customize the module by copy-pasting
the `zfc_rbac.global.php.dist` file to your `config/autoload` folder.
Enable the module by adding `LmcRbac` key to your `application.config.php` file. Customize the module by copy-pasting
the `lmc_rbac.global.php.dist` file to your `config/autoload` folder.

## Documentation

The official documentation is available in the [/docs](docs/) folder.

You can also find some Doctrine entities in the [/data](data/) folder that will help you to more quickly take advantage
of ZfcRbac.
of LmcRbac.

## Support

- File issues at https://github.com/ZF-Commons/zfc-rbac/issues.
- Ask questions in the [zf-common gitter](https://gitter.im/ZFCommons/zfc-rbac) chat.
- File issues at https://github.com/Laminas-Commons/LmcRbac/issues.
- Ask questions in the [LaminasCommons gitter](https://gitter.im/LaminasCommons/community) chat.
16 changes: 15 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
# Upgrade guide

## From ZfcRbac v3 to LmcRbac v1

The ZF-Commons orgnisation has been moved to Laminas-Commons and ZfcRbac has been split into two repositories.

- [LmcRbacMvc](https://github.com/Laminas-Commons/LmcRbacMvc) contains the old version 2 of ZfcRbac.
- LmcRbac contains the version 3 of ZfcRbac, which was only released as v3.alpha.1.

To upgrade

- Uninstall `zf-commons/zfc-rbac:3.0.0-alpha.1`.
- Install `laminas-commons/lmc-rbac:^1.0`
- Change `zfc-rbac.global.php` to `lmc-rbac.global.php` and update the key `zfc_rbac` to `lmc_rbac`.
- Review your code for usages of the `ZfcRbac/*` namespace to `LmcRbac/*` namespace.

## From v2.x to v3

- ZfcRbac is no longer a ZF2 module. Instead, it fully embraces middlewares and can be used for any middleware
library like Zend\Expressive. As a consequence, its scope has been dramatically reduced and now only provide
library like Mezzio. As a consequence, its scope has been dramatically reduced and now only provide
the base logic for authorization.

## From v2.2 to v2.3
Expand Down
23 changes: 11 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "zf-commons/zfc-rbac",
"description": "Zend Framework 2 Module that provides a layer of features of Zend\\Permissions\\Rbac",
"name": "laminas-commons/lmc-rbac",
"description": "Laminas Module that provides a layer of features of Laminas\\Permissions\\Rbac",
"type": "library",
"license": "MIT",
"keywords": [
"module",
"zf2",
"laminas",
"rbac",
"permissions"
],
Expand Down Expand Up @@ -36,8 +36,8 @@
],
"require": {
"php": "^7.2",
"zendframework/zend-servicemanager": "^3.3",
"zendframework/zend-stdlib": "^3.1"
"laminas/laminas-servicemanager": "^3.3",
"laminas/laminas-stdlib": "^3.1"
},
"require-dev": {
"malukenho/docheader": "^0.1.7",
Expand All @@ -49,22 +49,21 @@
},
"autoload": {
"psr-4": {
"ZfcRbac\\": "src/"
"LmcRbac\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"ZfcRbacTest\\": "test/"
"LmcRbacTest\\": "test/"
}
},
"extra": {
"branch-alias": {
"dev-master": "2.4-dev",
"dev-develop": "3.0-dev"
"dev-master": "1.1-dev"
},
"zf": {
"component": "ZfcRbac",
"config-provider": "ZfcRbac\\ConfigProvider"
"laminas": {
"component": "LmcRbac",
"config-provider": "LmcRbac\\ConfigProvider"
}
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions config/config.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

return [
'zfc_rbac' => [
'lmc_rbac' => [

/**
* Set the guest role
Expand All @@ -38,7 +38,7 @@
* It must be an array that contains configuration for the role provider. The provider config
* must follow the following format:
*
* 'ZfcRbac\Role\InMemoryRoleProvider' => [
* 'LmcRbac\Role\InMemoryRoleProvider' => [
* 'role1' => [
* 'children' => ['children1', 'children2'], // OPTIONAL
* 'permissions' => ['edit', 'read'] // OPTIONAL
Expand Down
2 changes: 1 addition & 1 deletion data/FlatRole.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Rbac\Role\RoleInterface;
use ZfcRbac\Permission\PermissionInterface;
use LmcRbac\Permission\PermissionInterface;

/**
* @ORM\Entity
Expand Down
2 changes: 1 addition & 1 deletion data/HierarchicalRole.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Rbac\Role\HierarchicalRoleInterface;
use ZfcRbac\Permission\PermissionInterface;
use LmcRbac\Permission\PermissionInterface;

/**
* @ORM\Entity
Expand Down
2 changes: 1 addition & 1 deletion data/Permission.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

use Doctrine\ORM\Mapping as ORM;
use ZfcRbac\Permission\PermissionInterface;
use LmcRbac\Permission\PermissionInterface;

/**
* @ORM\Entity
Expand Down
2 changes: 1 addition & 1 deletion data/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
These files are only provided as-in, and are not part of ZfcRbac. They provide you some basic Doctrine ORM
These files are only provided as-in, and are not part of LmcRbac. They provide you some basic Doctrine ORM
entities that you can use as a starting point.

## Flat role or hierarchical role?
Expand Down
10 changes: 5 additions & 5 deletions docs/01. Introduction.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Introduction

Welcome to the official documentation of ZfcRbac!
Welcome to the official documentation of LmcRbac!

In this part, the following questions will be answered:

* Why should I use an authorization module?
* What is the Rbac model?
* How can I integrate ZfcRbac into my application?
* How can I integrate LmcRbac into my application?

## Why should I use an authorization module?

Expand All @@ -28,17 +28,17 @@ The basic idea of Rbac is to use roles and permissions:
* **Roles** request access to **Permissions**
* **Permissions** are granted to **Roles**

By default, ZfcRbac can be used for two kinds of Rbac model:
By default, LmcRbac can be used for two kinds of Rbac model:

* Flat RBAC model: in this model, roles cannot have children. This is ideal for smaller application, as it is easier
to understand, and the database design is simpler (no need for a join table).
* Hierarchical RBAC model: in this model, roles can have children roles. When evaluating if a given role has a
permission, this model also checks recursively if any of its child roles also have the permission.


## How can I integrate ZfcRbac into my application?
## How can I integrate LmcRbac into my application?

ZfcRbac offers multiple ways to protect your application:
LmcRbac offers multiple ways to protect your application:

* Using **Guards**: those classes act as "firewalls" that block access to routes and/or controllers. Guards are usually
configured using PHP arrays, and are executed early in the MVC dispatch process. Typically this happens right after
Expand Down
38 changes: 19 additions & 19 deletions docs/02. Quick Start.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ the README file.

## Specifying an identity provider

By default, ZfcRbac internally uses the `Zend\Authentication\AuthenticationService` service key to retrieve the user (logged or
By default, LmcRbac internally uses the `Laminas\Authentication\AuthenticationService` service key to retrieve the user (logged or
not). Therefore, you must implement and register this service in your application by adding those lines in your `module.config.php` file:

```php
return [
'service_manager' => [
'factories' => [
'Zend\Authentication\AuthenticationService' => function($sm) {
'Laminas\Authentication\AuthenticationService' => function($sm) {
// Create your authentication service!
}
]
]
];
```
The identity given by `Zend\Authentication\AuthenticationService` must implement `ZfcRbac\Identity\IdentityInterface`. Note that the default identity provided with ZF2 does not implement this interface, neither does the ZfcUser suite.
The identity given by `Laminas\Authentication\AuthenticationService` must implement `LmcRbac\Identity\IdentityInterface`. Note that the default identity provided with ZF2 does not implement this interface, neither does the ZfcUser suite.

ZfcRbac is flexible enough to use something else than the built-in `AuthenticationService`, by specifying custom
LmcRbac is flexible enough to use something else than the built-in `AuthenticationService`, by specifying custom
identity providers. For more information, refer [to this section](/docs/03. Role providers.md#identity-providers).

## Adding a guard
Expand All @@ -37,32 +37,32 @@ grants access to any route that begins with `admin` (or is exactly `admin`) to t

```php
return [
'zfc_rbac' => [
'lmc_rbac' => [
'guards' => [
'ZfcRbac\Guard\RouteGuard' => [
'LmcRbac\Guard\RouteGuard' => [
'admin*' => ['admin']
]
]
]
];
```

ZfcRbac have several built-in guards, and you can also register your own guards. For more information, refer
LmcRbac have several built-in guards, and you can also register your own guards. For more information, refer
[to this section](/docs/04. Guards.md#built-in-guards).

## Adding a role provider

RBAC model is based on roles. Therefore, for ZfcRbac to work properly, it must be aware of all the roles that are
RBAC model is based on roles. Therefore, for LmcRbac to work properly, it must be aware of all the roles that are
used inside your application.

This configuration creates an *admin* role that has a children role called *member*. The *admin* role automatically
inherits the *member* permissions.

```php
return [
'zfc_rbac' => [
'lmc_rbac' => [
'role_provider' => [
\ZfcRbac\Role\InMemoryRoleProvider::class => [
\LmcRbac\Role\InMemoryRoleProvider::class => [
'admin' => [
'children' => ['member'],
'permissions' => ['delete']
Expand All @@ -79,15 +79,15 @@ return [
In this example, the *admin* role have two permissions: `delete` and `edit` (because it inherits the permissions from
its child), while the *member* role only has the permission `edit`.

ZfcRbac have several built-in role providers, and you can also register your own role providers. For more information,
LmcRbac have several built-in role providers, and you can also register your own role providers. For more information,
refer [to this section](/docs/03. Role providers.md#built-in-role-providers).

## Registering a strategy

When a guard blocks access to a route/controller, or if you throw the `ZfcRbac\Exception\UnauthorizedException`
exception in your service, ZfcRbac automatically performs some logic for you depending on the view strategy used.
When a guard blocks access to a route/controller, or if you throw the `LmcRbac\Exception\UnauthorizedException`
exception in your service, LmcRbac automatically performs some logic for you depending on the view strategy used.

For instance, if you want ZfcRbac to automatically redirect all unauthorized requests to the "login" route, add
For instance, if you want LmcRbac to automatically redirect all unauthorized requests to the "login" route, add
the following code in the `onBootstrap` method of your `Module.php` class:

```php
Expand All @@ -96,28 +96,28 @@ public function onBootstrap(EventInterface $e)
$t = $e->getTarget();

$t->getEventManager()->attach(
$t->getServiceManager()->get('ZfcRbac\View\Strategy\RedirectStrategy')
$t->getServiceManager()->get('LmcRbac\View\Strategy\RedirectStrategy')
);
}
```

By default, `RedirectStrategy` redirects all unauthorized requests to a route named "login" when user is not connected
and to a route named "home" when user is connected. This is, of course, entirely configurable.

> For flexibility purpose, ZfcRbac **does not** register any strategy for you by default!
> For flexibility purpose, LmcRbac **does not** register any strategy for you by default!
For more information about built-in strategies, refer [to this section](/docs/05. Strategies.md#built-in-strategies).

## Using the authorization service

Now that ZfcRbac is properly configured, you can inject the authorization service in any class and use it to check
Now that LmcRbac is properly configured, you can inject the authorization service in any class and use it to check
if the current identity is granted to do something.

The authorization service is registered inside the service manager using the following key: `ZfcRbac\Service\AuthorizationService`.
The authorization service is registered inside the service manager using the following key: `LmcRbac\Service\AuthorizationService`.
Once injected, you can use it as follow:

```php
use ZfcRbac\Exception\UnauthorizedException;
use LmcRbac\Exception\UnauthorizedException;

public function delete()
{
Expand Down
Loading

0 comments on commit 63a3d7a

Please sign in to comment.