Keycloak:检索所有可用的客户端会话 [英] Keycloak: retrieve all available client sessions

查看:252
本文介绍了Keycloak:检索所有可用的客户端会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Keycloak保护我的Spring应用程序(该应用程序在Keycloak中注册为my_app客户端).现在,我想检索该客户端的所有活动会话.如果我可以使用keycloak-admin-client做到这一点,那就太好了,因为我不知道如何在Java中使用Admin Rest API ...

I'm using Keycloak to secure my Spring app (which is registered in Keycloak as my_app client). Now I want to retrieve all active sessions of that client. Would be great if I could do it using keycloak-admin-client, because I couldn't figure out how to use Admin Rest API in java...

到目前为止,我已经尝试过:

So far I've tried this:

Keycloak keycloak=KeycloakBuilder.builder()
    .serverUrl("http://localhost:8180/auth")
    .realm("master")
    .username("admin")
    .password("admin")
    .clientId("admin-cli")
    .resteasyClient(new ResteasyClientBuilder().connectionPoolSize(10).build()).build();

ClientResource client=keycloak.realm("MY_REALM").clients().get("my_app").getUserSessions(1,100);

但是会引发404错误.

But it throws 404 error.

推荐答案

List clientRepresentations=keycloak.realm("MY_REALM").clients().findByClientId("my_app"); ClientRepresentation representation=clientRepresentations.get(0); ClientResource resource=keycloak.realm("MY_REALM").clients().get(representation.getId());

List clientRepresentations=keycloak.realm("MY_REALM").clients().findByClientId("my_app"); ClientRepresentation representation=clientRepresentations.get(0); ClientResource resource=keycloak.realm("MY_REALM").clients().get(representation.getId());

成功了.

这将检索客户端中的所有活动会话:

And this retrieves all active sessions in client:

List sessions=resource.getUserSessions(0,1000);

List sessions=resource.getUserSessions(0,1000);

这篇关于Keycloak:检索所有可用的客户端会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆