8000 Show indicator for transient user in user sessions list in admin ui by thomasdarimont · Pull Request #28882 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
< 8000 td class="blob-code blob-code-inner blob-code-hunk">@@ -97,4 +98,12 @@ public Map<String, String> getClients() {
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
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 @@ -677,6 +677,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