【发布时间】:2019-10-15 03:53:33
【问题描述】:
我已经从 Keycloak 的 OIDC 端点提取了用户的组信息,但它们没有附带我定义的组属性(请参阅组表单中的属性选项卡,靠近设置)。是否有要添加到我的请求中的声明?
我正在使用 RESTeasy 客户端访问 Keycloak 的管理 API(比使用提供的管理客户端的结果要好得多):
@Path("/admin/realms/{realm}")
public interface KeycloakAdminService {
@GET
@Path("/users/{id}/groups")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
List<GroupRepresentation> getUserGroups(@PathParam("realm") String realm, @PathParam("id") String userId,
@HeaderParam(AUTHORIZATION) String accessToken);
//DEBUG the access token must always be prefixed by "Bearer "
}
所以我可以获取用户的组:
private void fetchUserGroups(UserInfoOIDC infos, String userId) {
log.info("Fetching user groups from {}...", getRealm());
try {
KeycloakAdminService proxy = kcTarget.proxy(KeycloakAdminService.class);
AccessTokenResponse response = authzClient.obtainAccessToken(getAdminUsername(), getAdminPassword());
List<GroupRepresentation> groups = proxy.getUserGroups(getRealm(), userId,
"Bearer " + response.getToken());
infos.importUserGroups(groups); //DEBUG here we go!
} catch (WebApplicationException e) {
log.error("User groups failure on {}: {}", getRealm(), e.getMessage());
}
}
但是当涉及到数据探索时,结果发现 GroupRepresentation#getAttributes 结构中没有提供任何属性。
我了解到可以将声明添加到用户信息请求中。它适用于管理 API 吗?如何使用 RESTeasy 模板实现该结果? 谢谢
【问题讨论】:
-
我还在 Keycloak 的文档中读到了这一点:“组管理用户组。可以为组定义属性。您也可以将角色映射到组。成为 a 成员的用户组继承了组定义的属性和角色映射";是说我宁愿直接在用户信息中查找这些属性吗?但他们也没有出现,所以我的问题仍然存在......
-
对不起,法国假期...我会试一试,尽快回复你
标签: resteasy openid-connect keycloak-services