symfony2のセキュリティ設定に問題があります。 2つの異なるユーザーエンティティに対して2つのファイアウォールが必要です。ここで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 }
はすべて私のルーティングです:OwnerAccountため
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
ログインフォーム:
<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>
ログインf orm for 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フォームでログインしても、自分の/ダッシュボードにリダイレクトされます。 BusinessOwnerフォームでログインしても、動作しないで、/ login /にリダイレクトされ、 "BadCredentials"というエラーが表示されます。
私は理由は分かりませんが、entity_owner使用されています(/ business/loginから/ loginにリダイレクトされるため)
私の設定で何か問題がありますか?
entity_businessパターンはentity_ownerパターンと一致します(つまり、^/businessは^ /によって照合されます)。私は彼らが正しく動作するためには完全に別々のパターンでなければならないと思います。 – Martin
それは本当かもしれません。私は正規表現ではあまりよくありません。私のentity_ownerの "^ /"にマッチさせるが、 "^/business"にマッチさせる正規表現は何でしょうか?ありがとう –
オプション1:entity_ownerパターンに^ /(?! business)のようなものを試してみてください。オプション2:entity_ownerパターンを^/ownerに変更し、メインページを/ ownerにリダイレクトさせます。 – Martin