<commit_before>AnnotationFirewallBundle
========================

This bundle allows you to configure firewalls using annotations for your Symfony2 Project.
It is inspired by [<NAME>'s blog](http://php-and-symfony.matthiasnoback.nl/2012/07/symfony2-security-using-advanced-request-matchers-to-activate-firewalls/) and the [NelmioApiDocBundle](https://github.com/nelmio/NelmioApiDocBundle)

# Installation #

Update your `composer.json` file:

``` JSON
{
    "require": {
        "techpaf/annotation-firewall-bundle": "dev-master"
    }
}
```

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.

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

``` YAML
// app/config/security.yml
// ...
firewalls:
    any_firewall:
        #pattern: ^/api/    # No need of the pattern anymore
        request_matcher: techpaf.annotation_firewall.annotation_request_matcher
```

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: # WSSE
        request_matcher: techpaf.annotation_firewall.annotation_request_matcher
        // ...
```

## Annotations ##

Then you need to configure each Controller you want to secure using this bundle.
The annotations hierarchy and names are inspired from the [JMSSerializerBundle](https://github.com/schmittjoh/JMSSerializerBundle).
To avoid conflict with this bundle, you should import the annotations with an alias like `use TechPaf\AnnotationFirewallBundle\Annotation\Exclude as FirewallExpose;`.

``` PHP
<?php

namespace TechPaf\ExampleBundle\Controller;

// ...
use TechPaf\AnnotationFirewallBundle\Annotation\Exclude as FirewallExclude;
use TechPaf\AnnotationFirewallBundle\Annotation\ExclusionPolicy as FirewallExclusionPolicy;

/**
 * @FirewallExclusionPolicy("NONE")
 */
class MyController extends Controller
{
    /**
    * @Route("/")
    * @Template()
    **/
    public function securedAction()
    {
        return array('secured' => true);
    }

    /**
    * @Route("/")
    * @Template()
    *
    * @FirewallExclude
    **/
    public function notSecuredAction()
    {
        return array('secured' => false);
    }
}
```

They are three annotations:
* @FirewallExclusionPolicy
* @FirewallExclude
* @FirewallExpose

### @FirewallExclusionPolicy ###

This annotation specify the default policy for every routes of a controller.
It can have two values : `ALL` or `NONE`.

* `ALL` means that every route will be excluded from the firewall unless you add an `@FirewallExpose` annotation 
* `NONE` means that each route will be added to the firewall unless you add an `@FirewallExclude` annotation
<commit_msg>Fix installation guide errors<commit_after>AnnotationFirewallBundle
========================

This bundle allows you to configure firewalls using annotations for your Symfony2 Project.
It is inspired by [<NAME>'s blog](http://php-and-symfony.matthiasnoback.nl/2012/07/symfony2-security-using-advanced-request-matchers-to-activate-firewalls/), the [NelmioApiDocBundle](https://github.com/nelmio/NelmioApiDocBundle) and the [JMSSerializerBundle](https://github.com/schmittjoh/JMSSerializerBundle).

# Installation #

Update your `composer.json` file:

``` JSON
{
    "require": {
        "techpaf/annotation-firewall-bundle": "dev-master"
    }
}
```

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.

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

``` YAML
// app/config/security.yml
// ...
firewalls:
    any_firewall:
        #pattern: ^/api/    # No need of the pattern anymore
        request_matcher: techpaf.annotation_firewall.annotation_request_matcher
```

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: # WSSE
        request_matcher: techpaf.annotation_firewall.annotation_request_matcher
        // ...
```

## Annotations ##

Then you need to configure each Controller you want to secure using this bundle.
The annotations hierarchy and names are inspired by the [JMSSerializerBundle](https://github.com/schmittjoh/JMSSerializerBundle).
To avoid conflict with this bundle, you should import the annotations with an alias like `use TechPaf\AnnotationFirewallBundle\Annotation\Exclude as FirewallExpose;`.

``` PHP
<?php

namespace TechPaf\ExampleBundle\Controller;

// ...
use TechPaf\AnnotationFirewallBundle\Annotation\Exclude as FirewallExclude;
use TechPaf\AnnotationFirewallBundle\Annotation\ExclusionPolicy as FirewallExclusionPolicy;

/**
 * @FirewallExclusionPolicy("NONE")
 */
class MyController extends Controller
{
    /**
    * @Route("/secured")
    * @Template()
    **/
    public function securedAction()
    {
        return array('secured' => true);
    }

    /**
    * @Route("/not_secured")
    * @Template()
    *
    * @FirewallExclude
    **/
    public function notSecuredAction()
    {
        return array('secured' => false);
    }
}
```

They are three annotations:
* @FirewallExclusionPolicy
* @FirewallExclude
* @FirewallExpose

### @FirewallExclusionPolicy ###

This annotation specify the default policy for every routes of a controller.
It can have two values : `ALL` or `NONE`.

* `ALL` means that every route will be excluded from the firewall unless you add an `@FirewallExpose` annotation 
* `NONE` means that each route will be added to the firewall unless you add an `@FirewallExclude` annotation

{'fraction_non_alphanumeric': 0.1152719987671444, 'fraction_numerical': 0.0024657112035752814, 'mean_word_length': 3.6690647482014387, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7498437', 'n_tokens_mistral': 1978, 'n_tokens_neox': 1867, 'n_words': 529}