Tomcat: 403 服务器理解请求但在keycloak登录后拒绝授权错误

Tomcat: 403 The server understood the request but refuses to authorize it error after keycloak login

我目前正在尝试配置 Tomcat 8 网络应用程序以使用 Keycloak 作为身份提供者。我按照 official keycloak documentation 上的说明进行操作,并将用户角色 'user' 添加到我的 Keycloak 领域,用户应该必须能够访问该网络应用程序。 在 web.xml 中,我还将此角色添加到身份验证约束中。 这是我的 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 中指定的角色。

我自己修好了。如果其他人遇到此问题,请在我的 keycloak.json 文件中将“use-resource-role-mappings”设置为 true。将其设置为 false 后一切正常。