使用 keycloak rest admin api 获取给定部分 url 路径或基于正则表达式模式的资源

Csh*_*hah 0 api rest authorization keycloak

有没有办法使用rest admin api获取给定部分url的资源ID?

下面是我调用的端点 - http://localhost:8180/auth/realms/quickstart-serv-springboot/authz/protection/resource_set?uri=/wb/customer来获取资源 ID。

我想知道是否可以在uri的查询字符串中传递通配符,以便它返回资源ID。例如 -http://localhost:8180/auth/realms/quickstart-serv-springboot/authz/protection/resource_set?uri=/wb/customer/*http://localhost:8180/auth/realms/quickstart-serv-springboot/authz/protection/resource_set?uri=/wb/cust*提供一个正则表达式模式来获取匹配的资源 ID。

谢谢

Yur*_*y P 5

从源代码看来,它的工作方式如下:

  1. 第一个 Keycloak 尝试找到完全匹配
  2. 然后如果没有找到匹配项并且有参数“matchingUri=true”,它将尝试通过模式匹配来查找资源。

我没有检查,但建议在您的查询中添加“matchingUri=true”,然后重试。

还要注意不支持复杂模式。Keycloak 文档说:

Currently a very basic logic for path matching is supported. Examples of valid paths are:
Wildcards: /*
Suffix: /*.html
Sub-paths: /path/*
Path parameters: /resource/{id}
Exact match: /resource
Patterns: /{version}/resource, /api/{version}/resource, /api/{version}/resource/*
Run Code Online (Sandbox Code Playgroud)