Skip to content

Commit 8ecbc0c

Browse files
Add secure vault support for OAuth endpoint level proxy password
1 parent 3b24a0e commit 8ecbc0c

File tree

5 files changed

+54
-14
lines changed

5 files changed

+54
-14
lines changed

Diff for: components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/EndpointSecurity.java

+9
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ public static class ProxyConfigs {
284284
private String proxyProtocol;
285285
private String proxyUsername;
286286
private String proxyPassword;
287+
private String proxyPasswordAlias;
287288

288289
public boolean isProxyEnabled() {
289290
return proxyEnabled;
@@ -332,6 +333,14 @@ public String getProxyPassword() {
332333
public void setProxyPassword(String proxyPassword) {
333334
this.proxyPassword = proxyPassword;
334335
}
336+
337+
public String getProxyPasswordAlias() {
338+
return proxyPasswordAlias;
339+
}
340+
341+
public void setProxyPasswordAlias(String proxyPasswordAlias) {
342+
this.proxyPasswordAlias = proxyPasswordAlias;
343+
}
335344
}
336345

337346
@Override

Diff for: components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConstants.java

+1
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,7 @@ private ConfigParameters() {
18501850
public static final String ENDPOINT_SECURITY_CLIENT_ID = "clientId";
18511851
public static final String ENDPOINT_SECURITY_CLIENT_SECRET = "clientSecret";
18521852
public static final String ENDPOINT_SECURITY_ENABLED = "enabled";
1853+
public static final String ENDPOINT_SECURITY_PROXY_PASSWORD = "proxyPassword";
18531854
public static final String CONNECTION_TIMEOUT_CONFIG_TYPE = "connectionTimeoutConfigType";
18541855
public static final String PROXY_CONFIG_TYPE = "proxyConfigType";
18551856
public static final String CONNECTION_TIMEOUT_DURATION = "connectionTimeoutDuration";

Diff for: components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/GatewayUtils.java

+7
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ public static String retrieveOAuthPasswordAlias(String name, String version, Str
169169
.concat(APIConstants.ENDPOINT_SECURITY_PASSWORD).concat("--").concat(type);
170170
}
171171

172+
public static String retrieveOAuthProxyPasswordAlias(String name, String version, String type) {
173+
174+
return name.concat("--v").concat(version).concat("--")
175+
.concat(APIConstants.ENDPOINT_SECURITY_TYPE_OAUTH).concat("--")
176+
.concat(APIConstants.ENDPOINT_SECURITY_PROXY_PASSWORD).concat("--").concat(type);
177+
}
178+
172179
public static String retrieveBasicAuthAlias(String name, String version, String type) {
173180

174181
return name.concat("--v").concat(version).concat("--").concat(type);

Diff for: components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/TemplateBuilderUtil.java

+19
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,25 @@ private static void addCredentialsToList(String prefix, API api, GatewayAPIDTO g
15171517
gatewayAPIDTO.setCredentialsToBeAdd(addCredentialsToList(passwordDto,
15181518
gatewayAPIDTO.getCredentialsToBeAdd()));
15191519
}
1520+
if (endpointSecurity.has(APIConstants.PROXY_CONFIGS)) {
1521+
org.json.JSONObject proxyConfigs = (org.json.JSONObject) endpointSecurity.get(APIConstants
1522+
.PROXY_CONFIGS);
1523+
if (Boolean.TRUE.equals(proxyConfigs.get(APIConstants.PROXY_ENABLED))) {
1524+
String proxyPassword = (String) proxyConfigs.get(APIConstants.ENDPOINT_SECURITY_PROXY_PASSWORD);
1525+
CredentialDto proxyPasswordDto = new CredentialDto();
1526+
if (StringUtils.isNotEmpty(prefix)) {
1527+
proxyPasswordDto.setAlias(prefix.concat("--").concat(GatewayUtils
1528+
.retrieveOAuthProxyPasswordAlias(api.getId().getApiName(), api.getId().getVersion(),
1529+
type)));
1530+
} else {
1531+
proxyPasswordDto.setAlias(GatewayUtils.retrieveOAuthProxyPasswordAlias(api.getId().getApiName(),
1532+
api.getId().getVersion(), type));
1533+
}
1534+
proxyPasswordDto.setPassword(proxyPassword);
1535+
gatewayAPIDTO.setCredentialsToBeAdd(addCredentialsToList(proxyPasswordDto,
1536+
gatewayAPIDTO.getCredentialsToBeAdd()));
1537+
}
1538+
}
15201539
} else if (APIConstants.ENDPOINT_SECURITY_TYPE_BASIC.equalsIgnoreCase((String)
15211540
endpointSecurity.get(APIConstants.ENDPOINT_SECURITY_TYPE))) {
15221541
CredentialDto credentialDto = new CredentialDto();

Diff for: components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/template/SecurityConfigContext.java

+18-14
Original file line numberDiff line numberDiff line change
@@ -168,24 +168,28 @@ private EndpointSecurityModel retrieveEndpointSecurityModel(EndpointSecurityMode
168168
if (APIConstants.ENDPOINT_SECURITY_TYPE_OAUTH
169169
.equalsIgnoreCase(endpointSecurityModel.getType())) {
170170
if (StringUtils.isNotEmpty(prefix)) {
171-
endpointSecurityModel.setUniqueIdentifier(prefix.concat("--")
172-
.concat(GatewayUtils.retrieveUniqueIdentifier(apiId, type)));
171+
endpointSecurityModel.setUniqueIdentifier(prefix.concat("--").concat(GatewayUtils
172+
.retrieveUniqueIdentifier(apiId, type)));
173+
endpointSecurityModel.setClientSecretAlias(prefix.concat("--").concat(GatewayUtils
174+
.retrieveOauthClientSecretAlias(apiName, version, type)));
175+
endpointSecurityModel.setPasswordAlias(prefix.concat("--").concat(GatewayUtils
176+
.retrieveOAuthPasswordAlias(apiName, version, type)));
177+
if (endpointSecurityModel.getProxyConfigs() != null && endpointSecurityModel.getProxyConfigs()
178+
.isProxyEnabled()) {
179+
endpointSecurityModel.getProxyConfigs().setProxyPasswordAlias(prefix.concat("--")
180+
.concat(GatewayUtils.retrieveOAuthProxyPasswordAlias(apiName, version, type)));
181+
}
173182
} else {
174183
endpointSecurityModel.setUniqueIdentifier(GatewayUtils.retrieveUniqueIdentifier(apiId, type));
175-
}
176-
if (StringUtils.isNotEmpty(prefix)) {
177-
endpointSecurityModel.setClientSecretAlias(prefix.concat("--")
178-
.concat(GatewayUtils.retrieveOauthClientSecretAlias(apiName, version, type)));
179-
} else {
180184
endpointSecurityModel.setClientSecretAlias(GatewayUtils.retrieveOauthClientSecretAlias(apiName,
181185
version, type));
182-
}
183-
if (StringUtils.isNotEmpty(prefix)) {
184-
endpointSecurityModel.setPasswordAlias(prefix.concat("--")
185-
.concat(GatewayUtils.retrieveOAuthPasswordAlias(apiName, version, type)));
186-
} else {
187-
endpointSecurityModel.setPasswordAlias(GatewayUtils.retrieveOAuthPasswordAlias(apiName,
188-
version, type));
186+
endpointSecurityModel.setPasswordAlias(GatewayUtils.retrieveOAuthPasswordAlias(apiName, version,
187+
type));
188+
if (endpointSecurityModel.getProxyConfigs() != null && endpointSecurityModel.getProxyConfigs()
189+
.isProxyEnabled()) {
190+
endpointSecurityModel.getProxyConfigs().setProxyPasswordAlias(GatewayUtils
191+
.retrieveOAuthProxyPasswordAlias(apiName, version, type));
192+
}
189193
}
190194
}
191195
if (StringUtils.isNotBlank(endpointSecurityModel.getUsername())

0 commit comments

Comments
 (0)