Skip to content

Commit

Permalink
Merge pull request #541 from prasa7/global_km
Browse files Browse the repository at this point in the history
Global key manager UI implementation
  • Loading branch information
npamudika authored Feb 13, 2024
2 parents 85cde12 + 65f1a93 commit 0ccfde9
Show file tree
Hide file tree
Showing 8 changed files with 676 additions and 123 deletions.
24 changes: 24 additions & 0 deletions portals/admin/src/main/webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions portals/admin/src/main/webapp/site/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@
"KeyManagers.AddEditKeyManager.selfvalidate": "Self validate JWT",
"KeyManagers.AddEditKeyManager.space.error": "Key Manager name contains white spaces.",
"KeyManagers.AddEditKeyManager.title.edit": "Key Manager - Edit ",
"KeyManagers.AddEditKeyManager.title.editGlobal": "Global Key Manager - Edit ",
"KeyManagers.AddEditKeyManager.title.new": "Key Manager - Create new",
"KeyManagers.AddEditKeyManager.title.newGlobal": "Global Key Manager - Create new",
"KeyManagers.AddEditKeyManager.token.handling.options": "Token Handling Options",
"KeyManagers.AddEditKeyManager.token.validation.method": "Token Validation Method",
"KeyManagers.AddEditKeyManager.useIntrospect": "Use introspect",
Expand All @@ -304,10 +306,9 @@
"KeyManagers.ImportConfig.dialog.trigger.import": "Import",
"KeyManagers.ImportConfig.form.url": "Url",
"KeyManagers.ImportConfig.form.url.help": "Provide Url",
"KeyManagers.ListKeyManagers.List.addButtonProps.title": "Add Key Manager",
"KeyManagers.ListKeyManagers.List.addButtonProps.triggerButtonText": "Add Key Manager",
"KeyManagers.ListKeyManagers.List.title": "Key Managers",
"KeyManagers.ListKeyManagers.addButtonProps.triggerButtonText": "Add Key Manager",
"KeyManagers.ListKeyManagers.addGlobalKeyManager": "Add Global Key Manager",
"KeyManagers.ListKeyManagers.edit.success": " Key Manager updated successfully.",
"KeyManagers.ListKeyManagers.empty.title": "Key Managers",
"KeyManagers.ListKeyManagers.table.header.label.description": "Description",
Expand Down
5 changes: 3 additions & 2 deletions portals/admin/src/main/webapp/site/public/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@
"KeyManagers.AddEditKeyManager.selfvalidate": "",
"KeyManagers.AddEditKeyManager.space.error": "",
"KeyManagers.AddEditKeyManager.title.edit": "",
"KeyManagers.AddEditKeyManager.title.editGlobal": "",
"KeyManagers.AddEditKeyManager.title.new": "",
"KeyManagers.AddEditKeyManager.title.newGlobal": "",
"KeyManagers.AddEditKeyManager.token.handling.options": "",
"KeyManagers.AddEditKeyManager.token.validation.method": "",
"KeyManagers.AddEditKeyManager.useIntrospect": "",
Expand All @@ -303,10 +305,9 @@
"KeyManagers.ImportConfig.dialog.trigger.import": "",
"KeyManagers.ImportConfig.form.url": "",
"KeyManagers.ImportConfig.form.url.help": "",
"KeyManagers.ListKeyManagers.List.addButtonProps.title": "",
"KeyManagers.ListKeyManagers.List.addButtonProps.triggerButtonText": "",
"KeyManagers.ListKeyManagers.List.title": "",
"KeyManagers.ListKeyManagers.addButtonProps.triggerButtonText": "",
"KeyManagers.ListKeyManagers.addGlobalKeyManager": "",
"KeyManagers.ListKeyManagers.edit.success": "",
"KeyManagers.ListKeyManagers.empty.title": "",
"KeyManagers.ListKeyManagers.table.header.label.description": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import KeyValidations from 'AppComponents/KeyManagers/KeyValidations';
import PropTypes from 'prop-types';
import Radio from '@material-ui/core/Radio';
import RadioGroup from '@material-ui/core/RadioGroup';
import { Link as RouterLink } from 'react-router-dom';
import { Link as RouterLink, useLocation } from 'react-router-dom';
import Select from '@material-ui/core/Select';
import TextField from '@material-ui/core/TextField';
import cloneDeep from 'lodash.clonedeep';
Expand Down Expand Up @@ -201,10 +201,13 @@ function AddEditKeyManager(props) {
const [isResidentKeyManager, setIsResidentKeyManager] = useState(false);
const [isTokenTypeSelected, setIsTokenTypeSelected] = useState(true);
const { match: { params: { id } }, history } = props;
const { settings } = useAppContext();
const [validRoles, setValidRoles] = useState([]);
const [invalidRoles, setInvalidRoles] = useState([]);
const [roleValidity, setRoleValidity] = useState(true);
const { settings, isSuperTenant, user: { _scopes } } = useAppContext();
const location = useLocation();
const { isGlobal } = (location && location.state) || false;
const isSuperAdmin = isSuperTenant && _scopes.includes('apim:admin_settings');

const defaultKMType = (settings.keyManagerConfiguration
&& settings.keyManagerConfiguration.length > 0)
Expand Down Expand Up @@ -328,7 +331,8 @@ function AddEditKeyManager(props) {
};
useEffect(() => {
if (id) {
restApi.keyManagerGet(id).then((result) => {
const api = isGlobal ? restApi.globalKeyManagerGet(id) : restApi.keyManagerGet(id);
api.then((result) => {
let editState;
if (result.body.name !== null) {
const newTokenValidation = (result.body.tokenValidation.length === 0)
Expand Down Expand Up @@ -515,12 +519,15 @@ function AddEditKeyManager(props) {
permissionType: state.permissions.permissionStatus,
roles: validRoles,
},
global: isGlobal,
};

if (id) {
promisedAddKeyManager = restApi.updateKeyManager(id, keymanager);
promisedAddKeyManager = isGlobal
? restApi.updateGlobalKeyManager(id, keymanager) : restApi.updateKeyManager(id, keymanager);
} else {
promisedAddKeyManager = restApi.addKeyManager(keymanager);
promisedAddKeyManager = isGlobal
? restApi.addGlobalKeyManager(keymanager) : restApi.addKeyManager(keymanager);
promisedAddKeyManager
.then(() => {
return (intl.formatMessage({
Expand Down Expand Up @@ -616,18 +623,29 @@ function AddEditKeyManager(props) {
setExpanded(!expanded);
};

let pageTitle;
if (isGlobal) {
pageTitle = id ? `${intl.formatMessage({
id: 'KeyManagers.AddEditKeyManager.title.editGlobal',
defaultMessage: 'Global Key Manager - Edit ',
})} ${name}` : intl.formatMessage({
id: 'KeyManagers.AddEditKeyManager.title.newGlobal',
defaultMessage: 'Global Key Manager - Create new',
});
} else {
pageTitle = id ? `${intl.formatMessage({
id: 'KeyManagers.AddEditKeyManager.title.edit',
defaultMessage: 'Key Manager - Edit ',
})} ${name}` : intl.formatMessage({
id: 'KeyManagers.AddEditKeyManager.title.new',
defaultMessage: 'Key Manager - Create new',
});
}

return (
<ContentBase
pageStyle='half'
title={
id ? `${intl.formatMessage({
id: 'KeyManagers.AddEditKeyManager.title.edit',
defaultMessage: 'Key Manager - Edit ',
})} ${name}` : intl.formatMessage({
id: 'KeyManagers.AddEditKeyManager.title.new',
defaultMessage: 'Key Manager - Create new',
})
}
title={pageTitle}
help={<div />}
>
{importingConfig && (
Expand Down Expand Up @@ -2161,7 +2179,13 @@ function AddEditKeyManager(props) {
</Grid>
<Grid item xs={12}>
<Box component='span' m={1}>
<Button id='keymanager-add' variant='contained' color='primary' onClick={formSaveCallback}>
<Button
id='keymanager-add'
variant='contained'
color='primary'
onClick={formSaveCallback}
disabled={isGlobal && !isSuperAdmin}
>
{saving ? (<CircularProgress size={16} />) : (
<>
{id ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,24 @@ import { FormattedMessage } from 'react-intl';
import DialogContentText from '@material-ui/core/DialogContentText';
import DeleteForeverIcon from '@material-ui/icons/DeleteForever';
import FormDialogBase from 'AppComponents/AdminPages/Addons/FormDialogBase';
import { useAppContext } from 'AppComponents/Shared/AppContext';

/**
* Render delete dialog box.
* @param {JSON} props component props.
* @returns {JSX} Loading animation.
*/
function Delete({ updateList, dataRow }) {
const { id, type } = dataRow;
const { id, type, isGlobal } = dataRow;
const { isSuperTenant, user: { _scopes } } = useAppContext();
const isSuperAdmin = isSuperTenant && _scopes.includes('apim:admin_settings');

const formSaveCallback = () => {
// todo: don't create a new promise
const promiseAPICall = new Promise((resolve, reject) => {
const restApi = new API();
restApi
.deleteKeyManager(id)
const api = isGlobal ? restApi.deleteGlobalKeyManager(id) : restApi.deleteKeyManager(id);
api
.then(() => {
resolve(
<FormattedMessage
Expand Down Expand Up @@ -65,7 +68,7 @@ function Delete({ updateList, dataRow }) {
triggerIconProps={{
color: 'primary',
component: 'span',
disabled: type === 'default',
disabled: type === 'default' || (isGlobal && !isSuperAdmin),
}}
>
<DialogContentText>
Expand Down
Loading

0 comments on commit 0ccfde9

Please sign in to comment.