Keycloak 策略执行器不起作用,Sprint 启动应用程序。
我使用带有 Keycloak 版本 10.0.2 的 spring boot v 2.3.1,我需要在我的应用程序中设置策略执行器,使用 keycloak 工作的身份验证部分,但是如果我将策略执行器配置添加到 application.properties,则出现错误
===================>application.properties 文件:
server.port = 8082
# keycloak config
keycloak.realm = my-realm
keycloak.auth-server-url = http://localhost:8080/auth
keycloak.resource = resource_server
keycloak.credentials.secret = 1adb9e31-cd6a-4eb5-95c5-6a45e972b64a
keycloak.ssl-required=external
keycloak.public-client = true
keycloak.bearer-only = true
#keycloak.verify-token-audience = true
keycloak.cors=true
keycloak.use-resource-role-mappings = true
keycloak.confidential-port=0
keycloak.principal-attribute=preferred_username
keycloak.policy-enforcer-config.enforcement-mode= PERMISSIVE
keycloak.policy-enforcer-config.lazy-load-paths=true
keycloak.policy-enforcer-config.paths[0].name=page_resource
keycloak.policy-enforcer-config.paths[0].path=/uma-protected-resource
keycloak.policy-enforcer-config.paths[0].methods[0].method=GET
keycloak.policy-enforcer-config.paths[0].methods[0].scopes[0]= view
================>在 keycloak 中测试用户评估:
Result
*PERMIT
Scopes
*view
*edit
*delete
Policies
*edit_permission_resource(User-Managed Policy)
decision was PERMIT by AFFIRMATIVE decision. Granted Scopes: edit.
*view_permission_resource(User-Managed Policy)
decision was PERMIT by AFFIRMATIVE decision. Granted Scopes: view.
*delete_permission_resource(User-Managed Policy)
decision was PERMIT by AFFIRMATIVE decision. Granted Scopes: delete.
================>** 错误日志**:
java.lang.RuntimeException:获取策略执行器失败
at org.keycloak.adapters.KeycloakDeployment.getPolicyEnforcer.... at org.keycloak.adapters.AuthenticatedActionsHandler.corsRequest... at ... at ...
引起: java.lang.RuntimeException:找不到资源
at ... at ...
引起:引起:org.keycloak.authorization.client.util.HttpResponseException:来自服务器的意外响应:401 /未经授权
at ... at ...
我使用具有正确权限的 et 用户令牌,但我不知道为什么它不起作用。我想,他在 kaycloak 上找不到资源,但他在那里有正确的权利
keycloak 中的客户端:resource_server https://i.stack.imgur.com/d3huA.png https://i.stack.imgur.com/o9xDc.png
keycloak 中的资源 https://i.stack.imgur.com/mslnu.png
谢谢你的帮助 :)