PHPackages                             techpaf/annotation-firewall-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. techpaf/annotation-firewall-bundle

ActiveSymfony-bundle[Authentication &amp; Authorization](/categories/authentication)

techpaf/annotation-firewall-bundle
==================================

Symfony2 bundle

017PHP

Since Dec 4Pushed 12y ago1 watchersCompare

[ Source](https://github.com/MattPieraggi/TechPafAnnotationFirewallBundle)[ Packagist](https://packagist.org/packages/techpaf/annotation-firewall-bundle)[ RSS](/packages/techpaf-annotation-firewall-bundle/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

AnnotationFirewallBundle
========================

[](#annotationfirewallbundle)

This bundle allows you to configure firewalls using annotations for your Symfony2 Project. It is inspired by [Matthias Noback'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).

[![knpbundles.com](https://camo.githubusercontent.com/ecb3d37cd895bf2b1ee7a1b81e322040539b8bee8907c929441c983ba0be9f3d/687474703a2f2f6b6e7062756e646c65732e636f6d2f4d61747450696572616767692f54656368506166416e6e6f746174696f6e4669726577616c6c42756e646c652f62616467652d73686f7274)](http://knpbundles.com/MattPieraggi/TechPafAnnotationFirewallBundle)

Installation
============

[](#installation)

Update your `composer.json` file:

```
{
    "require": {
        "techpaf/annotation-firewall-bundle": "0.1.*@dev"
    }
}
```

Register the bundle in `app/AppKernel.php`:

```
// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new TechPaf\AnnotationFirewallBundle\TechPafAnnotationFirewallBundle(),
    );
}
```

Usage
=====

[](#usage)

The AnnotationFirewallBundle uses annotations to indicate which Routes should be secured.

Security.yml
------------

[](#securityyml)

Instead of using a pattern like `pattern: ^/api/` in your `security.yml` file, you need to register the request\_matcher provided by the bundle.

```
# 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:

```
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
-----------

[](#annotations)

Then you need to configure each Controller you want to secure using this bundle.

```
