|
| 1 | +MxcRouteGuard |
| 2 | +============= |
| 3 | +Version 0.0.1 Created by Frank Hein and the maxence team |
| 4 | + |
| 5 | +Introduction |
| 6 | +------------ |
| 7 | + |
| 8 | +MxcRouteGuard restricts access to routes by unauthenticated users. |
| 9 | +Out of the box MxcRouteGuard works with ZfcUser, however, alternative authentication |
| 10 | +may be used as long as they provide a public function hasIdentity() returning bool. |
| 11 | +MxcRouteGuard is designed to be very simple. |
| 12 | + |
| 13 | +Requirements |
| 14 | +------------ |
| 15 | + |
| 16 | +* [Zend Framework 2](https://github.com/zendframework/zf2) (latest master) |
| 17 | + |
| 18 | +Features / Goals |
| 19 | +---------------- |
| 20 | + |
| 21 | +* Allow/Deny access to application routes globally for anonymous users |
| 22 | +* Support for ZfcUser Registration Feature (automatically whitelist if enabled) |
| 23 | +* Support for ZfcUser redirect feature |
| 24 | + |
| 25 | +Installation |
| 26 | +------------ |
| 27 | + |
| 28 | +### Main Setup |
| 29 | + |
| 30 | +#### By cloning project |
| 31 | + |
| 32 | +1. Clone this project into your `./vendor/` directory. |
| 33 | + |
| 34 | +#### With composer |
| 35 | + |
| 36 | +1. Add this project in your composer.json: |
| 37 | + |
| 38 | + ```json |
| 39 | + "require": { |
| 40 | + "mxc-commons/mxc-routeguard": "dev-master" |
| 41 | + } |
| 42 | + ``` |
| 43 | + |
| 44 | +2. Now tell composer to download MxcRouteGuard by running the command: |
| 45 | + |
| 46 | + ```bash |
| 47 | + $ php composer.phar update |
| 48 | + ``` |
| 49 | + |
| 50 | +#### Post installation |
| 51 | + |
| 52 | +1. Enabling it in your `application.config.php`file. |
| 53 | + |
| 54 | + ```php |
| 55 | + <?php |
| 56 | + return array( |
| 57 | + 'modules' => array( |
| 58 | + // ... |
| 59 | + 'MxcRouteGuard', |
| 60 | + ), |
| 61 | + // ... |
| 62 | + ); |
| 63 | + ``` |
| 64 | + |
| 65 | +Options |
| 66 | +------- |
| 67 | + |
| 68 | +The MxcRouteGuard module has some options to allow you to quickly customize the basic |
| 69 | +functionality. After installing MxcRouteGuard, copy |
| 70 | +`./vendor/maxence/MxcRouteGuard/config/mxcrouteguard.global.php.dist` to |
| 71 | +`./config/autoload/mxcrouteguard.global.php` and change the values as desired. |
| 72 | + |
| 73 | +The following options are available: |
| 74 | + |
| 75 | +- **auth_service** - Name of Authentication Service class to use. Useful for using your own |
| 76 | + authentication service instead of the default ZfcUser. Default is `zfcuser_auth_service`. |
| 77 | +- **guard_mode** - Two modes ('white', 'black') are provided to handle the observed routes list |
| 78 | + (see below). In whitelist mode all routes but the routes provided in the observed routes list |
| 79 | + are protected from anonymous access. In blacklist mode only the routes provided in the observed |
| 80 | + route list are protected from anonymous acceess. Default is 'white'. |
| 81 | +- **observed_routes** - List of routes to protect from anonymous success (black mode) or allow to |
| 82 | + anonymous access (white mode) |
| 83 | +- **anonymous_redirect** - If access gets blocked the anonymous user gets redirected to the route |
| 84 | + specified here. Note: The anonymous_redirect route automatically gets whitelisted regardless of |
| 85 | + the guard mode. Default: 'zfcuser/login' |
| 86 | +- **strategy** - By default MxcRouteGuard redirects attempts to access protected routes by an |
| 87 | + anonymous user. If you want something else but a redirect to happen you may supply an alternative |
| 88 | + strategy here to handle anonymous access. |
| 89 | + |
| 90 | +ZfcUser support |
| 91 | +--------------- |
| 92 | + |
| 93 | +If ZfcUser is used and the ZfcUser enable_registration flag is set true then MxcRouteGuard |
| 94 | +automatically whitelists 'zfcuser/register' regardless of the guard mode. |
| 95 | + |
| 96 | +In case a route gets blocked MxcRouteGuard applies a redirectto parameter to the anonymous_redirect |
| 97 | +route which can be used by ZfcUser, if the use_redirect_parameter_if_present setting is set true. |
| 98 | + |
| 99 | +Note |
| 100 | +---- |
| 101 | + |
| 102 | +For authenticated users MxcRouteGuard provides full access to all routes. If you need a more |
| 103 | +detailled control of who can access what route, use ZfcRbac or BjyAuthorize or similar modules |
| 104 | +instead of MxcRouteGuard. |
| 105 | + |
| 106 | +Common use cases for MxcRouteGuard are demo apps which only require a user to be known. |
0 commit comments