diff --git a/admin-ui/app/locales/en/translation.json b/admin-ui/app/locales/en/translation.json index a0704d4d7..9ad6a8b69 100644 --- a/admin-ui/app/locales/en/translation.json +++ b/admin-ui/app/locales/en/translation.json @@ -25,7 +25,8 @@ "yes": "Yes", "change_password": "Change Password", "close": "Close", - "delete": "Delete" + "delete": "Delete", + "revoke": "Revoke" }, "dashboard": { "summary_title": "Actives Users & Access Token Stats", @@ -300,7 +301,8 @@ "creationTime": "Creation Time", "select_date_range":"Select a date range", "scope": "Scope", - "scopeExpression": "Scope Expression" + "scopeExpression": "Scope Expression", + "selectUserRevoke": "Select the user to revoke" }, "languages": { "french": "French", diff --git a/admin-ui/app/locales/fr/translation.json b/admin-ui/app/locales/fr/translation.json index 1c0e4e6d0..9b893468f 100644 --- a/admin-ui/app/locales/fr/translation.json +++ b/admin-ui/app/locales/fr/translation.json @@ -91,7 +91,8 @@ "view": "Vue", "yes": "Oui", "close": "Fermer", - "delete": "Supprimez" + "delete": "Supprimez", + "revoke": "Révoquer" }, "fields": { "access_token_signing_alg": "Algorithme de signature de jeton d'accès", @@ -287,7 +288,8 @@ "associatedClient": "Client associé", "creationTime": "Heure de création", "portée": "Portée", - "scopeExpression": "Expression d'étendue" + "scopeExpression": "Expression d'étendue", + "selectUserRevoke": "Sélectionnez l'utilisateur à révoquer" }, "messages": { "action_commit_question": "Journal d'audit : vous souhaitez appliquer les modifications apportées sur cette page ?", diff --git a/admin-ui/app/locales/pt/translation.json b/admin-ui/app/locales/pt/translation.json index 274f7989a..2be82dfdc 100644 --- a/admin-ui/app/locales/pt/translation.json +++ b/admin-ui/app/locales/pt/translation.json @@ -89,7 +89,8 @@ "view": "Visualizar", "yes": "Sim", "close": "Fechar", - "delete": "Deletar" + "delete": "Deletar", + "revoke": "Revogar" }, "fields": { "access_token_signing_alg": "Algoritmo de assinatura de token de acesso", @@ -281,7 +282,8 @@ "associatedClient": "Cliente Associado", "creationTime": "Tempo de Criação", "escopo": "Escopo", - "scopeExpression": "Expressão de escopo" + "scopeExpression": "Expressão de escopo", + "selectUserRevoke": "Selecione o usuário para revogar" }, "messages": { "action_commit_question": "Registro de auditoria: deseja aplicar as alterações feitas nesta página?", diff --git a/admin-ui/app/utils/PermChecker.js b/admin-ui/app/utils/PermChecker.js index 09e55666a..32c876a1f 100644 --- a/admin-ui/app/utils/PermChecker.js +++ b/admin-ui/app/utils/PermChecker.js @@ -90,9 +90,12 @@ export const STAT_JANS_READ = 'jans_stat' export const USER_READ = BASE_URL + '/config/user.readonly' export const USER_WRITE = BASE_URL + '/config/user.write' +export const SESSION_READ = BASE_URL + '/jans-auth-server/session.readonly' +export const SESSION_DELETE = BASE_URL + '/jans-auth-server/session.delete' + export const hasPermission = (scopes, scope) => { if (scopes) { - return scopes.includes(scope, 0) + return scopes.map(scp => scope === scp) } return false } diff --git a/admin-ui/plugins/auth-server/components/Sessions/SessionListPage.js b/admin-ui/plugins/auth-server/components/Sessions/SessionListPage.js index f0c9207dc..e4893ff2b 100644 --- a/admin-ui/plugins/auth-server/components/Sessions/SessionListPage.js +++ b/admin-ui/plugins/auth-server/components/Sessions/SessionListPage.js @@ -1,9 +1,11 @@ import React, { useState, useEffect, useContext } from 'react' import moment from 'moment' +import isEmpty from 'lodash/isEmpty' import MaterialTable from '@material-table/core' -import { DeleteOutlined } from '@material-ui/icons' -import { Paper } from '@material-ui/core' +import Autocomplete from '@material-ui/lab/Autocomplete' +import { Paper, TextField, Box } from '@material-ui/core' import { connect } from 'react-redux' +import { Button } from 'reactstrap' import { Card, CardBody } from 'Components' import GluuViewWrapper from 'Routes/Apps/Gluu/GluuViewWrapper' import applicationStyle from 'Routes/Apps/Gluu/styles/applicationstyle' @@ -13,8 +15,13 @@ import { getSessions, revokeSession } from 'Plugins/auth-server/redux/actions/Se import SetTitle from 'Utils/SetTitle' import { ThemeContext } from 'Context/theme/themeContext' import getThemeColor from 'Context/theme/config' +import { + hasPermission, + SESSION_DELETE, +} from 'Utils/PermChecker' function SessionListPage({ sessions, permissions, loading, dispatch }) { + console.log('permissions', permissions) const { t } = useTranslation() const myActions = [] const [item, setItem] = useState({}) @@ -25,6 +32,9 @@ function SessionListPage({ sessions, permissions, loading, dispatch }) { const selectedTheme = theme.state.theme const themeColors = getThemeColor(selectedTheme) const bgThemeColor = { background: themeColors.background } + const sessionUsername = sessions.map(session => session.sessionAttributes.auth_user) + const usernames = [...new Set(sessionUsername)] + const [revokeUsername, setRevokeUsername] = useState() SetTitle(t('menus.sessions')) @@ -60,9 +70,12 @@ function SessionListPage({ sessions, permissions, loading, dispatch }) { dispatch(getSessions()) }, []) - const handleRevoke = (row) => { - setItem(row) - toggle() + const handleRevoke = () => { + const row = !isEmpty(sessions) ? sessions.find(({ sessionAttributes }) => sessionAttributes.auth_user === revokeUsername) : null + if (row) { + setItem(row) + toggle() + } } const onRevokeConfirmed = (message) => { @@ -76,6 +89,30 @@ function SessionListPage({ sessions, permissions, loading, dispatch }) { + {hasPermission(permissions, SESSION_DELETE) && ( + + + {t('fields.selectUserRevoke')} + + option} + style={{ width: 300 }} + onChange={(_, value) => setRevokeUsername(value)} + renderInput={(params) => } + /> + {revokeUsername && ( + + )} + + )} , @@ -96,14 +133,16 @@ function SessionListPage({ sessions, permissions, loading, dispatch }) { }} /> - + {!isEmpty(item) && ( + + )} )