mxc-commons
Zend Framework 2 Module that provides protection for routes from anonymous access.
Version 1.0.1 created by Frank Hein and the mxc-commons team.
MxcRouteGuard is part of the maxence Open Source Initiative by by maxence business consulting gmbh, Germany.
MxcRouteGuard restricts access to routes for unauthenticated users. Out of the box MxcRouteGuard works with ZfcUser, however, alternative authentication services
(such as Zend\Authentication\AuthenticationService
) may be used as long as they provide a public function hasIdentity()
returning bool
. MxcRouteGuard is
designed to be very simple and reasonably extendable.
./vendor/
directory.Add this project in your composer.json:
"require": {
"mxc-commons/mxc-routeguard": "dev-master"
}
Now tell composer to download MxcRouteGuard by running the command:
$ php composer.phar update
Enabling it in your application.config.php
file.
<?php
return array(
'modules' => array(
// ...
'MxcRouteGuard',
),
// ...
);
The MxcRouteGuard module has some options to allow you to quickly customize the basic
functionality. After installing MxcRouteGuard, copy
./vendor/maxence/MxcRouteGuard/config/mxcrouteguard.global.php.dist
to
./config/autoload/mxcrouteguard.global.php
and change the values as desired.
The following options are available:
zfcuser_auth_service
.white
, black
) are provided to handle the observed routes list
(see below). In whitelist mode all routes but the routes provided in the observed routes list
are protected from anonymous access. In blacklist mode only the routes provided in the observed
route list are protected from anonymous acceess. Default is white
.black
mode) or allow to
anonymous access (white
mode). Default: array()
zfcuser/login
MxcRouteGuard\Service\Strategy\RedirectStrategy
If ZfcUser is used and the ZfcUser enable_registration flag is set true then MxcRouteGuard
automatically whitelists zfcuser/register
regardless of the guard mode.
In case a route gets blocked MxcRouteGuard applies a redirect
parameter to the anonymous_redirect
route which can be used by ZfcUser, if the use_redirect_parameter_if_present
setting is set true
.
For authenticated users MxcRouteGuard provides full access to all routes. If you need more detailled control of who can access what route, use ZfcRbac or BjyAuthorize or similar modules instead of MxcRouteGuard.
Common use cases for MxcRouteGuard are demo apps which only require a user to be known.
MxcRouteGuard is released under the New BSD License. See license.txt
.