From c6e42195cc25f630f24e7778b3fb27e82c465cd1 Mon Sep 17 00:00:00 2001 From: rmsamitha Date: Tue, 5 Nov 2024 21:15:48 +0530 Subject: [PATCH] Introduce proxy support for backend oauth security --- .../apimgt/api/model/EndpointSecurity.java | 67 +++++++++++++++++++ .../carbon/apimgt/impl/APIProviderImpl.java | 7 +- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/EndpointSecurity.java b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/EndpointSecurity.java index 3310180d7a3d..f896150cdff0 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/EndpointSecurity.java +++ b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/EndpointSecurity.java @@ -56,6 +56,8 @@ public class EndpointSecurity { private int socketTimeoutDuration = -1; + private ProxyConfigs proxyConfigs; + public EndpointSecurity(EndpointSecurity endpointSecurity) { this.uniqueIdentifier = endpointSecurity.uniqueIdentifier; @@ -72,11 +74,19 @@ public EndpointSecurity(EndpointSecurity endpointSecurity) { this.connectionTimeoutDuration = endpointSecurity.connectionTimeoutDuration; this.connectionRequestTimeoutDuration = endpointSecurity.connectionRequestTimeoutDuration; this.socketTimeoutDuration = endpointSecurity.socketTimeoutDuration; + this.proxyConfigs = endpointSecurity.proxyConfigs; } public EndpointSecurity() { } + public ProxyConfigs getProxyConfigs() { + return proxyConfigs; + } + + public void setProxyConfigs(ProxyConfigs proxyConfigs) { + this.proxyConfigs = proxyConfigs; + } public String getUniqueIdentifier() { @@ -241,6 +251,63 @@ public void setSocketTimeoutDuration(int socketTimeoutDuration) { this.socketTimeoutDuration = socketTimeoutDuration; } + public static class ProxyConfigs { + private boolean proxyEnabled; + private String proxyHost; + private String proxyPort; + private String proxyProtocol; + private String proxyUsername; + private String proxyPassword; + + public boolean isProxyEnabled() { + return proxyEnabled; + } + + public void setProxyEnabled(boolean proxyEnabled) { + this.proxyEnabled = proxyEnabled; + } + + public String getProxyHost() { + return proxyHost; + } + + public void setProxyHost(String proxyHost) { + this.proxyHost = proxyHost; + } + + public String getProxyPort() { + return proxyPort; + } + + public void setProxyPort(String proxyPort) { + this.proxyPort = proxyPort; + } + + public String getProxyProtocol() { + return proxyProtocol; + } + + public void setProxyProtocol(String proxyProtocol) { + this.proxyProtocol = proxyProtocol; + } + + public String getProxyUsername() { + return proxyUsername; + } + + public void setProxyUsername(String proxyUsername) { + this.proxyUsername = proxyUsername; + } + + public String getProxyPassword() { + return proxyPassword; + } + + public void setProxyPassword(String proxyPassword) { + this.proxyPassword = proxyPassword; + } + } + @Override public String toString() { diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java index 66ceeb1f9b8d..a06a898cf5c6 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIProviderImpl.java @@ -1257,10 +1257,12 @@ private void updateEndpointSecurity(API oldApi, API api) throws APIManagementExc endpointSecurity.setClientId(oldEndpointSecurity.getClientId()); endpointSecurity.setClientSecret(oldEndpointSecurity.getClientSecret()); endpointSecurity.setCustomParameters(oldEndpointSecurity.getCustomParameters()); + endpointSecurity.setProxyConfigs(oldEndpointSecurity.getProxyConfigs()); } } - endpointSecurityJson.replace(APIConstants.ENDPOINT_SECURITY_PRODUCTION, new JSONParser() - .parse(new ObjectMapper().writeValueAsString(endpointSecurity))); + endpointSecurityJson.replace(APIConstants.ENDPOINT_SECURITY_PRODUCTION, + new JSONParser().parse( + new ObjectMapper().writeValueAsString(endpointSecurity))); } } if (endpointSecurityJson.get(APIConstants.ENDPOINT_SECURITY_SANDBOX) != null) { @@ -1303,6 +1305,7 @@ private void updateEndpointSecurity(API oldApi, API api) throws APIManagementExc endpointSecurity.setClientId(oldEndpointSecurity.getClientId()); endpointSecurity.setClientSecret(oldEndpointSecurity.getClientSecret()); endpointSecurity.setCustomParameters(oldEndpointSecurity.getCustomParameters()); + endpointSecurity.setProxyConfigs(oldEndpointSecurity.getProxyConfigs()); } } endpointSecurityJson.replace(APIConstants.ENDPOINT_SECURITY_SANDBOX,