2017 © Pedro Peláez
 

symfony-bundle annotation-firewall-bundle

Symfony2 bundle

image

techpaf/annotation-firewall-bundle

Symfony2 bundle

  • Wednesday, December 4, 2013
  • by MattPieraggi
  • Repository
  • 1 Watchers
  • 0 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

AnnotationFirewallBundle

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)

knpbundles.com, (*2)

Installation

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(), ); }

Usage

The AnnotationFirewallBundle uses annotations to indicate which Routes should be secured., (*5)

Security.yml

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)

app/config/security.yml

...

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 # ...

Annotations

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)

@FirewallExclusionPolicy

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 annotation

By default the exclusion policy is ALL, so unless you add annotations, no route will be secured using the AnnotationFirewallBundle., (*17)

@FirewallExclude

This annotation exclude a specific route from the firewall (the route is not secured), (*18)

@FirewallExpose

This annotation add a specific route to the firewall (the route is secured), (*19)

TODO

The next updates are going to be: * Allow usage of the AnnotationFirewallBundle in multiple firewalls simultaneously * Add Cache, (*20)

The Versions

04/12 2013

dev-master

9999999-dev http://github.com/MattPieraggi/TechPafAnnotationFirewallBundle

Symfony2 bundle

  Sources   Download

MIT

The Requires

 

by Mathieu Pieraggi

symfony firewall annotation