The symfony Reference Book

The security.yml Configuration File

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


About

You are currently reading "The symfony Reference Book" which is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported License license.

Master symfony

Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).
trainings.sensiolabs.com

Books on symfony

Learn more about symfony with the official guides.
books.sensiolabs.com

L'audit Qualité par SensioLabs

200 points de contrôle de votre applicatif web.
audit.sensiolabs.com

Chapter Content

Authentication

Authorization

symfony training
Be trained by symfony experts
Feb 21: Köln (Getting Started with Symfony2 - English)
Feb 27: Köln (Mastering Symfony2 - English)
Mar 05: Köln (Web Development with Symfony2 - Deutsch)
Mar 05: Montreal (Web Development with Symfony2 - English)
Mar 05: Montreal (Getting Started with Symfony2 - English)
and more...

Search


powered by google
You are currently browsing "The symfony Reference Book" in English for the 1.4 version - Switch to version: - Switch to language:
Creative Commons License This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.
The symfony reference guide
Support symfony!
Buy this book
or donate.
Buy The symfony reference guide from amazon.com

The security.yml configuration file describes the authentication and authorization rules for a symfony application.

The configuration information from the security.yml file is used by the user factory class (sfBasicSecurityUser by default). The enforcement of the authentication and authorization is done by the security filter.

When an application is created, symfony generates a default security.yml file in the application config/ directory which describes the security for the whole application (under the default key):

default:
  is_secure: false

As discussed in the introduction, the security.yml file benefits from the configuration cascade mechanism, and can include constants.

The default application configuration can be overridden for a module by creating a security.yml file in the config/ directory of the module. The main keys are action names without the execute prefix (index for the executeIndex method for instance).

To determine if an action is secure or not, symfony looks for the information in the following order:

The same precedence rules are used to determine the credentials needed to access an action.

The security.yml configuration file is cached as a PHP file; the process is automatically managed by the sfSecurityConfigHandler class.

Authentication

The default configuration of security.yml, installed by default for each application, authorizes access to anybody:

default:
  is_secure: false

By setting the is_secure key to true in the application security.yml file, the entire application will require authentication for all users.

When an un-authenticated user tries to access a secured action, symfony forwards the request to the login action configured in settings.yml.

To modify authentication requirements for a module, create a security.yml file in the config/ directory of the module and define an all key:

all:
  is_secure: true

To modify authentication requirements for a single action of a module, create a security.yml file in the config/ directory of the module and define a key after the name of the action:

index:
  is_secure: false

It is not possible to secure the login action. This is to avoid infinite recursion.

Authorization

When a user is authenticated, the access to some actions can be even more restricted by defining credentials. When credentials are defined, a user must have the required credentials to access the action:

all:
  is_secure:   true
  credentials: admin

The credential system of symfony is simple and powerful. A credential is a string that can represent anything you need to describe the application security model (like groups or permissions).

The credentials key supports Boolean operations to describe complex credential requirements by using the notation array.

If a user must have the credential A and the credential B, wrap the credentials with square brackets:

index:
  credentials: [A, B]

If a user must have credential the A or the credential B, wrap them with two pairs of square brackets:

index:
  credentials: [[A, B]]

You can also mix and match brackets to describe any kind of Boolean expression with any number of credentials.

The cache.yml Configuration File »
« The databases.yml Configuration File

Questions & Feedback

If you find a typo or an error, please register and open a ticket.

If you need support or have a technical question, please post to the official user mailing-list.