Download the PHP package sil/route-security-bundle without Composer
On this page you can find all versions of the php package sil/route-security-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package route-security-bundle
SilRouteSecurityBundle
This bundle provide a way to secure accesses to all routes of your application and adapt the view according to the logged user.
Principle
- The bundle generate roles for all configured routes.
- The bundle listen the
kernel.request
event and retrieve the requested route. - If the route is configure to be secured, the bundle check if the current user has the appropriate role. If not, an AccessDeniedException from Symfony security component is throw. You will see above how to modify this behaviour.
For all routes configured in access control, the user must be authenticated and implement the UserInterface
of Symfony security component.
Installation
Composer
composer require sil/route-security-bundle
Register the bundle
Add routes configuration
Routes are only required if you want to use the Javascript part of this bundle.
Configuration
You can configure the bundle under the sil_route_security
key.
Options
Enable access control
By default, the access control is disable.
List of secured routes
You can define a list of secured routes :
Secured routes format
In addition or instead of secured routes list, you can define a regex format to configure a set of routes to be secured :
List of ignored routes
You can define a list of ignored routes :
Ignored routes format
In addition or instead of ignored routes list, you can define a regex format to configure a set of routes to be not secured :
Naming strategy
By default, to generate a role for route, the bundle convert the route name to ROLE_.strtoupper($route_name). If you want a different format, you can make your hown converter. Just create a service that implement the NamingStrategyInterface and configure the bundle option with your service identifier.
Roles provider
All generated roles is accessible through the sil_route_security.roles_provider
service.
For exemple, you can inject this service into your UserFormType
to configure the associates roles to an user.
Adapt template view
The bundle expose :
- Twig functions that allow you to generate view according to the roles of user.
- Javascript object that allow you to generate view according to the roles of user.
Twig
hasUserAccessToRoute
- Check if the user has access to the given route
- Exemple :
hasUserAccessAtLeastOneRoute
- Check if the user has access at least to one route
- Exemple :
hasUserAccessToRoutes
- Check if the user has access to all given routes
- Exemple :
Javascript
Installation
To load it globally, add the following line to your template:
Usage
Access denied behavior
When user access to secured route and does not have the right, an AccessDeniedException
is throw. The framework will convert it to a 403 response.
Just before that, the event AccessDeniedToRouteEvent
is dispatch.
You can listen it and implement your hown behaviour, logging the action for exemple, return a custom response, redirect, whatever...
All versions of route-security-bundle with dependencies
symfony/framework-bundle Version ^6.0 || ^7.0
symfony/security-core Version ^6.0 || ^7.0
symfony/yaml Version ^6.0 || ^7.0
symfony/expression-language Version ^6.0 || ^7.0
twig/twig Version ^3.0