dev-master
9999999-dev http://github.com/MattPieraggi/TechPafAnnotationFirewallBundleSymfony2 bundle
MIT
The Requires
- php >=5.3.2
- symfony/framework-bundle ~2.0
by Mathieu Pieraggi
symfony firewall annotation
 Wallogit.com
                    
                    2017 © Pedro Peláez
                         Wallogit.com
                    
                    2017 © Pedro Peláez
                    
                    
                    
                    
                
                
            
Symfony2 bundle
This bundle allows you to configure firewalls using annotations for your Symfony2 Project. It is inspired by Matthias Noback's blog, the NelmioApiDocBundle and the JMSSerializerBundle., (*1)
Update your composer.json file:, (*3)
``` JSON { "require": { "techpaf/annotation-firewall-bundle": "0.1.*@dev" } }, (*4)
Register the bundle in `app/AppKernel.php`: ``` PHP // app/AppKernel.php public function registerBundles() { return array( // ... new TechPaf\AnnotationFirewallBundle\TechPafAnnotationFirewallBundle(), ); }
The AnnotationFirewallBundle uses annotations to indicate which Routes should be secured., (*5)
Instead of using a pattern like pattern: ^/api/ in your security.yml file, you need to register the request_matcher provided by the bundle., (*6)
``` YAML, (*7)
firewalls: any_firewall: #pattern: ^/api/ # No need of the pattern anymore request_matcher: techpaf.annotation_firewall.annotation_request_matcher, (*8)
You can use it with multiple firewalls. For example: ``` YAML firewalls: dev: # default Firewall pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false fos_secured: # FOSUserBundle Firewall pattern: ^/admin/ # ... wsse_secured: # MopaWSSEAuthenticationBundle Firewall request_matcher: techpaf.annotation_firewall.annotation_request_matcher # ...
Then you need to configure each Controller you want to secure using this bundle., (*9)
``` PHP <?php, (*10)
namespace TechPaf\ExampleBundle\Controller;, (*11)
// ... use TechPaf\AnnotationFirewallBundle\Annotation\FirewallExclude; use TechPaf\AnnotationFirewallBundle\Annotation\FirewallExclusionPolicy;, (*12)
/** * @FirewallExclusionPolicy("NONE") */ class MyController extends Controller { /** * @Route("/secured") * @Template() **/ public function securedAction() { return array('secured' => true); }, (*13)
/**
* @Route("/not_secured")
* @Template()
*
* @FirewallExclude
**/
public function notSecuredAction()
{
    return array('secured' => false);
}
} ```, (*14)
There are three annotations: * @FirewallExclusionPolicy * @FirewallExclude * @FirewallExpose, (*15)
This annotation specify the default policy for every routes of a controller.
It can have two values : ALL or NONE., (*16)
ALL means that every route will be excluded from the firewall unless you add an @FirewallExpose annotation NONE means that every route will be added to the firewall unless you add an @FirewallExclude annotationBy default the exclusion policy is ALL, so unless you add annotations, no route will be secured using the AnnotationFirewallBundle., (*17)
This annotation exclude a specific route from the firewall (the route is not secured), (*18)
This annotation add a specific route to the firewall (the route is secured), (*19)
The next updates are going to be: * Allow usage of the AnnotationFirewallBundle in multiple firewalls simultaneously * Add Cache, (*20)
Symfony2 bundle
MIT
symfony firewall annotation