Skip to content
This repository was archived by the owner on Jul 3, 2020. It is now read-only.

Commit 7344374

Browse files
authored
Merge pull request #346 from chukShirley/docs-grammar-readability-fixes
Make grammar and readability improvements to documentation
2 parents 2650f15 + 4e642e1 commit 7344374

File tree

8 files changed

+90
-90
lines changed

8 files changed

+90
-90
lines changed

docs/01. Introduction.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ In this part, the following questions will be answered:
1010

1111
## Why should I use an authorization module?
1212

13-
The authorization part of an application is an essential aspect to secure your application. While the authentication
13+
The authorization part of an application is an essential aspect of securing your application. While the authentication
1414
part tells you who is using your website, the authorization answers if the given identity has the permission to
1515
perform specific actions.
1616

@@ -30,20 +30,20 @@ The basic idea of Rbac is to use roles and permissions:
3030

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

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

3838

3939
## How can I integrate ZfcRbac into my application?
4040

4141
ZfcRbac offers multiple ways to protect your application:
4242

43-
* Using **Guards**: those classes act as "firewalls" that block access to routes and/or controllers. Guards are usually
43+
* Using **Guards**: these classes act as "firewalls" that block access to routes and/or controllers. Guards are usually
4444
configured using PHP arrays, and are executed early in the MVC dispatch process. Typically this happens right after
4545
the route has been matched.
46-
* Using **AuthorizationService**: a complementary method is to use the `AuthorizationService` and inject them into your
46+
* Using **AuthorizationService**: a complementary method is to use the `AuthorizationService` class and inject it into your
4747
service classes to protect them from unwanted access.
4848

4949
While it is advised to use both methods to make your application even more secure, this is completely optional and you

docs/02. Quick Start.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
In this section, you will learn:
44

5-
* How to setup the module
5+
* How to set up the module
66
* How to specify an identity provider
7-
* How to add simple role provider
7+
* How to add a simple role provider
88

99
Before starting the quick start, make sure you have properly installed the module by following the instructions in
1010
the README file.
1111

1212
## Specifying an identity provider
1313

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

1717
```php
1818
return [
@@ -27,12 +27,12 @@ return [
2727
```
2828
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.
2929

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

3333
## Adding a guard
3434

35-
A guard allows to block access to routes and/or controllers using a simple syntax. For instance, this configuration
35+
A guard allows your application to block access to routes and/or controllers using a simple syntax. For instance, this configuration
3636
grants access to any route that begins with `admin` (or is exactly `admin`) to the `admin` role only:
3737

3838
```php
@@ -47,15 +47,15 @@ return [
4747
];
4848
```
4949

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

5353
## Adding a role provider
5454

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

58-
This configuration creates an *admin* role that has a children role called *member*. The *admin* role automatically
58+
This configuration creates an *admin* role that has a child role called *member*. The *admin* role automatically
5959
inherits the *member* permissions.
6060

6161
```php
@@ -76,10 +76,10 @@ return [
7676
];
7777
```
7878

79-
In this example, the *admin* role have two permissions: `delete` and `edit` (because it inherits the permissions from
80-
its child), while the *member* role only has the permission `edit`.
79+
In this example, the *admin* role has two permissions: `delete` and `edit` (because it inherits the permissions from
80+
its child), while the *member* role only has the `edit` permission.
8181

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

8585
## Registering a strategy
@@ -101,16 +101,16 @@ public function onBootstrap(EventInterface $e)
101101
}
102102
```
103103

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

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

111111
## Using the authorization service
112112

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

116116
The authorization service is registered inside the service manager using the following key: `ZfcRbac\Service\AuthorizationService`.

docs/03. Role providers.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ A role provider is an object that returns a list of roles. Each role provider mu
1313
`ZfcRbac\Role\RoleProviderInterface` interface. The only required method is `getRoles`, and must return an array
1414
of `Rbac\Role\RoleInterface` objects.
1515

16-
Roles can come from any sources: in memory, from a file, from a database... However, please note that since ZfcRbac
17-
2.0, you can specify only one role provider per application. The reason is that having multiple role providers make
16+
Roles can come from one of many sources: in memory, from a file, from a database... However, please note that since ZfcRbac
17+
2.0, you can specify only one role provider per application. The reason is that having multiple role providers makes
1818
the workflow harder and can lead to security problems that are very hard to spot.
1919

2020
## Identity providers?
2121

22-
Identity providers return the current identity. Most of the time, this means the logged user. ZfcRbac comes with a
22+
Identity providers return the current identity. Most of the time, this means the logged in user. ZfcRbac comes with a
2323
default identity provider (`ZfcRbac\Identity\AuthenticationIdentityProvider`) that uses the
2424
`Zend\Authentication\AuthenticationService` service.
2525

@@ -83,7 +83,7 @@ return [
8383
];
8484
```
8585

86-
The `children` and `permissions` subkeys are entirely optionals. Internally, the `InMemoryRoleProvider` creates
86+
The `children` and `permissions` subkeys are entirely optional. Internally, the `InMemoryRoleProvider` creates
8787
either a `Rbac\Role\Role` object if the role does not have any children, or a `Rbac\Role\HierarchicalRole` if
8888
the role has at least one child.
8989

@@ -162,7 +162,7 @@ Please note that your entity fetched from the table MUST implement the `Rbac\Rol
162162

163163
## Creating custom role providers
164164

165-
To create a custom role providers, you first need to create a class that implements the `ZfcRbac\Role\RoleProviderInterface`
165+
To create a custom role provider, you first need to create a class that implements the `ZfcRbac\Role\RoleProviderInterface`
166166
interface.
167167

168168
Then, you need to add it to the role provider manager:

docs/04. Guards.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
In this section, you will learn:
44

5-
* What are guards
5+
* What guards are
66
* How to use and configure built-in guards
77
* How to create custom guards
88

9-
## What are guards and when to use them?
9+
## What are guards and when should you use them?
1010

1111
Guards (called firewalls in older versions of ZfcRbac) are listeners that are registered on a specific event of
12-
the MVC workflow. They allow to quickly unauthorized requests.
12+
the MVC workflow. They allow your application to quickly mark a request as unauthorized.
1313

1414
Here is a simple workflow without guards:
1515

@@ -27,14 +27,14 @@ If you want to protect a route for a set of permissions, you must use RoutePermi
2727
you may want to grant access to a route "post/delete" only to roles having the "delete" permission.
2828
Note that in a RBAC system, a permission is linked to a role, not to a user.
2929

30-
Albeit simple to use, guards should not be the only protection in your application, and you should always also
31-
protect your service. The reason is that your business logic should be handled by your service. Protecting a given
30+
Albeit simple to use, guards should not be the only protection in your application, and you should always
31+
protect your services as well. The reason is that your business logic should be handled by your service. Protecting a given
3232
route or controller does not mean that the service cannot be access from elsewhere (another action for instance).
3333

3434
### Protection policy
3535

36-
By default, when a guard is added, it will perform check only on the specified guard rules. Any route or controller
37-
that are not specified in the rules will be "granted" by default. Therefore, the default is a "blacklist"
36+
By default, when a guard is added, it will perform a check only on the specified guard rules. Any route or controller
37+
that is not specified in the rules will be "granted" by default. Therefore, the default is a "blacklist"
3838
mechanism.
3939

4040
However, you may want a more restrictive approach (also called "whitelist"). In this mode, once a guard is added,
@@ -87,15 +87,15 @@ more rules in another module. All the rules will be automatically merged.
8787
you decide to use both conjointly, I recommend you to set the protection policy to "allow" (otherwise, you will
8888
need to define rules for every routes AND every controller, which can become quite frustrating!).
8989

90-
Please note that if your application use both route and controller guards, route guards are always executed
90+
Please note that if your application uses both route and controller guards, route guards are always executed
9191
**before** controller guards (they have a higher priority).
9292

9393
### RouteGuard
9494

9595
> The RouteGuard listens to the `MvcEvent::EVENT_ROUTE` event with a priority of -5.
9696
97-
The RouteGuard allows to protect a route or a hierarchy of route. You must provide an array of "key" => "value",
98-
where the key is a route pattern, and value an array of role names:
97+
The RouteGuard allows your application to protect a route or a hierarchy of routes. You must provide an array of "key" => "value",
98+
where the key is a route pattern and the value is an array of role names:
9999

100100
```php
101101
return [
@@ -110,7 +110,7 @@ return [
110110
];
111111
```
112112

113-
> Only one role in a rule need to be matched (it is an OR condition).
113+
> Only one role in a rule needs to be matched (it is an OR condition).
114114
115115
Those rules grant access to all admin routes to users that have the "admin" role, and grant access to the "login"
116116
route to users that have the "guest" role (eg.: most likely unauthenticated users).
@@ -168,8 +168,8 @@ return [
168168

169169
> The RoutePermissionsGuard listens to the `MvcEvent::EVENT_ROUTE` event with a priority of -8.
170170
171-
The RoutePermissionsGuard allows to protect a route or a hierarchy of route. You must provide an array of "key" => "value",
172-
where the key is a route pattern, and value an array of permissions names:
171+
The RoutePermissionsGuard allows your application to protect a route or a hierarchy of routes. You must provide an array of "key" => "value",
172+
where the key is a route pattern and the value is an array of permission names:
173173

174174
```php
175175
return [
@@ -243,14 +243,14 @@ return [
243243
];
244244
```
245245

246-
This rule will be inaccessible.
246+
This route will be inaccessible.
247247

248248

249249
### ControllerGuard
250250

251251
> The ControllerGuard listens to the `MvcEvent::EVENT_ROUTE` event with a priority of -10.
252252
253-
The ControllerGuard allows to protect a controller. You must provide an array of array:
253+
The ControllerGuard allows your application to protect a controller. You must provide an array of arrays:
254254

255255
```php
256256
return [
@@ -292,7 +292,7 @@ return [
292292
];
293293
```
294294

295-
You can combine a generic rule and a specific action rule for the same controller, as follow:
295+
You can combine a generic rule and a specific action rule for the same controller, as follows:
296296

297297
```php
298298
return [
@@ -314,14 +314,14 @@ return [
314314
];
315315
```
316316

317-
Those rules grant access to each actions of the controller to users that have the "member" role, but restrict the
317+
These rules grant access to each controller action to users that have the "member" role, but restrict the
318318
"delete" action to "admin" only.
319319

320320
### ControllerPermissionsGuard
321321

322322
> The ControllerPermissionsGuard listens to the `MvcEvent::EVENT_ROUTE` event with a priority of -13.
323323
324-
The ControllerPermissionsGuard allows to protect a controller using permissions. You must provide an array of array:
324+
The ControllerPermissionsGuard allows your application to protect a controller using permissions. You must provide an array of arrays:
325325

326326
```php
327327
return [
@@ -341,7 +341,7 @@ return [
341341
> All permissions in a rule must be matched (it is an AND condition).
342342
343343
In the previous example, the user must have ```post.update``` **AND** ```post.delete``` permissions
344-
to access each actions of the MyController controller.
344+
to access each action of the MyController controller.
345345

346346
As for all other guards, you can use a wildcard (*) character for permissions.
347347

@@ -350,15 +350,15 @@ The configuration rules are the same as for ControllerGuard.
350350
### Security notice
351351

352352
RouteGuard and ControllerGuard listen to the `MvcEvent::EVENT_ROUTE` event. Therefore, if you use the
353-
`forward` method into your controller, those guards will not intercept and check requests (because internally
353+
`forward` method in your controller, those guards will not intercept and check requests (because internally
354354
ZF2 does not trigger again a new MVC loop).
355355

356356
Most of the time, this is not an issue, but you must be aware of it, and this is an additional reason why you
357357
should always protect your services too.
358358

359359
## Creating custom guards
360360

361-
ZfcRbac is flexible enough to allow you to create custom guard. Let's say we want to create a guard that will
361+
ZfcRbac is flexible enough to allow you to create custom guards. Let's say we want to create a guard that will
362362
refuse access based on an IP addresses blacklist.
363363

364364
First create the guard:
@@ -412,9 +412,9 @@ By default, guards are listening to the event `MvcEvent::EVENT_ROUTE` with a pri
412412
event to listen by overriding the `EVENT_NAME` constant in your guard subclass). However, in this case, we don't
413413
even need to wait for the route to be matched, so we overload the `EVENT_PRIORITY` constant to be executed earlier.
414414

415-
The `isGranted` method simply retrieves the client IP address, and check it against the blacklist.
415+
The `isGranted` method simply retrieves the client IP address, and checks it against the blacklist.
416416

417-
However, for this to work, we must register the newly created guard to the guard plugin manager. To do so, add the
417+
However, for this to work, we must register the newly created guard with the guard plugin manager. To do so, add the
418418
following code in your config:
419419

420420
```php
@@ -429,7 +429,7 @@ return [
429429
];
430430
```
431431

432-
The `guard_manager` config follows a conventional service manager config format.
432+
The `guard_manager` config follows a conventional service manager configuration format.
433433

434434
Now, let's create the factory:
435435

@@ -467,9 +467,9 @@ class IpGuardFactory implements FactoryInterface, MutableCreationOptionsInterfac
467467
```
468468

469469
The `MutableCreationOptionsInterface` was introduced in Zend Framework 2.2, and allows your factories to accept
470-
options. In fact, in a real use case, you would likely fetched the blacklist from database.
470+
options. In fact, in a real use case, you would likely fetched the blacklist from a database.
471471

472-
Now, we just need to add the guard to the `guards` option, so that ZfcRbac execute the logic behind this guard. In
472+
Now we just need to add the guard to the `guards` option, so that ZfcRbac can execute the logic behind this guard. In
473473
your config, add the following code:
474474

475475
```php

docs/05. Strategies.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
In this section, you will learn:
44

5-
* What are strategies
5+
* What strategies are
66
* How to use built-in strategies
7-
* Creating custom strategies
7+
* How to create custom strategies
88

99
## What are strategies?
1010

1111
A strategy is an object that listens to the `MvcEvent::EVENT_DISPATCH_ERROR` event. It is used to describe what
12-
happens when an access to a resource is unauthorized by ZfcRbac.
12+
happens when access to a resource is unauthorized by ZfcRbac.
1313

1414
ZfcRbac strategies all check if an `ZfcRbac\Exception\UnauthorizedExceptionInterface` has been thrown.
1515

@@ -33,10 +33,10 @@ ZfcRbac comes with two built-in strategies: `RedirectStrategy` and `Unauthorized
3333

3434
### RedirectStrategy
3535

36-
This strategy allows to redirect any unauthorized request to another route, by optionally appending the previous
37-
URL as a query param.
36+
This strategy allows your application to redirect any unauthorized request to another route by optionally appending the previous
37+
URL as a query parameter.
3838

39-
To register it, copy-paste this code in your Module.php class:
39+
To register it, copy-paste this code into your Module.php class:
4040

4141
```php
4242
public function onBootstrap(EventInterface $e)
@@ -65,17 +65,17 @@ return [
6565
];
6666
```
6767

68-
If a user tries to access to an unauthorized resource (eg.: http://www.example.com/delete), he/she will be
69-
redirect to the "login" route if is not connected and to the "home" route otherwise (it must exists in your route config,
68+
If users try to access an unauthorized resource (eg.: http://www.example.com/delete), they will be
69+
redirected to the "login" route if is not connected and to the "home" route otherwise (it must exist in your route configuration
7070
of course) with the previous URL appended : http://www.example.com/login?redirectTo=http://www.example.com/delete
7171

7272
You can prevent redirection when a user is connected (i.e. so that the user gets a 403 page) by setting `redirect_when_connected` to `false`.
7373

7474
### UnauthorizedStrategy
7575

76-
This strategy allows to render a template on any unauthorized request.
76+
This strategy allows your application to render a template on any unauthorized request.
7777

78-
To register it, copy-paste this code in your Module.php class:
78+
To register it, copy-paste this code into your Module.php class:
7979

8080
```php
8181
public function onBootstrap(EventInterface $e)

0 commit comments

Comments
 (0)