我的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>
BusinessOwner的登录表单:
<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(应该是/ business / login),错误为“BadCredentials”
我不确定为什么,但似乎只使用了entity_owner(因为它从/ business / login重定向到/ login)
我的配置有问题吗?
答案 0 :(得分:3)
对于entity_owner模式尝试类似^/(?!business)
的内容,这可能会阻止entity_owner模式与entity_business模式匹配。
答案 1 :(得分:2)
将所有所有者资源移至/ owner。将entity_owner模式更改为^/owner
,并将主页重定向到/ owner。