From 577aaebfa90427ad9ad48d4fe1e24703711ff45c Mon Sep 17 00:00:00 2001 From: Kannan Kirishikesan Date: Wed, 20 Mar 2024 10:23:06 +0530 Subject: [PATCH 1/2] Adds mtls oauth optional values --- .../Configuration/RuntimeConfiguration.jsx | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/RuntimeConfiguration.jsx b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/RuntimeConfiguration.jsx index 5d25ef2dcc5..8a1ccbe2671 100644 --- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/RuntimeConfiguration.jsx +++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/RuntimeConfiguration.jsx @@ -46,7 +46,9 @@ import { API_SECURITY_BASIC_AUTH, API_SECURITY_API_KEY, API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_MANDATORY, + API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_OPTIONAL, API_SECURITY_MUTUAL_SSL_MANDATORY, + API_SECURITY_MUTUAL_SSL_OPTIONAL, API_SECURITY_MUTUAL_SSL, } from './components/APISecurity/components/apiSecurityConstants'; import WebSubConfiguration from './components/WebSubConfiguration'; @@ -243,21 +245,26 @@ export default function RuntimeConfiguration() { return { ...copyAPIConfig(state), [action]: value }; case 'securityScheme': // If event came from mandatory selector of either Application level or Transport level - if ( - [API_SECURITY_MUTUAL_SSL_MANDATORY, API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_MANDATORY] - .includes(event.name) - ) { - // If user select not mandatory (optional) , Remove the respective schema, else add it - if (event.value === 'optional') { - return { - ...copyAPIConfig(state), - [action]: state[action].filter((schema) => schema !== event.name), - }; - } else if (state[action].includes(event.name)) { - return state; // Add for completeness, Ideally there couldn't exist this state - } else { - return { ...copyAPIConfig(state), [action]: [...state[action], event.name] }; - } + if (API_SECURITY_MUTUAL_SSL_MANDATORY === event.name) { + const filteredArray = state[action] + .filter((schema) => (schema !== API_SECURITY_MUTUAL_SSL_MANDATORY + && schema !== API_SECURITY_MUTUAL_SSL_OPTIONAL)) + .concat(event.value); + const newState = { + ...copyAPIConfig(state), + [action]: filteredArray, + }; + return newState; + } else if (API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_MANDATORY === event.name) { + const filteredArray = state[action] + .filter((schema) => (schema !== API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_MANDATORY + && schema !== API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_OPTIONAL)) + .concat(event.value); + const newState = { + ...copyAPIConfig(state), + [action]: filteredArray, + }; + return newState; } // User checked on one of api security schemas (either OAuth, Basic, ApiKey or Mutual SSL) if (event.checked) { From 225098d358db6b5c98e36311185ba78d50f7b619 Mon Sep 17 00:00:00 2001 From: Kannan Kirishikesan Date: Fri, 22 Mar 2024 09:43:31 +0530 Subject: [PATCH 2/2] Reflect changes in security scheme in UI --- .../Configuration/RuntimeConfiguration.jsx | 38 ++++++++++++++++--- .../components/ApplicationLevel.jsx | 4 ++ .../APISecurity/components/TransportLevel.jsx | 4 ++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/RuntimeConfiguration.jsx b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/RuntimeConfiguration.jsx index 55cab9cd7df..40184214582 100644 --- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/RuntimeConfiguration.jsx +++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/RuntimeConfiguration.jsx @@ -270,9 +270,21 @@ export default function RuntimeConfiguration() { if (event.checked) { if (state[action].includes(event.value)) { return state; // Add for completeness, Ideally there couldn't exist this state - } else { - return { ...copyAPIConfig(state), [action]: [...state[action], event.value] }; + } else if (event.value === API_SECURITY_MUTUAL_SSL + && event.value !== DEFAULT_API_SECURITY_OAUTH2 + && event.value !== API_SECURITY_BASIC_AUTH + && event.value !== API_SECURITY_API_KEY) { + return { ...copyAPIConfig(state), + [action]: [...state[action], event.value, API_SECURITY_MUTUAL_SSL_MANDATORY] }; + } else if (event.value !== API_SECURITY_MUTUAL_SSL + && (event.value === DEFAULT_API_SECURITY_OAUTH2 + || event.value === API_SECURITY_BASIC_AUTH + || event.value === API_SECURITY_API_KEY)) { + return { ...copyAPIConfig(state), + [action]: [...state[action], event.value, + API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_MANDATORY] }; } + return { ...copyAPIConfig(state), [action]: [...state[action], event.value] }; } else if (state[action].includes(event.value)) { // User has unchecked a security schema type const newState = { @@ -287,17 +299,31 @@ export default function RuntimeConfiguration() { ) ) { const noMandatoryOAuthBasicAuth = newState[action] - .filter((schema) => schema !== API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_MANDATORY); + .filter((schema) => (schema !== API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_MANDATORY + && schema !== API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_OPTIONAL + && schema !== API_SECURITY_MUTUAL_SSL_MANDATORY + && schema !== API_SECURITY_MUTUAL_SSL_OPTIONAL)); + const newSecurityScheme = newState[action].includes(API_SECURITY_MUTUAL_SSL) ? + [...noMandatoryOAuthBasicAuth, API_SECURITY_MUTUAL_SSL_MANDATORY] + : noMandatoryOAuthBasicAuth; return { ...newState, - [action]: noMandatoryOAuthBasicAuth, + [action]: newSecurityScheme, }; } else if (!newState[action].includes(API_SECURITY_MUTUAL_SSL)) { const noMandatoryMutualSSL = newState[action] - .filter((schema) => schema !== API_SECURITY_MUTUAL_SSL_MANDATORY); + .filter((schema) => (schema !== API_SECURITY_MUTUAL_SSL_MANDATORY + && schema !== API_SECURITY_MUTUAL_SSL_OPTIONAL + && schema !== API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_MANDATORY + && schema !== API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_OPTIONAL)); + const newSecurityScheme = (newState[action].includes(DEFAULT_API_SECURITY_OAUTH2) + || newState[action].includes(API_SECURITY_BASIC_AUTH) + || newState[action].includes(API_SECURITY_API_KEY)) ? + [...noMandatoryMutualSSL, API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_MANDATORY] + : noMandatoryMutualSSL; return { ...newState, - [action]: noMandatoryMutualSSL, + [action]: newSecurityScheme, }; } diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/components/APISecurity/components/ApplicationLevel.jsx b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/components/APISecurity/components/ApplicationLevel.jsx index 7cf8cfe0add..fba45119e40 100644 --- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/components/APISecurity/components/ApplicationLevel.jsx +++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/components/APISecurity/components/ApplicationLevel.jsx @@ -148,6 +148,10 @@ export default function ApplicationLevel(props) { const [mandatoryValueRef, setMandatoryValueRef] = useState(mandatoryValue); + useEffect(() => { + setMandatoryValueRef(mandatoryValue); + }); + return ( ( diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/components/APISecurity/components/TransportLevel.jsx b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/components/APISecurity/components/TransportLevel.jsx index 306874c6587..bc9669479ad 100644 --- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/components/APISecurity/components/TransportLevel.jsx +++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Configuration/components/APISecurity/components/TransportLevel.jsx @@ -219,6 +219,10 @@ function TransportLevel(props) { const [mandatoryValueRef, setMandatoryValueRef] = useState(mandatoryValue); + useEffect(() => { + setMandatoryValueRef(mandatoryValue); + }); + return ( (