1

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);

But it throws 404 error.

hong4rc
  • 3,999
  • 4
  • 21
  • 40

1 Answers1

3

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());

did the trick.

And this retrieves all active sessions in client:

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