access_denied 客户端用户出错,即使 keycloak 评估说允许

access_denied error for client user even though keycloak evaluation says permit

我有多个资源,每个资源都指向应用程序上的一个页面。我正在使用 keycloak (v10.0.2) 来验证请求。我有两个用户,管理员和客户。管理员可以访问所有资源,而客户只能访问少数资源。在 keycloak 上分配权限后,我在控制台上进行了评估,并确保按照我的意愿授予资源权限。

现在,当以管理员身份访问应用程序时,所有资源都可以正常访问。但是当以客户端身份登录时,登录和几个页面工作正常,但其余页面失败 OAuth2AuthenticationProcessingFilter。以下是来自日志的消息。

DEBUG o.s.security.web.FilterChainProxy.doFilter - /services/customerAPI/listOfCustomers at position 6 of 12 in additional filter chain; firing Filter: 'OAuth2AuthenticationProcessingFilter'
DEBUG o.s.s.o.p.a.OAuth2AuthenticationProcessingFilter.doFilter - Authentication request failed: error="access_denied", error_description="Invalid token does not contain resource id (ums)"
DEBUG o.s.s.w.h.writers.HstsHeaderWriter.writeHeaders - Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@8ff0a24
DEBUG o.s.s.o.p.e.DefaultOAuth2ExceptionRenderer.writeWithMessageConverters - Written [error="access_denied", error_description="Invalid token does not contain resource id (ums)"] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@5adada73]
DEBUG o.s.s.w.c.SecurityContextPersistenceFilter.doFilter - SecurityContextHolder now cleared, as request processing completed

有人可以帮我找出我做错了什么吗?

将默认客户端角色 uma_protection 分配给 "Client" 用户解决了该问题。