Search code examples
securityconfigurationkernelsymfonysonata

How to use different security.yml files / security settings?


I have Symfony3 project where I want completly separate Sonata admin bundles from main appliaction. Main application and sonata users are different entities which are never cross. Also all security settings are independent and different. Furthermore in future there will be another admin subsytem - completly different from current one for another aspect of application.

I think about different environments or overriding kernel (by this methodics) and need to know how to specify security settings per environment (if it is correct approach and won't blow up framwork) or make it selectable by overriding kernel. Or... whatever approach you know to do this.

My Symfony version is 3.1.


Solution

  • You can create new environments in addition to the existing prod, dev and test ones, as described in the documentation How to Master and Create new Environments. This will give you access to a new configuration file (config_[your_new_environment].yml), which in turn could load a different security.yml file altogether in the imports statement and override the default values.

    Example:

    // config_sonata.yml
    
    imports:
        - { resource: config.yml }
        - { resource: security_sonata.yml }
    

    In your case though, I would first investigate using different firewalls as part of the main security.yml file. If the URLs you wish to secure in your different applications do not overlap, you can simply add more firewalls and user providers. This should allow you to cover all your needs and keep everything in one place.