<p>我正在嘗試將使用者的身份驗證與管理員的身份驗證分開。 </p>
<p>所以我建立了2個防火牆和2個不同的存取控制。 </p>
<p>我的security.yaml檔案如下:</p>
<pre class="brush:php;toolbar:false;">enable_authenticator_manager: true
password_hashers:
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
providers:
owner_authentication:
entity:
class: App\Entity\Merchant\Owner
property: emailAddress
user_authentication:
entity:
class: App\Entity\User\User
property: emailAddress
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
user:
lazy: true
pattern: ^/admin/login/
provider: user_authentication
user_checker: App\Security\AuthentificableModelChecker
form_login:
provider: user_authentication
default_target_path: app.dashboard.index
use_referer: true
use_forward: false
login_path: app.authorization.admin_login
check_path: app.authorization.admin_login
username_parameter: login[emailAddress]
password_parameter: login[password]
logout:
path: app.authorization.logout
target: app.authorization.admin_login
main:
lazy: true
pattern: ^/
provider: owner_authentication
user_checker: App\Security\AuthentificableModelChecker
form_login:
provider: owner_authentication
default_target_path: app.dashboard.index
use_referer: true
use_forward: false
login_path: app.authorization.login
check_path: app.authorization.login
username_parameter: login[emailAddress]
password_parameter: login[password]
logout:
path: app.authorization.logout
target: app.authorization.login
access_control:
- { path: ^/admin/login, roles: PUBLIC_ACCESS}
- { path: ^/login, roles: PUBLIC_ACCESS }
- { path: ^/, roles: ROLE_USER }</pre>
<p>主防火牆上的一切都正常運作,但當我使用使用者(管理員)防火牆提交按鈕時,登入頁面會刷新自身,然後什麼事也不發生。我沒有任何錯誤。 </p>
<p>** 如果我在主防火牆上新增使用者(管理員)登錄,那麼/admin/login將正常工作,而另一個則不再工作。 </p>
<p>當我呼叫<code>$authenticationUtils->getLastAuthenticationError()</code>時,我沒有收到任何錯誤。但驗證也不起作用。</p>
<p>這是我的控制器的樣子:</p>
<pre class="brush:php;toolbar:false;">public function adminLogin(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser()) {
return $this->redirectToRoute('app.dashboard.index');
}
$loginForm = $this->createForm(LoginType::class, ['emailAddress' => $authenticationUtils->getLastUsername()]);
return $this->renderForm('app/pages/authorization/admin_login.html.twig', [
'title' => 'Log in',
'login_form' => $loginForm,
'error' => $authenticationUtils->getLastAuthenticationError()?->getMessageKey(),
]);
}</pre>
<p>這是一個人遇到的相同問題:https://grafikart.fr/forum/35234,但我找不到任何解決方案。 </p>
Your Answer
1 個答案
最後,我找到了答案,我會在這裡發布:https://stackoverflow.com/a/42352112/8003007
我所需要做的是在兩個防火牆中新增一個context: my_context。
這是一個難以辨識的選項,因為它在官方和目前的Symfony文件中並沒有出現,只出現在先前的版本中,例如Symfony 3.4。
Hot Questions
function_exists()無法判定自訂函數
2024-04-29 11:01:01
google 瀏覽器 手機版顯示的怎麼實現
2024-04-23 00:22:19
子窗口操作父窗口,輸出沒反應
2024-04-19 15:37:47
父視窗沒有輸出
2024-04-18 23:52:34
關於CSS心智圖的課件在哪?
2024-04-16 10:10:18
Hot Tools
vc9-vc14(32+64位元)運行庫合集(連結在下方)
phpStudy安裝所需運行函式庫集合下載
VC9 32位
VC9 32位元 phpstudy整合安裝環境運行庫
php程式設計師工具箱完整版
程式設計師工具箱 v1.0 php整合環境
VC11 32位
VC11 32位元 phpstudy整合安裝環境運行庫
SublimeText3漢化版
中文版,非常好用
熱門話題
抖音等級價目表1-75
20337
7
20337
7
wifi顯示無ip分配
13531
4
13531
4
虛擬手機號碼接收驗證碼
11851
4
11851
4
gmail信箱登陸入口在哪裡
8836
17
8836
17
windows安全中心怎麼關閉
8420
7
8420
7
熱門文章
2025年加密貨幣市場十大趨勢預測:下一個風口在哪裡?
2025-11-07
By DDD
幣圈土狗項目如何識別?避免歸零幣的陷阱與風險預警
2025-11-07
By DDD
解決CSS @media 查詢優先級與規則覆蓋問題的教程
2025-11-07
By DDD
win10字體安裝後在軟件裡找不到怎麼辦_win10字體安裝與識別方法
2025-11-07
By DDD
鐵路12306支付失敗訂單還在嗎_鐵路12306支付失敗訂單處理方法
2025-11-07
By DDD





