Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php symfony2中的多个防火墙_Php_Security_Symfony - Fatal编程技术网

Php symfony2中的多个防火墙

Php symfony2中的多个防火墙,php,security,symfony,Php,Security,Symfony,我在symfony2中的安全配置有问题。我需要两个防火墙用于两个不同的用户实体 以下是我的配置文件: security.yml: security: encoders: entity_owner: class: Pisteur\CoreBundle\Entity\OwnerAccount algorithm: sha512 iterations: 5000 encode_as_

我在symfony2中的安全配置有问题。我需要两个防火墙用于两个不同的用户实体

以下是我的配置文件:

security.yml:

security:
    encoders:
        entity_owner:
            class: Pisteur\CoreBundle\Entity\OwnerAccount
            algorithm: sha512
            iterations: 5000
            encode_as_base64: false
        entity_business:
            class: Pisteur\BusinessBundle\Entity\BusinessOwner
            algorithm: sha512
            iterations: 5000
            encode_as_base64: false
    providers:
        entity_owner:
            name: entity_owner
            entity:
                class: Pisteur\CoreBundle\Entity\OwnerAccount
                property: username
        entity_business:
            name: entity_business
            entity:
                class: Pisteur\BusinessBundle\Entity\BusinessOwner
                property: username
    firewalls:
        entity_business:
            pattern: ^/business
            anonymous: ~
            form_login:
                check_path: /business/login_check
                login_path: /business/login
                default_target_path: /business/dashboard
            provider: entity_business
            logout:
                path: /logout
                target: /business/login
        entity_owner:
            pattern: ^/
            anonymous: ~
            form_login:
                login_path: /login
                check_path: /login_check
                default_target_path: /dashboard
            provider: entity_owner
            logout:
                path: /logout
                target: /login
    role_hierarchy:
        ROLE_ADMIN: [ROLE_USER, ROLE_BUSINESS]
        ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
    access_control:
        - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/business/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/account, roles: ROLE_USER }
        - { path: ^/dashboard, roles: ROLE_USER }
        - { path: ^/business/dashboard, roles: ROLE_BUSINESS }
        - { path: ^/_internal, roles: IS_AUTHENTICATED_ANONYMOUSLY, ip: 127.0.0.1 }
以下是我所有的路线:

security_login:
    pattern:  /login
    defaults: { _controller: "PisteurSecurityBundle:Security:login" }
    requirements: { _method: get }

login_check:
    pattern: /login_check

business_security_login:
    pattern:  /business/login
    defaults: { _controller: "PisteurSecurityBundle:BusinessSecurity:login" }
    requirements: { _method: get }

business_login_check:
    pattern: /business/login_check

logout:
    pattern: /logout
OwnerAccount的登录表单:

<form id="login-form" action="{{ path('login_check') }}" method="post">
            <label><input id="username" type="text" name="_username" /></label>
            <label><input id="password" type="password" name="_password" /></label>
            <button class="btn custom large orange-button" type="submit" id="login-button">{% trans from "login" %}login{% endtrans %}</button>
 </form>
业务所有者的登录表单:

<form id="login-form" action="{{ path('business_login_check') }}" method="post">
            <label><input id="username" type="text" name="_username" /></label>
            <label><input id="password" type="password" name="_password" /></label>
            <button class="btn custom large orange-button" type="submit" id="login-button">{% trans from "login" %}login{% endtrans %}</button>
</form>
当我使用OwnerAccount表单登录时,它将工作并重定向到/dashboard。 当我使用BusinessOwner表单登录时,它不起作用,并重定向到/login should是/business/login,错误为BadCredentials

我不知道为什么,但似乎只使用了实体所有者,因为它从/business/login重定向到/login


我的配置有问题吗?

请尝试类似于^/?的方法?!业务对于实体所有者模式,这可能会阻止实体所有者模式与实体所有者业务模式匹配。

将所有所有者资源移动到/owner。将实体所有者模式更改为^/owner,并将主页重定向到/owner。

您的实体业务模式与实体所有者模式匹配,即^/business与^/匹配。我认为它们必须是完全独立的模式才能正常工作。这可能是真的。我对正则表达式不是很在行。对于我的实体所有者而言,与^/但不与^/业务匹配的正则表达式是什么?谢谢选项1:尝试类似^/?的方法?!实体所有者模式的业务。选项2:将entity_owner模式更改为^/owner,并将主页重定向到/owner。您应该将其作为正式答案编写。我稍后会测试它,如果它有效,我会把你的答案记为好答案。