我目前正在嘗試配置 Tomcat 8 Web 應用程式以使用 Keycloak 作為身份提供者。我按照官方 keycloak 檔案中的說明進行操作,并將用戶角色“user”添加到我的 Keycloak Realm 中,用戶應該有權訪問網路應用程式。在 web.xml 中,我還將此角色添加到了 auth-constraint。這是我的 web.xml
<security-constraint>
<web-resource-collection>
<web-resource-name>Customers</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>user</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>this is ignored currently</realm-name>
</login-config>
<security-role>
<role-name>user</role-name>
</security-role>
當我嘗試訪問路徑 (/*) 時,tomcat 成功將我重定向到 keycloak 登錄頁面。但是在使用分配了用戶角色的用戶登錄后,我只在瀏覽器中收到以下錯誤:
HTTP Status 403 – Forbidden - The server understood the request but refuses to authorize it
我期望成功重定向,因為登錄用戶具有 web.xml 中給出的角色。
uj5u.com熱心網友回復:
我自己修好了。如果其他人遇到此問題,請在我的 keycloak.json 檔案中將“use-resource-role-mappings”設定為 true。將其設定為 false 后一切正常。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/316747.html
下一篇:tomcatjvm引數丟失
