Skip to content

Commit

Permalink
Show indicator for transient user in user sessions list in admin ui (…
Browse files Browse the repository at this point in the history
…28879)

For transient users a transient label is now shown in the realm sessions and client sessions list in the admin ui.

Fixes keycloak#28879

Co-authored-by: Thomas Darimont <thomas.darimont@googlemail.com>
Co-authored-by: Hynek Mlnařík <hmlnarik@users.noreply.github.com>
Signed-off-by: Thomas Darimont <thomas.darimont@googlemail.com>
  • Loading branch information
thomasdarimont and hmlnarik committed Apr 19, 2024
1 parent f9e68cd commit 6861718
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class UserSessionRepresentation {
private long lastAccess;
private boolean rememberMe;
private Map<String, String> clients = new HashMap<>();
private boolean transientUser;

public String getId() {
return id;
Expand Down Expand Up @@ -97,4 +98,12 @@ public Map<String, String> getClients() {
public void setClients(Map<String, String> clients) {
this.clients = clients;
}

public boolean isTransientUser() {
return transientUser;
}

public void setTransientUser(boolean transientUser) {
this.transientUser = transientUser;
}
}
19 changes: 18 additions & 1 deletion js/apps/admin-ui/src/sessions/SessionsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type UserSessionRepresentation from "@keycloak/keycloak-admin-client/lib/defs/userSessionRepresentation";
import {
Button,
Label,
List,
ListItem,
ListVariant,
ToolbarItem,
Tooltip,
} from "@patternfly/react-core";
import { CubesIcon } from "@patternfly/react-icons";
import { CubesIcon, InfoCircleIcon } from "@patternfly/react-icons";
import { MouseEvent, ReactNode, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { Link, useMatch, useNavigate } from "react-router-dom";
Expand Down Expand Up @@ -50,9 +52,24 @@ export type SessionsTableProps = {

const UsernameCell = (row: UserSessionRepresentation) => {
const { realm } = useRealm();
const { t } = useTranslation();
return (
<Link to={toUser({ realm, id: row.userId!, tab: "sessions" })}>
{row.username}
{row.transientUser && (
<>
{" "}
<Tooltip content={t("transientUserTooltip")}>
<Label
data-testid="user-details-label-transient-user"
icon={<InfoCircleIcon />}
isCompact
>
{t("transientUser")}
</Label>
</Tooltip>
</>
)}
</Link>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export default interface UserSessionRepresentation {
start?: number;
userId?: string;
username?: string;
transientUser?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;
import org.keycloak.models.UserSessionModel;
import org.keycloak.models.light.LightweightUserAdapter;
import org.keycloak.services.resources.admin.permissions.AdminPermissionEvaluator;

import jakarta.ws.rs.Consumes;
Expand Down Expand Up @@ -118,6 +119,7 @@ public static SessionRepresentation toRepresentation(UserSessionModel session, S
ClientModel client = clientSession.getClient();
rep.getClients().put(client.getId(), client.getClientId());
}
rep.setTransientUser(LightweightUserAdapter.isLightweightUser(session.getUser().getId()));
return rep;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class SessionRepresentation {
private String ipAddress;
private long start;
private long lastAccess;
private boolean transientUser;

private SessionType type;
private Map<String, String> clients = new HashMap<>();
Expand Down Expand Up @@ -81,6 +82,14 @@ public void setClients(Map<String, String> clients) {
this.clients = clients;
}

public boolean isTransientUser() {
return transientUser;
}

public void setTransientUser(boolean transientUser) {
this.transientUser = transientUser;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ public static UserSessionRepresentation toRepresentation(UserSessionModel sessio
ClientModel client = clientSession.getClient();
rep.getClients().put(client.getId(), client.getClientId());
}
rep.setTransientUser(LightweightUserAdapter.isLightweightUser(session.getUser().getId()));
return rep;
}

Expand Down

0 comments on commit 6861718

Please sign in to comment.