From f6fe8ce95d31514ce089a3802662dfbe4983ef60 Mon Sep 17 00:00:00 2001 From: Thisal Tennakoon Date: Fri, 15 Sep 2023 01:54:04 +0530 Subject: [PATCH 1/2] Initial commit --- .../Details/AsyncApiConsole/AsyncApiUI.jsx | 4 +- .../RuntimeConfigurationWebSocket.jsx | 118 ++++++++++++++---- 2 files changed, 99 insertions(+), 23 deletions(-) diff --git a/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/AsyncApiConsole/AsyncApiUI.jsx b/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/AsyncApiConsole/AsyncApiUI.jsx index 266392e0731..84987cf32ba 100644 --- a/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/AsyncApiConsole/AsyncApiUI.jsx +++ b/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/AsyncApiConsole/AsyncApiUI.jsx @@ -149,13 +149,13 @@ export default function AsyncApiUI(props) { function generateWSSubscriptionCommand(topic) { const token = generateAccessToken(); if (topic.name.includes('*')) { - let wscat = `wscat -c '${endPoint}' -H 'Authorization: ${token}'`; + let wscat = `wscat -c '${endPoint}' -H '${securitySchemeType === 'API-KEY' ? 'apikey' : 'Authorization'}: ${token}'`; if (isAdvertised && authorizationHeader !== '') { wscat = `wscat -c '${endPoint}' -H '${authorizationHeader}: ${token}'`; } return wscat; } else { - let wscat = `wscat -c '${endPoint}/${getTopicName(topic)}' -H 'Authorization: ${token}'`; + let wscat = `wscat -c '${endPoint}/${getTopicName(topic)}' -H '${securitySchemeType === 'API-KEY' ? 'apikey': 'Authorization'}: ${token}'`; if (isAdvertised && authorizationHeader !== '') { wscat = `wscat -c '${endPoint}/${getTopicName(topic)}' -H '${authorizationHeader}: ${token}'`; } diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/RuntimeConfigurationWebSocket.jsx b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/RuntimeConfigurationWebSocket.jsx index a554a150169..f29172bec1d 100644 --- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/RuntimeConfigurationWebSocket.jsx +++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/RuntimeConfigurationWebSocket.jsx @@ -24,6 +24,13 @@ import Paper from '@material-ui/core/Paper'; import { Link, useHistory } from 'react-router-dom'; import Box from '@material-ui/core/Box'; import Button from '@material-ui/core/Button'; +import FormGroup from '@material-ui/core/FormGroup'; +import ExpansionPanelDetails from '@material-ui/core/ExpansionPanelDetails'; +import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; +import ExpansionPanelSummary from '@material-ui/core/ExpansionPanelSummary'; +import WrappedExpansionPanel from 'AppComponents/Shared/WrappedExpansionPanel'; +import Checkbox from '@material-ui/core/Checkbox'; +import FormControlLabel from '@material-ui/core/FormControlLabel'; import { FormattedMessage } from 'react-intl'; import Alert from 'AppComponents/Shared/Alert'; import ArrowForwardIcon from '@material-ui/icons/SettingsEthernet'; @@ -34,6 +41,10 @@ import API from 'AppData/api'; import Endpoints from './components/Endpoints'; import KeyManager from './components/KeyManager'; import APILevelRateLimitingPolicies from './components/APILevelRateLimitingPolicies'; +import { + DEFAULT_API_SECURITY_OAUTH2, + API_SECURITY_API_KEY +} from './components/APISecurity/components/apiSecurityConstants'; const useStyles = makeStyles((theme) => ({ root: { @@ -95,6 +106,9 @@ const useStyles = makeStyles((theme) => ({ display: 'flex', height: '100%', }, + error: { + color: theme.palette.error.main, + } })); /** @@ -177,6 +191,13 @@ export default function RuntimeConfiguration() { nextState.keyManagers = ['all']; } return nextState; + case 'securityScheme': + if (value.checked) { + nextState.securityScheme = [...nextState.securityScheme, value.value]; + } else { + nextState.securityScheme = nextState.securityScheme.filter((item) => item !== value.value); + } + return nextState; default: return state; } @@ -187,6 +208,23 @@ export default function RuntimeConfiguration() { const [apiConfig, configDispatcher] = useReducer(configReducer, copyAPIConfig(api)); const classes = useStyles(); + const Validate = () => { + + if (!apiConfig.securityScheme.includes(DEFAULT_API_SECURITY_OAUTH2) + && !apiConfig.securityScheme.includes(API_SECURITY_API_KEY) + ) { + return ( + + + + ); + } + return null; + }; + /** * * Handle the configuration view save button action @@ -232,27 +270,65 @@ export default function RuntimeConfiguration() {
- - - -
- - - - - - - - - -
+ + }> + + + + + + + + + + configDispatcher({ + action: 'securityScheme', + value: { checked, value }, + })} + value={DEFAULT_API_SECURITY_OAUTH2} + color='primary' + /> + )} + label='OAuth2' + /> + configDispatcher({ + action: 'securityScheme', + value: { checked, value }, + })} + value={API_SECURITY_API_KEY} + color='primary' + id='api-security-api-key-checkbox' + /> + )} + label='Api Key' + /> + + + + + + + + +
From bd4bcad7274de41e5762e7699062ac61f598e940 Mon Sep 17 00:00:00 2001 From: Thisal Tennakoon <42693357+thisaltennakoon@users.noreply.github.com> Date: Tue, 2 Jan 2024 12:25:35 +0530 Subject: [PATCH 2/2] Update RuntimeConfigurationWebSocket.jsx --- .../Details/Configuration/RuntimeConfigurationWebSocket.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/RuntimeConfigurationWebSocket.jsx b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/RuntimeConfigurationWebSocket.jsx index f29172bec1d..3d780e06df6 100644 --- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/RuntimeConfigurationWebSocket.jsx +++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/RuntimeConfigurationWebSocket.jsx @@ -217,7 +217,7 @@ export default function RuntimeConfiguration() { );