Skip to content

Commit 9722ed4

Browse files
committed
1st set of required changes
1 parent 19fb07d commit 9722ed4

File tree

4 files changed

+48
-49
lines changed

4 files changed

+48
-49
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ public API updateAPI(API api, API existingAPI) throws APIManagementException {
10511051
}
10521052

10531053
// Update API in new Dev Portal
1054-
if (APIUtil.isNewPortalEnabled() && APIConstants.PUBLISHED.equals(api.getStatus())) {
1054+
if (NewDevPortalHandler.isNewPortalEnabled() && APIConstants.PUBLISHED.equals(api.getStatus())) {
10551055
NewDevPortalHandler.update(organization, new ApiTypeWrapper(api));
10561056
}
10571057

@@ -2586,7 +2586,7 @@ public void deleteAPI(String apiUuid, String organization) throws APIManagementE
25862586
}
25872587

25882588
// Delete from new Developer Portal
2589-
if (APIUtil.isNewPortalEnabled()) {
2589+
if (NewDevPortalHandler.isNewPortalEnabled()) {
25902590
NewDevPortalHandler.unpublish(organization, api);
25912591
}
25922592
} catch (APIManagementException e) {

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

-32
Original file line numberDiff line numberDiff line change
@@ -9992,38 +9992,6 @@ public static JSONObject getMandatoryPropertyKeysFromRegistry(String organizatio
99929992
return null;
99939993
}
99949994

9995-
public static boolean isNewPortalEnabled() {
9996-
return Boolean.parseBoolean(getConfigProperty(APIConstants.API_STORE_NEW_PORTAL_ENABLED, "false"));
9997-
}
9998-
9999-
public static String getNewPortalURL() {
10000-
return getConfigProperty(APIConstants.API_STORE_NEW_PORTAL_URL, "");
10001-
}
10002-
10003-
public static Map<String, String> getServerSecurityStores() {
10004-
ServerConfiguration serverConfig = ServerConfiguration.getInstance();
10005-
10006-
Map<String, String> stores = new HashMap<>();
10007-
stores.put("trustStoreLocation", serverConfig.getFirstProperty("Security.TrustStore.Location"));
10008-
stores.put("trustStorePassword", serverConfig.getFirstProperty("Security.TrustStore.Password"));
10009-
stores.put("trustStoreType", serverConfig.getFirstProperty("Security.TrustStore.Type"));
10010-
10011-
stores.put("keyStoreLocation", serverConfig.getFirstProperty("Security.KeyStore.Location"));
10012-
stores.put("keyStorePassword", serverConfig.getFirstProperty("Security.KeyStore.Password"));
10013-
stores.put("keyStoreType", serverConfig.getFirstProperty("Security.KeyStore.Type"));
10014-
stores.put("keyPassword", serverConfig.getFirstProperty("Security.KeyStore.KeyPassword"));
10015-
stores.put("keyAlias", serverConfig.getFirstProperty("Security.KeyStore.KeyAlias"));
10016-
10017-
return stores;
10018-
}
10019-
10020-
private static String getConfigProperty(String key, String defaultValue) {
10021-
APIManagerConfiguration apiManagerConfiguration =
10022-
ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
10023-
String propertyValue = apiManagerConfiguration.getFirstProperty(key);
10024-
return StringUtils.isNotEmpty(propertyValue) ? propertyValue : defaultValue;
10025-
}
10026-
100279995
public static boolean isDefaultApplicationCreationEnabled() {
100289996
APIManagerConfiguration apiManagerConfiguration =
100299997
ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ public static void changeLifecycle(String user, APIProvider apiProvider, String
7676

7777
// Next Gen Dev Portal Publication
7878
if (Arrays.asList(APIConstants.PUBLISH, APIConstants.REPUBLISH).contains(action)
79-
&& APIUtil.isNewPortalEnabled()) {
79+
&& NewDevPortalHandler.isNewPortalEnabled()) {
8080
NewDevPortalHandler.publish(orgId, apiTypeWrapper);
8181
}
8282

8383
// Next Gen Dev Portal Un-Publication
8484
if (Arrays.asList(APIConstants.DEPRECATE, APIConstants.BLOCK, APIConstants.DEMOTE_TO_CREATED).contains(action)
85-
&& APIUtil.isNewPortalEnabled()) {
85+
&& NewDevPortalHandler.isNewPortalEnabled()) {
8686
NewDevPortalHandler.unpublish(orgId, apiTypeWrapper.getApi());
8787
}
8888

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

+44-13
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.wso2.carbon.apimgt.impl.utils;
2020

2121
import com.fasterxml.jackson.core.type.TypeReference;
22+
import org.apache.commons.lang3.StringUtils;
2223
import org.apache.commons.logging.Log;
2324
import org.apache.commons.logging.LogFactory;
2425
import org.apache.http.client.methods.*;
@@ -34,6 +35,7 @@
3435
import org.json.simple.JSONObject;
3536
import org.wso2.carbon.apimgt.api.APIConsumer;
3637
import org.wso2.carbon.apimgt.impl.APIConstants;
38+
import org.wso2.carbon.apimgt.impl.APIManagerConfiguration;
3739
import org.wso2.carbon.apimgt.impl.APIManagerFactory;
3840
import org.wso2.carbon.apimgt.impl.dao.constants.DevPortalProcessingConstants;
3941
import org.wso2.carbon.apimgt.api.APIManagementException;
@@ -55,6 +57,8 @@
5557
import java.util.Arrays;
5658

5759
import com.fasterxml.jackson.databind.ObjectMapper;
60+
import org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder;
61+
import org.wso2.carbon.base.ServerConfiguration;
5862

5963
public class NewDevPortalHandler {
6064

@@ -77,10 +81,14 @@ private String getResponseBody() {
7781
}
7882

7983
private static final Log log = LogFactory.getLog(NewDevPortalHandler.class);
80-
private static final String baseUrl = APIUtil.getNewPortalURL();
84+
private static final String baseUrl = getNewPortalURL();
8185
private static final ObjectMapper objectMapper = new ObjectMapper();
8286
private static final Map<String, String> orgIdCache = new HashMap<>();
8387

88+
public static boolean isNewPortalEnabled() {
89+
return Boolean.parseBoolean(getConfigProperty(APIConstants.API_STORE_NEW_PORTAL_ENABLED, "false"));
90+
}
91+
8492
public static void publish(String tenantName, ApiTypeWrapper apiTypeWrapper) {
8593
try {
8694
SSLConnectionSocketFactory sslsf = generateSSLSF();
@@ -462,32 +470,44 @@ private static HttpResponseData apiPutAction(String orgId, String apiId, String
462470
}
463471

464472
private static SSLConnectionSocketFactory generateSSLSF() throws APIManagementException {
465-
Map<String, String> serverSecurityStores = APIUtil.getServerSecurityStores();
466-
char[] keyStorePassword = serverSecurityStores.get("keyStorePassword").toCharArray();
467-
char[] keyPassword = serverSecurityStores.get("keyPassword").toCharArray();
468-
char[] trustStorePassword = serverSecurityStores.get("trustStorePassword").toCharArray();
473+
ServerConfiguration serverConfig = ServerConfiguration.getInstance();
474+
char[] keyStorePassword = serverConfig.getFirstProperty("Security.KeyStore.Password").toCharArray();
475+
char[] keyPassword = serverConfig.getFirstProperty("Security.KeyStore.KeyPassword").toCharArray();
476+
char[] trustStorePassword = serverConfig.getFirstProperty("Security.TrustStore.Password").toCharArray();
469477
try {
478+
// Key Store
470479
KeyStore keyStore;
471-
String keyStoreType = serverSecurityStores.get("keyStoreType");
480+
String keyStoreType = serverConfig.getFirstProperty("Security.KeyStore.Type");
472481
if (keyStoreType != null) {
473482
keyStore = KeyStore.getInstance(keyStoreType);
474483
} else {
475484
keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
476485
}
477-
try (FileInputStream keyStoreStream = new FileInputStream(serverSecurityStores.get("keyStoreLocation"))) {
486+
try (FileInputStream keyStoreStream = new FileInputStream(
487+
serverConfig.getFirstProperty("Security.KeyStore.Location"))) {
478488
keyStore.load(keyStoreStream, keyStorePassword);
479489
}
490+
491+
// Trust Store
492+
KeyStore trustStore;
493+
String trustStoreType = serverConfig.getFirstProperty("Security.TrustStore.Type");
494+
if (trustStoreType != null) {
495+
trustStore = KeyStore.getInstance(trustStoreType);
496+
} else {
497+
trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
498+
}
499+
try (FileInputStream trustStoreStream = new FileInputStream(
500+
serverConfig.getFirstProperty("Security.TrustStore.Location"))) {
501+
trustStore.load(trustStoreStream, trustStorePassword);
502+
}
503+
480504
return new SSLConnectionSocketFactory(
481505
SSLContexts.custom()
482506
.loadKeyMaterial(
483507
keyStore,
484508
keyPassword,
485-
(aliases, socket) -> serverSecurityStores.get("keyAlias"))
486-
.loadTrustMaterial(
487-
new File(serverSecurityStores.get("trustStoreLocation")),
488-
trustStorePassword)
489-
.build()
490-
);
509+
(aliases, socket) -> serverConfig.getFirstProperty("Security.KeyStore.KeyAlias"))
510+
.loadTrustMaterial(trustStore, null).build());
491511
} catch (GeneralSecurityException | IOException e) {
492512
throw new APIManagementException("Error while certification processing: " + e.getMessage(), e);
493513
} finally {
@@ -497,4 +517,15 @@ private static SSLConnectionSocketFactory generateSSLSF() throws APIManagementEx
497517
Arrays.fill(trustStorePassword, ' ');
498518
}
499519
}
520+
521+
private static String getNewPortalURL() {
522+
return getConfigProperty(APIConstants.API_STORE_NEW_PORTAL_URL, "");
523+
}
524+
525+
private static String getConfigProperty(String key, String defaultValue) {
526+
APIManagerConfiguration apiManagerConfiguration =
527+
ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
528+
String propertyValue = apiManagerConfiguration.getFirstProperty(key);
529+
return StringUtils.isNotEmpty(propertyValue) ? propertyValue : defaultValue;
530+
}
500531
}

0 commit comments

Comments
 (0)