More than one firewall at Symfony2 project security.yml, how to deal with pattern?

ReynierPM

I am working in a project where I will need two firewalls or secured areas. The first firewall/secured area will allow login/logout using HWIOAuthBundle using Salesforce as provider, the second firewall/secured area will allow login/logout through FOSUserBundle since this is for internal sysadmin and so on. I have a doubt trying to get security.yml file well setup since I don't know how to deal with pattern parameter. I have read Security reference but have not idea in how to do this. This is what I have at the moment:

firewalls:
        #this is the public area accessed by/from iOs app and only users registered at Salesforce as rep can login
        rep_area:
            methods: [GET, POST]
            pattern: ^/
            anonymous: true
            logout: true

        #this is the secured area accessed through web browser and only internals are allowed to login
        admin_area:
            pattern:    ^/
            anonymous:    ~

How should I configure pattern in that case?

Update: firewalls not working

This is how the firewalls section looks after users answer:

firewalls:
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false

    #this is the secured area accessed through web browser and only internals are allowed to login
    admin_area:
        pattern:    ^/admin
        anonymous:    ~
        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
            login_path: /login
            check_path: /login_check
            post_only: true
            always_use_default_target_path: true
            target_path_parameter: _target_path
            use_referer: false
            failure_path: null
            failure_forward: false
        logout:
            path:   fos_user_security_logout
            target: /

    #this is the public area accessed by/from iOs app and only users registered at Salesforce as rep can login
    rep_area:
        methods: [GET, POST]
        pattern: ^/
        anonymous: true
        logout: true

But if I try http://appdev.local/app_dev.php/admin/ I got this error:

InvalidConfigurationException in BaseNode.php line 313: Invalid configuration for path "security.firewalls.admin_area": The check_path "/login_check" for login method "form_login" is not matched by the firewall pattern "^/admin".

Why?

Edit 2: what about if have FOSUserBundle && HWIOAuth work together?

As additional info and I forgot to tell this from the very beginning, I have and need FOSUserBundle && HWIOAuth installed and I am trying to get both working as should be. In that case this is how my routing.yml looks like:

#HWIOAuthBundle
hwi_oauth_redirect:
    resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
    prefix:   /connect

hwi_oauth_login:
    resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
    prefix:   /login

salesforce_login:
    pattern: /login/check-salesforce

#PDOne
pd_one:
    resource: "@PDOneBundle/Controller/"
    type:     annotation
    prefix:   /

template:
    resource: "@TemplateBundle/Controller/"
    type:     annotation
    prefix:   /

#FOSUserBundle
fos_user:
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"
fos_user_security:
    prefix: /admin
    resource: "@FOSUserBundle/Resources/config/routing/security.xml"

#SonataAdmin
admin:
    resource: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
    prefix: /admin

_sonata_admin:
    resource: .
    type: sonata_admin
    prefix: /admin

How I should deal with prefix between FOSUserBundle && HWIOAuth?

Squeegy

Just simply

firewalls:
    #this is the secured area accessed through web browser and only internals are allowed to login
            admin_area:
                pattern:    ^/admin
                anonymous:    ~

        #this is the public area accessed by/from iOs app and only users registered at Salesforce as rep can login
        rep_area:
            methods: [GET, POST]
            pattern: ^/
            anonymous: true
            logout: true

It's a regex telling symfony that all routes ^ (beginning) with / follow this rule. Or /admin follow another rule. The firewall will always follow whatever rule it matches first. So your admin rule must come first or else it won't work.

Edit

In your routes settings where you add in the security routes for FOS UserBundle try having /admin appended as a prefix. Could be because /admin is your rule but the route being generated for login is host.com/login instead of host.com/admin/login

fos_user_security:
    prefix: /admin
    resource: "@FOSUserBundle/Resources/config/routing/security.xml"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Service Locator Pattern - How to deal with more than one implementation of the same service interface

From Dev

Service Locator Pattern - How to deal with more than one implementation of the same service interface

From Dev

How do I edit more than one one-to-many entities in symfony2?

From Dev

How to deal with subquery which returns more than one value

From Dev

How to deal with subquery which returns more than one value

From Dev

How to deal with more than one scope in an Angular directive?

From Dev

How to run a winform project for more than one?

From Dev

Complex firewall configuration - Symfony2 security

From Dev

Symfony3 Login form : how to parametrize firewall in security.yml?

From Dev

How to load cmake script with more than one project with Qt Creator

From Dev

How to load cmake script with more than one project with Qt Creator

From Dev

how to add more than one android app to your firebase project?

From Dev

replace more than one pattern python

From Dev

Design pattern for class with more than one methods

From Dev

No more than 9 arguments in QString arg? How to deal with it?

From Dev

Symfony2 - Purpose of `anonymous.key` in security.yml

From Dev

How to display data from more than one table to my view using MVP pattern in C# winforms?

From Dev

Symfony2 multiple firewall loop error in one of them

From Dev

symfony2 form: how to save entity and how to add more then one entity to the same form?

From Dev

How to filter in more than one column in ng2-table?

From Dev

How can I contain more than 2 models in one template?

From Dev

Regex for excluding a pattern of more than 2 "==" in Java

From Java

More than one folder / project in one Sublime Text 3 window

From Dev

Push more than one netbeans project in one repository

From Dev

Push more than one netbeans project in one repository

From Dev

Python Regular expression: is there a symbol to search for more than one occurence of a pattern?

From Dev

Associate Pattern Element with More than One Node in Cypher

From Dev

Strategy pattern in Python when a "strategy" consists of more than one function

From Dev

Can there be more than one template method in an implementation of the Template Method pattern?

Related Related

  1. 1

    Service Locator Pattern - How to deal with more than one implementation of the same service interface

  2. 2

    Service Locator Pattern - How to deal with more than one implementation of the same service interface

  3. 3

    How do I edit more than one one-to-many entities in symfony2?

  4. 4

    How to deal with subquery which returns more than one value

  5. 5

    How to deal with subquery which returns more than one value

  6. 6

    How to deal with more than one scope in an Angular directive?

  7. 7

    How to run a winform project for more than one?

  8. 8

    Complex firewall configuration - Symfony2 security

  9. 9

    Symfony3 Login form : how to parametrize firewall in security.yml?

  10. 10

    How to load cmake script with more than one project with Qt Creator

  11. 11

    How to load cmake script with more than one project with Qt Creator

  12. 12

    how to add more than one android app to your firebase project?

  13. 13

    replace more than one pattern python

  14. 14

    Design pattern for class with more than one methods

  15. 15

    No more than 9 arguments in QString arg? How to deal with it?

  16. 16

    Symfony2 - Purpose of `anonymous.key` in security.yml

  17. 17

    How to display data from more than one table to my view using MVP pattern in C# winforms?

  18. 18

    Symfony2 multiple firewall loop error in one of them

  19. 19

    symfony2 form: how to save entity and how to add more then one entity to the same form?

  20. 20

    How to filter in more than one column in ng2-table?

  21. 21

    How can I contain more than 2 models in one template?

  22. 22

    Regex for excluding a pattern of more than 2 "==" in Java

  23. 23

    More than one folder / project in one Sublime Text 3 window

  24. 24

    Push more than one netbeans project in one repository

  25. 25

    Push more than one netbeans project in one repository

  26. 26

    Python Regular expression: is there a symbol to search for more than one occurence of a pattern?

  27. 27

    Associate Pattern Element with More than One Node in Cypher

  28. 28

    Strategy pattern in Python when a "strategy" consists of more than one function

  29. 29

    Can there be more than one template method in an implementation of the Template Method pattern?

HotTag

Archive