added brute login user temporary lock indication (#259)

* added brute login user temporary lock indication

* spelling
This commit is contained in:
Erik Jan de Wit 2020-12-16 07:58:00 +01:00 committed by GitHub
parent 79e671062c
commit 0a5efbb781
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 10 deletions

View file

@ -22,7 +22,7 @@
"@patternfly/react-table": "4.19.24",
"file-saver": "^2.0.2",
"i18next": "^19.6.2",
"keycloak-admin": "1.14.2",
"keycloak-admin": "1.14.4",
"lodash": "^4.17.20",
"moment": "^2.29.1",
"react": "^16.8.5",

View file

@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useContext, useState } from "react";
import { useTranslation } from "react-i18next";
import {
AlertVariant,
@ -8,18 +8,25 @@ import {
PageSection,
ToolbarItem,
} from "@patternfly/react-core";
import { InfoCircleIcon } from "@patternfly/react-icons";
import { InfoCircleIcon, WarningTriangleIcon } from "@patternfly/react-icons";
import UserRepresentation from "keycloak-admin/lib/defs/userRepresentation";
import { useAdminClient } from "../context/auth/AdminClient";
import { ViewHeader } from "../components/view-header/ViewHeader";
import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable";
import { useAlerts } from "../components/alert/Alerts";
import { RealmContext } from "../context/realm-context/RealmContext";
type BruteUser = UserRepresentation & {
brute?: Record<string, object>;
};
export const UsersSection = () => {
const { t } = useTranslation("users");
const adminClient = useAdminClient();
const { addAlert } = useAlerts();
const { realm: realmName } = useContext(RealmContext);
const [key, setKey] = useState("");
const refresh = () => setKey(`${new Date().getTime()}`);
@ -31,7 +38,24 @@ export const UsersSection = () => {
if (search) {
params.search = search;
}
return await adminClient.users.find({ ...params });
const users = await adminClient.users.find({ ...params });
const realm = await adminClient.realms.findOne({ realm: realmName });
if (realm?.bruteForceProtected) {
const brutes = await Promise.all(
users.map((user: BruteUser) =>
adminClient.attackDetection.findOne({
id: user.id!,
})
)
);
for (let index = 0; index < users.length; index++) {
const user: BruteUser = users[index];
user.brute = brutes[index];
}
}
return users;
};
const deleteUser = async (user: UserRepresentation) => {
@ -44,14 +68,19 @@ export const UsersSection = () => {
}
};
const StatusRow = (user: UserRepresentation) => {
const StatusRow = (user: BruteUser) => {
return (
<>
{!user.enabled && (
<Label color="red" icon={<InfoCircleIcon />}>
<Label key={user.id} color="red" icon={<InfoCircleIcon />}>
{t("disabled")}
</Label>
)}
{user.brute?.disabled && (
<Label key={user.id} color="orange" icon={<WarningTriangleIcon />}>
{t("temporaryDisabled")}
</Label>
)}
</>
);
};

View file

@ -9,6 +9,7 @@
"firstName": "First name",
"status": "Status",
"disabled": "Disabled",
"temporaryDisabled": "Temporarily disabled",
"addUser": "Add user",
"deleteUser": "Delete user",
"userDeletedSuccess": "The user has been deleted",

View file

@ -13207,10 +13207,10 @@ junk@^3.1.0:
resolved "https://registry.yarnpkg.com/junk/-/junk-3.1.0.tgz#31499098d902b7e98c5d9b9c80f43457a88abfa1"
integrity sha512-pBxcB3LFc8QVgdggvZWyeys+hnrNWg4OcZIU/1X59k5jQdLBlCsYGRQaz234SqoRLTCgMH00fY0xRJH+F9METQ==
keycloak-admin@1.14.2:
version "1.14.2"
resolved "https://registry.yarnpkg.com/keycloak-admin/-/keycloak-admin-1.14.2.tgz#5b983a10bcc01573c79d4f3d6eefe74bd35c8d3f"
integrity sha512-eO0jLEVQJ+yk2Xw6B73dDQWhHwR5CjGsdx3zu1csJTTehCy0ftLJVX/BFnlGmQnF1sVYKpXomoCbUtesYYXntQ==
keycloak-admin@1.14.4:
version "1.14.4"
resolved "https://registry.yarnpkg.com/keycloak-admin/-/keycloak-admin-1.14.4.tgz#67f9a0991e88003f23a3c6a9d87c7a11294afd12"
integrity sha512-16/ctPH/Pz+XLL62tQp1d2XziMaPtxjthrfXcr+wfeJYMGH09QQTd1EDJjdFskuhZOhmYlifaAYPanQLwbUFEg==
dependencies:
axios "^0.21.0"
camelize "^1.0.0"