From a21ad48c49b186ad1e95113a70afe452fe7d9bc7 Mon Sep 17 00:00:00 2001 From: rusirijayodaillesinghe Date: Thu, 23 May 2024 19:35:19 +0530 Subject: [PATCH] Add endpointType to client certificate --- .../wso2/carbon/apimgt/api/APIProvider.java | 4 +- .../apimgt/api/dto/ClientCertificateDTO.java | 21 +++++++ .../carbon/apimgt/impl/APIProviderImpl.java | 12 ++-- .../apimgt/impl/UserAwareAPIProvider.java | 11 ++-- .../certificatemgt/CertificateManager.java | 6 +- .../CertificateManagerImpl.java | 11 ++-- .../carbon/apimgt/impl/dao/ApiMgtDAO.java | 9 +++ .../apimgt/impl/dao/CertificateMgtDAO.java | 19 +++++-- .../impl/dao/constants/SQLConstants.java | 19 ++++--- .../src/main/resources/publisher-api.yaml | 19 +++++++ .../v1/dto/ClientCertMetadataDTO.java | 55 ++++++++++++++++++- .../mappings/CertificateRestApiUtils.java | 1 + .../v1/common/mappings/ImportUtils.java | 6 +- .../apimgt/rest/api/publisher/v1/ApisApi.java | 8 +-- .../rest/api/publisher/v1/ApisApiService.java | 4 +- .../publisher/v1/impl/ApisApiServiceImpl.java | 11 ++-- .../src/main/resources/publisher-api.yaml | 19 +++++++ 17 files changed, 186 insertions(+), 49 deletions(-) diff --git a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIProvider.java b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIProvider.java index c7e9ac392513..787f420ffa53 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIProvider.java +++ b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIProvider.java @@ -802,7 +802,7 @@ String addBlockCondition(String conditionType, String conditionValue, boolean co * @throws APIManagementException API Management Exception. */ int addClientCertificate(String userName, ApiTypeWrapper apiTypeWrapper, String certificate, String alias, - String tierName, String organization) throws APIManagementException; + String tierName, String endpointType, String organization) throws APIManagementException; /** * Method to remove the certificate which mapped to the given alias, endpoint from publisher and gateway nodes. @@ -965,7 +965,7 @@ ClientCertificateDTO getClientCertificate(String alias, ApiTypeWrapper apiTypeWr * @throws APIManagementException API Management Exception. */ int updateClientCertificate(String certificate, String alias, ApiTypeWrapper apiTypeWrapper, String tier, - int tenantId, String organization) throws APIManagementException; + String endpointType, int tenantId, String organization) throws APIManagementException; /** * Retrieve the certificate which matches the given alias. diff --git a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/ClientCertificateDTO.java b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/ClientCertificateDTO.java index 0d6313f93904..5b9582ef3eff 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/ClientCertificateDTO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/dto/ClientCertificateDTO.java @@ -28,8 +28,12 @@ public class ClientCertificateDTO { private String certificate; private String uniqueId; private String tierName; + private String endpointType; private APIIdentifier apiIdentifier; + public ClientCertificateDTO() { + } + /** * To get the identifier of the API related with client certificate. * @@ -65,6 +69,23 @@ public void setTierName(String tierName) { this.tierName = tierName; } + /** + * To get the endpoint type of the certificate. + * @return endpoint type. + */ + public String getEndpointType() { + return endpointType; + } + + /** + * To set the endpoint type for the current certificate. + * + * @param endpointType endpoint type (whether PRODUCTION or SANDBOX). + */ + public void setEndpointType(String endpointType) { + this.endpointType = endpointType; + } + /** * To get the alias of the certificate. * 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 3025e4581cfe..4add89c91d0d 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 @@ -3907,14 +3907,15 @@ public int addCertificate(String userName, String certificate, String alias, Str @Override public int addClientCertificate(String userName, ApiTypeWrapper apiTypeWrapper, String certificate, String alias, - String tierName, String organization) throws APIManagementException { + String tierName, String endpointType, String organization) + throws APIManagementException { checkAccessControlPermission(userNameWithoutChange, apiTypeWrapper.getAccessControl(), apiTypeWrapper.getAccessControlRoles()); ResponseCode responseCode = ResponseCode.INTERNAL_SERVER_ERROR; int tenantId = APIUtil.getInternalOrganizationId(organization); - responseCode = certificateManager - .addClientCertificate(apiTypeWrapper.getId(), certificate, alias, tierName, tenantId, organization); + responseCode = certificateManager.addClientCertificate(apiTypeWrapper.getId(), certificate, + alias, tierName, endpointType, tenantId, organization); return responseCode.getResponseCode(); } @@ -4058,11 +4059,12 @@ public int updateCertificate(String certificateString, String alias) throws APIM @Override public int updateClientCertificate(String certificate, String alias, ApiTypeWrapper apiTypeWrapper, - String tier, int tenantId, String organization) throws APIManagementException { + String tier, String endpointType, int tenantId, String organization) + throws APIManagementException { checkAccessControlPermission(userNameWithoutChange, apiTypeWrapper.getAccessControl(), apiTypeWrapper.getAccessControlRoles()); ResponseCode responseCode = certificateManager - .updateClientCertificate(certificate, alias, tier, tenantId, organization); + .updateClientCertificate(certificate, alias, tier, endpointType, tenantId, organization); return responseCode != null ? responseCode.getResponseCode() : ResponseCode.INTERNAL_SERVER_ERROR.getResponseCode(); diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/UserAwareAPIProvider.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/UserAwareAPIProvider.java index 0b654fdd81b8..ed3e89e65d0b 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/UserAwareAPIProvider.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/UserAwareAPIProvider.java @@ -102,8 +102,9 @@ public SubscribedAPI getSubscriptionByUUID(String uuid) throws APIManagementExce @Override public int addClientCertificate(String userName, ApiTypeWrapper apiTypeWrapper, String certificate, String alias, - String tierName, String organization) throws APIManagementException { - return super.addClientCertificate(userName, apiTypeWrapper, certificate, alias, tierName, organization); + String tierName, String endpointType, String organization) throws APIManagementException { + return super.addClientCertificate(userName, apiTypeWrapper, certificate, alias, tierName, endpointType, + organization); } @Override @@ -156,8 +157,10 @@ public int updateCertificate(String certificateString, String alias) throws APIM @Override public int updateClientCertificate(String certificate, String alias, ApiTypeWrapper apiIdentifier, - String tier, int tenantId, String organization) throws APIManagementException { - return super.updateClientCertificate(certificate, alias, apiIdentifier, tier, tenantId, organization); + String tier, String endpointType, int tenantId, String organization) + throws APIManagementException { + return super.updateClientCertificate(certificate, alias, apiIdentifier, tier, endpointType, + tenantId, organization); } @Override diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/certificatemgt/CertificateManager.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/certificatemgt/CertificateManager.java index e0b1f571cccb..098261e30c3e 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/certificatemgt/CertificateManager.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/certificatemgt/CertificateManager.java @@ -182,7 +182,7 @@ public interface CertificateManager { * certificate is expired. */ ResponseCode addClientCertificate(Identifier apiIdentifier, String certificate, String alias, String tierName, - int tenantId, String organization); + String endpointType, int tenantId, String organization); /** * Method to delete the client certificate from publisher node. @@ -236,8 +236,8 @@ List searchClientCertificates(int tenantId, String alias, * @param organization : Organization * @return : true if update succeeds, false if fails */ - ResponseCode updateClientCertificate(String certificate, String alias, String tier, int tenantId, - String organization) throws APIManagementException; + ResponseCode updateClientCertificate(String certificate, String alias, String tier, String endpointType, + int tenantId, String organization) throws APIManagementException; /** * To get the count of the client certificates updated for the particular tenant. diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/certificatemgt/CertificateManagerImpl.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/certificatemgt/CertificateManagerImpl.java index 72628214e74e..3bcfed7785ba 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/certificatemgt/CertificateManagerImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/certificatemgt/CertificateManagerImpl.java @@ -114,7 +114,7 @@ public ResponseCode addCertificateToParentNode(String certificate, String alias, @Override public ResponseCode addClientCertificate(Identifier apiIdentifier, String certificate, String alias, - String tierName, int tenantId, String organization) { + String tierName, String endpointType, int tenantId, String organization) { ResponseCode responseCode; try { @@ -124,7 +124,8 @@ public ResponseCode addClientCertificate(Identifier apiIdentifier, String certif responseCode = ResponseCode.ALIAS_EXISTS_IN_TRUST_STORE; } else { certificateMgtDAO - .addClientCertificate(certificate, apiIdentifier, alias, tierName, tenantId, organization); + .addClientCertificate(certificate, apiIdentifier, alias, tierName, endpointType, + tenantId, organization); } } } catch (CertificateManagementException e) { @@ -454,8 +455,8 @@ public ResponseCode updateCertificate(String certificate, String alias) throws A } @Override - public ResponseCode updateClientCertificate(String certificate, String alias, String tier, int tenantId, - String organization) throws APIManagementException { + public ResponseCode updateClientCertificate(String certificate, String alias, String tier, String endpointType, + int tenantId, String organization) throws APIManagementException { ResponseCode responseCode = ResponseCode.SUCCESS; if (StringUtils.isNotEmpty(certificate)) { @@ -464,7 +465,7 @@ public ResponseCode updateClientCertificate(String certificate, String alias, St try { if (responseCode.getResponseCode() == ResponseCode.SUCCESS.getResponseCode()) { boolean isSuccess = certificateMgtDAO - .updateClientCertificate(certificate, alias, tier, tenantId, organization); + .updateClientCertificate(certificate, alias, tier, endpointType, tenantId, organization); if (isSuccess) { responseCode = ResponseCode.SUCCESS; } else { diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java index 6829667932c8..55a6bd1bc009 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java @@ -16990,6 +16990,7 @@ public void addAPIRevision(APIRevision apiRevision) throws APIManagementExceptio clientCertificateDTO.setAlias(rs.getString(1)); clientCertificateDTO.setCertificate(APIMgtDBUtil.getStringFromInputStream(rs.getBinaryStream(2))); clientCertificateDTO.setTierName(rs.getString(3)); + clientCertificateDTO.setEndpointType(rs.getString(4)); clientCertificateDTOS.add(clientCertificateDTO); } } @@ -17004,6 +17005,7 @@ public void addAPIRevision(APIRevision apiRevision) throws APIManagementExceptio insertClientCertificateStatement.setBoolean(5, false); insertClientCertificateStatement.setString(6, clientCertificateDTO.getTierName()); insertClientCertificateStatement.setString(7, apiRevision.getRevisionUUID()); + insertClientCertificateStatement.setString(8, clientCertificateDTO.getEndpointType()); insertClientCertificateStatement.addBatch(); } insertClientCertificateStatement.executeBatch(); @@ -17908,6 +17910,7 @@ public void restoreAPIRevision(APIRevision apiRevision) throws APIManagementExce clientCertificateDTO.setAlias(rs.getString(1)); clientCertificateDTO.setCertificate(APIMgtDBUtil.getStringFromInputStream(rs.getBinaryStream(2))); clientCertificateDTO.setTierName(rs.getString(3)); + clientCertificateDTO.setEndpointType(rs.getString(4)); clientCertificateDTOS.add(clientCertificateDTO); } } @@ -17922,6 +17925,7 @@ public void restoreAPIRevision(APIRevision apiRevision) throws APIManagementExce insertClientCertificateStatement.setBoolean(5, false); insertClientCertificateStatement.setString(6, clientCertificateDTO.getTierName()); insertClientCertificateStatement.setString(7, "Current API"); + insertClientCertificateStatement.setString(8, clientCertificateDTO.getEndpointType()); insertClientCertificateStatement.addBatch(); } insertClientCertificateStatement.executeBatch(); @@ -18222,6 +18226,7 @@ public void addAPIProductRevision(APIRevision apiRevision) throws APIManagementE clientCertificateDTO.setAlias(rs.getString(1)); clientCertificateDTO.setCertificate(APIMgtDBUtil.getStringFromInputStream(rs.getBinaryStream(2))); clientCertificateDTO.setTierName(rs.getString(3)); + clientCertificateDTO.setEndpointType(rs.getString(4)); clientCertificateDTOS.add(clientCertificateDTO); } } @@ -18236,6 +18241,7 @@ public void addAPIProductRevision(APIRevision apiRevision) throws APIManagementE insertClientCertificateStatement.setBoolean(5, false); insertClientCertificateStatement.setString(6, clientCertificateDTO.getTierName()); insertClientCertificateStatement.setString(7, apiRevision.getRevisionUUID()); + insertClientCertificateStatement.setString(8, clientCertificateDTO.getEndpointType()); insertClientCertificateStatement.addBatch(); } insertClientCertificateStatement.executeBatch(); @@ -18458,6 +18464,7 @@ public void restoreAPIProductRevision(APIRevision apiRevision) throws APIManagem clientCertificateDTO.setAlias(rs.getString(1)); clientCertificateDTO.setCertificate(APIMgtDBUtil.getStringFromInputStream(rs.getBinaryStream(2))); clientCertificateDTO.setTierName(rs.getString(3)); + clientCertificateDTO.setEndpointType(rs.getString(4)); clientCertificateDTOS.add(clientCertificateDTO); } } @@ -18472,6 +18479,8 @@ public void restoreAPIProductRevision(APIRevision apiRevision) throws APIManagem insertClientCertificateStatement.setBoolean(5, false); insertClientCertificateStatement.setString(6, clientCertificateDTO.getTierName()); insertClientCertificateStatement.setString(7, "Current API"); + insertClientCertificateStatement.setString(8, + clientCertificateDTO.getEndpointType()); insertClientCertificateStatement.addBatch(); } insertClientCertificateStatement.executeBatch(); diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/CertificateMgtDAO.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/CertificateMgtDAO.java index b295526bf04b..293252cf3ca4 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/CertificateMgtDAO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/CertificateMgtDAO.java @@ -73,7 +73,7 @@ public static CertificateMgtDAO getInstance() { private boolean addClientCertificate(Connection connection, String certificate, Identifier apiIdentifier, - String alias, String tierName, + String alias, String tierName, String endpointType, int tenantId, String organization) throws SQLException { boolean result; @@ -87,6 +87,7 @@ private boolean addClientCertificate(Connection connection, String certificate, preparedStatement.setString(6, apiIdentifier.getVersion()); preparedStatement.setString(7, organization); preparedStatement.setString(8, tierName); + preparedStatement.setString(9, endpointType); result = preparedStatement.executeUpdate() >= 1; } return result; @@ -103,8 +104,8 @@ private boolean addClientCertificate(Connection connection, String certificate, * @return true if the update succeeds, unless false. * @throws CertificateManagementException Certificate Management Exception. */ - public boolean updateClientCertificate(String certificate, String alias, String tier, int tenantId, - String organization) throws CertificateManagementException { + public boolean updateClientCertificate(String certificate, String alias, String tier, String endpointType, + int tenantId, String organization) throws CertificateManagementException { List clientCertificateDTOList = getClientCertificates(tenantId, alias, null, organization); @@ -124,13 +125,16 @@ public boolean updateClientCertificate(String certificate, String alias, String if (StringUtils.isNotEmpty(tier)) { clientCertificateDTO.setTierName(tier); } + if (StringUtils.isNotEmpty(tier)) { + clientCertificateDTO.setEndpointType(endpointType); + } try (Connection connection = APIMgtDBUtil.getConnection()) { try { connection.setAutoCommit(false); deleteClientCertificate(connection, null, alias, tenantId); addClientCertificate(connection, clientCertificateDTO.getCertificate(), clientCertificateDTO.getApiIdentifier(), alias, clientCertificateDTO.getTierName(), - tenantId, organization); + clientCertificateDTO.getEndpointType(), tenantId, organization); connection.commit(); } catch (SQLException e) { handleConnectionRollBack(connection); @@ -296,6 +300,7 @@ public List getClientCertificates(int tenantId, String ali alias = resultSet.getString("ALIAS"); ClientCertificateDTO clientCertificateDTO = new ClientCertificateDTO(); clientCertificateDTO.setTierName(resultSet.getString("TIER_NAME")); + clientCertificateDTO.setEndpointType(resultSet.getString("ENDPOINT_TYPE")); clientCertificateDTO.setAlias(alias); clientCertificateDTO.setCertificate( APIMgtDBUtil.getStringFromInputStream(resultSet.getBinaryStream("CERTIFICATE"))); @@ -742,19 +747,21 @@ private void handleException(String message, Throwable e) throws CertificateMana * @param certificate : Client certificate that need to be added. * @param apiIdentifier : API which the client certificate is uploaded against. * @param alias : Alias for the new certificate. + * @param endpointType : Type of endpoint of the certificate * @param tenantId : The Id of the tenant who uploaded the certificate. * @param organization : Organization * @return : True if the information is added successfully, false otherwise. * @throws CertificateManagementException if existing entry is found for the given endpoint or alias. */ public boolean addClientCertificate(String certificate, Identifier apiIdentifier, String alias, String tierName, - int tenantId, String organization) throws CertificateManagementException { + String endpointType, int tenantId, String organization) + throws CertificateManagementException { try (Connection connection = APIMgtDBUtil.getConnection()) { try { connection.setAutoCommit(false); boolean status = addClientCertificate(connection, certificate, apiIdentifier, alias, tierName, - tenantId, organization); + endpointType, tenantId, organization); connection.commit(); return status; } catch (SQLException e) { diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java index 1fb0e3a2e44d..9b2f8c6d39f0 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java @@ -3386,8 +3386,9 @@ public static class CertificateConstants { public static class ClientCertificateConstants{ public static final String INSERT_CERTIFICATE = "INSERT INTO AM_API_CLIENT_CERTIFICATE " + - "(CERTIFICATE, TENANT_ID, ALIAS, API_ID, TIER_NAME) VALUES(?, ?, ?, (SELECT API_ID FROM AM_API WHERE " + - "API_PROVIDER = ? AND API_NAME = ? AND API_VERSION = ? AND ORGANIZATION = ? ), ?)"; + "(CERTIFICATE, TENANT_ID, ALIAS, API_ID, TIER_NAME, ENDPOINT_TYPE) " + + "VALUES(?, ?, ?, (SELECT API_ID FROM AM_API WHERE " + + "API_PROVIDER = ? AND API_NAME = ? AND API_VERSION = ? AND ORGANIZATION = ? ), ?, ?)"; public static final String GET_CERTIFICATES_FOR_API = "SELECT ALIAS FROM AM_API_CLIENT_CERTIFICATE WHERE " + "TENANT_ID=? and API_ID=(SELECT API_ID FROM AM_API WHERE API_PROVIDER = ? AND API_NAME = ? AND " + @@ -3401,21 +3402,21 @@ public static class ClientCertificateConstants{ + "WHERE ALIAS=? AND REMOVED=? AND TENANT_ID =? and REVISION_UUID ='Current API'"; public static final String SELECT_CERTIFICATE_FOR_TENANT = - "SELECT AC.CERTIFICATE, AC.ALIAS, AC.TIER_NAME, AA.API_PROVIDER, AA.API_NAME, " + "SELECT AC.CERTIFICATE, AC.ALIAS, AC.TIER_NAME, AC.ENDPOINT_TYPE, AA.API_PROVIDER, AA.API_NAME, " + "AA.API_VERSION FROM AM_API_CLIENT_CERTIFICATE AC, AM_API AA " + "WHERE AC.REMOVED=? AND AC.TENANT_ID=? AND AA.API_ID=AC.API_ID AND AC.REVISION_UUID ='Current API'"; public static final String SELECT_CERTIFICATE_FOR_TENANT_ALIAS = - "SELECT AC.CERTIFICATE, AC.ALIAS, AC.TIER_NAME, AA.API_PROVIDER, AA.API_NAME, AA.API_VERSION " + "SELECT AC.CERTIFICATE, AC.ALIAS, AC.TIER_NAME, AC.ENDPOINT_TYPE, AA.API_PROVIDER, AA.API_NAME, AA.API_VERSION " + "FROM AM_API_CLIENT_CERTIFICATE AC, AM_API AA " + "WHERE AC.REMOVED=? AND AC.TENANT_ID=? AND AC.ALIAS=? AND AA.API_ID=AC.API_ID AND AC.REVISION_UUID ='Current API'"; public static final String SELECT_CERTIFICATE_FOR_TENANT_ALIAS_APIID = - "SELECT AC.CERTIFICATE, AC.ALIAS, AC.TIER_NAME FROM AM_API_CLIENT_CERTIFICATE AC " + "SELECT AC.CERTIFICATE, AC.ALIAS, AC.TIER_NAME, AC.ENDPOINT_TYPE FROM AM_API_CLIENT_CERTIFICATE AC " + "WHERE AC.REMOVED=? AND AC.TENANT_ID=? AND AC.ALIAS=? AND AC.API_ID = ? AND AC.REVISION_UUID ='Current API'"; public static final String SELECT_CERTIFICATE_FOR_TENANT_APIID = - "SELECT AC.CERTIFICATE, AC.ALIAS, AC.TIER_NAME FROM AM_API_CLIENT_CERTIFICATE AC " + "SELECT AC.CERTIFICATE, AC.ALIAS, AC.TIER_NAME, AC.ENDPOINT_TYPE FROM AM_API_CLIENT_CERTIFICATE AC " + "WHERE AC.REMOVED=? AND AC.TENANT_ID=? AND AC.API_ID=? AND AC.REVISION_UUID ='Current API'"; public static final String PRE_DELETE_CERTIFICATES = "DELETE FROM AM_API_CLIENT_CERTIFICATE " @@ -3783,12 +3784,12 @@ public static class APIRevisionSqlConstants { public static final String INSERT_URL_MAPPINGS = "INSERT INTO AM_API_URL_MAPPING(API_ID, HTTP_METHOD," + " AUTH_SCHEME, URL_PATTERN, THROTTLING_TIER, REVISION_UUID) VALUES(?,?,?,?,?,?)"; public static final String GET_CLIENT_CERTIFICATES = "SELECT ALIAS, CERTIFICATE," + - " TIER_NAME FROM AM_API_CLIENT_CERTIFICATE WHERE API_ID = ? AND REVISION_UUID='Current API' AND REMOVED=FALSE"; + " TIER_NAME, ENDPOINT_TYPE FROM AM_API_CLIENT_CERTIFICATE WHERE API_ID = ? AND REVISION_UUID='Current API' AND REMOVED=FALSE"; public static final String GET_CLIENT_CERTIFICATES_MSSQL = "SELECT ALIAS, CERTIFICATE," + - " TIER_NAME FROM AM_API_CLIENT_CERTIFICATE WHERE API_ID = ? AND REVISION_UUID='Current API' AND REMOVED=0"; + " TIER_NAME, ENDPOINT_TYPE FROM AM_API_CLIENT_CERTIFICATE WHERE API_ID = ? AND REVISION_UUID='Current API' AND REMOVED=0"; public static final String GET_CLIENT_CERTIFICATES_ORACLE_SQL = "SELECT ALIAS, CERTIFICATE," + - " TIER_NAME FROM AM_API_CLIENT_CERTIFICATE WHERE API_ID = ? AND REVISION_UUID='Current API' AND REMOVED=0"; + " TIER_NAME, ENDPOINT_TYPE FROM AM_API_CLIENT_CERTIFICATE WHERE API_ID = ? AND REVISION_UUID='Current API' AND REMOVED=0"; public static final String INSERT_CLIENT_CERTIFICATES = "INSERT INTO AM_API_CLIENT_CERTIFICATE(TENANT_ID, " + "ALIAS, API_ID, CERTIFICATE, REMOVED, TIER_NAME, REVISION_UUID) VALUES(?,?,?,?,?,?,?)"; diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/publisher-api.yaml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/publisher-api.yaml index 747da722370d..fa761a3bac38 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/publisher-api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/publisher-api.yaml @@ -4616,6 +4616,7 @@ paths: - alias - certificate - tier + - endpointType properties: certificate: type: string @@ -4629,6 +4630,12 @@ paths: tier: type: string description: API tier to which the certificate should be applied. + endpointType: + type: string + description: Whether the endpoint is production or sandbox + enum: + - PRODUCTION + - SANDBOX required: true responses: 200: @@ -4741,6 +4748,12 @@ paths: tier: type: string description: The tier of the certificate + endpointType: + type: string + description: Whether the endpoint is production or sandbox + enum: + - PRODUCTION + - SANDBOX responses: 200: description: | @@ -11328,6 +11341,12 @@ components: tier: type: string example: Gold + endpointType: + type: string + example: PRODUCTION + enum: + - PRODUCTION + - SANDBOX description: Meta data of certificate LifecycleState: title: Lifecycle State diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/ClientCertMetadataDTO.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/ClientCertMetadataDTO.java index 7a58d442b036..094fafcbb17c 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/ClientCertMetadataDTO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/ClientCertMetadataDTO.java @@ -27,6 +27,38 @@ public class ClientCertMetadataDTO { private String apiId = null; private String tier = null; + @XmlType(name="EndpointTypeEnum") + @XmlEnum(String.class) + public enum EndpointTypeEnum { + PRODUCTION("PRODUCTION"), + SANDBOX("SANDBOX"); + private String value; + + EndpointTypeEnum (String v) { + value = v; + } + + public String value() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static EndpointTypeEnum fromValue(String v) { + for (EndpointTypeEnum b : EndpointTypeEnum.values()) { + if (String.valueOf(b.value).equals(v)) { + return b; + } + } +return null; + } + } + private EndpointTypeEnum endpointType = null; + /** **/ public ClientCertMetadataDTO alias(String alias) { @@ -78,6 +110,23 @@ public void setTier(String tier) { this.tier = tier; } + /** + **/ + public ClientCertMetadataDTO endpointType(EndpointTypeEnum endpointType) { + this.endpointType = endpointType; + return this; + } + + + @ApiModelProperty(example = "PRODUCTION", value = "") + @JsonProperty("endpointType") + public EndpointTypeEnum getEndpointType() { + return endpointType; + } + public void setEndpointType(EndpointTypeEnum endpointType) { + this.endpointType = endpointType; + } + @Override public boolean equals(java.lang.Object o) { @@ -90,12 +139,13 @@ public boolean equals(java.lang.Object o) { ClientCertMetadataDTO clientCertMetadata = (ClientCertMetadataDTO) o; return Objects.equals(alias, clientCertMetadata.alias) && Objects.equals(apiId, clientCertMetadata.apiId) && - Objects.equals(tier, clientCertMetadata.tier); + Objects.equals(tier, clientCertMetadata.tier) && + Objects.equals(endpointType, clientCertMetadata.endpointType); } @Override public int hashCode() { - return Objects.hash(alias, apiId, tier); + return Objects.hash(alias, apiId, tier, endpointType); } @Override @@ -106,6 +156,7 @@ public String toString() { sb.append(" alias: ").append(toIndentedString(alias)).append("\n"); sb.append(" apiId: ").append(toIndentedString(apiId)).append("\n"); sb.append(" tier: ").append(toIndentedString(tier)).append("\n"); + sb.append(" endpointType: ").append(toIndentedString(endpointType)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/CertificateRestApiUtils.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/CertificateRestApiUtils.java index b8eafcafdfff..25997a7c1727 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/CertificateRestApiUtils.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/CertificateRestApiUtils.java @@ -195,6 +195,7 @@ public static ClientCertificatesDTO getPaginatedClientCertificates( clientCertMetadataDTO.setAlias(clientCertificateDTO.getAlias()); clientCertMetadataDTO.setApiId(clientCertificateDTO.getApiIdentifier().toString()); clientCertMetadataDTO.setTier(clientCertificateDTO.getTierName()); + clientCertificateDTO.setEndpointType(clientCertificateDTO.getEndpointType()); clientCertificateList.add(clientCertMetadataDTO); } Map paginatedParams = RestApiCommonUtil.getPaginationParams(offset, limit, certCount); diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ImportUtils.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ImportUtils.java index 44d3d40ae0e7..8e1008a44618 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ImportUtils.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ImportUtils.java @@ -2257,10 +2257,10 @@ private static void addClientCertificates(String pathToArchive, APIProvider apiP for (ClientCertificateDTO certDTO : certificateMetadataDTOS) { if (ResponseCode.ALIAS_EXISTS_IN_TRUST_STORE.getResponseCode() == (apiProvider.addClientCertificate( APIUtil.replaceEmailDomainBack(apiIdentifier.getProviderName()), apiTypeWrapper, - certDTO.getCertificate(), certDTO.getAlias(), certDTO.getTierName(), organization)) - && isOverwrite) { + certDTO.getCertificate(), certDTO.getAlias(), certDTO.getTierName(),certDTO.getEndpointType(), + organization)) && isOverwrite) { apiProvider.updateClientCertificate(certDTO.getCertificate(), certDTO.getAlias(), apiTypeWrapper, - certDTO.getTierName(), tenantId, organization); + certDTO.getTierName(), certDTO.getEndpointType(), tenantId, organization); } } } catch (APIManagementException e) { diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/ApisApi.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/ApisApi.java index ed7d69ed0f06..98371b8d6130 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/ApisApi.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/ApisApi.java @@ -95,8 +95,8 @@ public class ApisApi { @ApiResponse(code = 200, message = "OK. The Certificate added successfully. ", response = ClientCertMetadataDTO.class), @ApiResponse(code = 400, message = "Bad Request. Invalid request or validation error.", response = ErrorDTO.class), @ApiResponse(code = 500, message = "Internal Server Error.", response = ErrorDTO.class) }) - public Response addAPIClientCertificate(@ApiParam(value = "**API ID** consisting of the **UUID** of the API. ",required=true) @PathParam("apiId") String apiId, @Multipart(value = "certificate") InputStream certificateInputStream, @Multipart(value = "certificate" ) Attachment certificateDetail, @Multipart(value = "alias") String alias, @Multipart(value = "tier") String tier) throws APIManagementException{ - return delegate.addAPIClientCertificate(apiId, certificateInputStream, certificateDetail, alias, tier, securityContext); + public Response addAPIClientCertificate(@ApiParam(value = "**API ID** consisting of the **UUID** of the API. ",required=true) @PathParam("apiId") String apiId, @Multipart(value = "certificate") InputStream certificateInputStream, @Multipart(value = "certificate" ) Attachment certificateDetail, @Multipart(value = "alias") String alias, @Multipart(value = "tier") String tier, @Multipart(value = "endpointType") String endpointType) throws APIManagementException{ + return delegate.addAPIClientCertificate(apiId, certificateInputStream, certificateDetail, alias, tier, endpointType, securityContext); } @POST @@ -1547,8 +1547,8 @@ public Response undeployAPIRevision(@ApiParam(value = "**API ID** consisting of @ApiResponse(code = 400, message = "Bad Request. Invalid request or validation error.", response = ErrorDTO.class), @ApiResponse(code = 404, message = "Not Found. The specified resource does not exist.", response = ErrorDTO.class), @ApiResponse(code = 500, message = "Internal Server Error.", response = ErrorDTO.class) }) - public Response updateAPIClientCertificateByAlias( @Size(min=1,max=30)@ApiParam(value = "Alias for the certificate",required=true) @PathParam("alias") String alias, @ApiParam(value = "**API ID** consisting of the **UUID** of the API. ",required=true) @PathParam("apiId") String apiId, @Multipart(value = "certificate", required = false) InputStream certificateInputStream, @Multipart(value = "certificate" , required = false) Attachment certificateDetail, @Multipart(value = "tier", required = false) String tier) throws APIManagementException{ - return delegate.updateAPIClientCertificateByAlias(alias, apiId, certificateInputStream, certificateDetail, tier, securityContext); + public Response updateAPIClientCertificateByAlias( @Size(min=1,max=30)@ApiParam(value = "Alias for the certificate",required=true) @PathParam("alias") String alias, @ApiParam(value = "**API ID** consisting of the **UUID** of the API. ",required=true) @PathParam("apiId") String apiId, @Multipart(value = "certificate", required = false) InputStream certificateInputStream, @Multipart(value = "certificate" , required = false) Attachment certificateDetail, @Multipart(value = "tier", required = false) String tier, @Multipart(value = "endpointType", required = false) String endpointType) throws APIManagementException{ + return delegate.updateAPIClientCertificateByAlias(alias, apiId, certificateInputStream, certificateDetail, tier, endpointType, securityContext); } @PUT diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/ApisApiService.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/ApisApiService.java index 10f13b24633d..aac29878c6cb 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/ApisApiService.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/ApisApiService.java @@ -64,7 +64,7 @@ public interface ApisApiService { - public Response addAPIClientCertificate(String apiId, InputStream certificateInputStream, Attachment certificateDetail, String alias, String tier, MessageContext messageContext) throws APIManagementException; + public Response addAPIClientCertificate(String apiId, InputStream certificateInputStream, Attachment certificateDetail, String alias, String tier, String endpointType, MessageContext messageContext) throws APIManagementException; public Response addAPIDocument(String apiId, DocumentDTO documentDTO, String ifMatch, MessageContext messageContext) throws APIManagementException; public Response addAPIDocumentContent(String apiId, String documentId, String ifMatch, InputStream fileInputStream, Attachment fileDetail, String inlineContent, MessageContext messageContext) throws APIManagementException; public Response addAPIMonetization(String apiId, APIMonetizationInfoDTO apIMonetizationInfoDTO, MessageContext messageContext) throws APIManagementException; @@ -138,7 +138,7 @@ public interface ApisApiService { public Response restoreAPIRevision(String apiId, String revisionId, MessageContext messageContext) throws APIManagementException; public Response undeployAPIRevision(String apiId, String revisionId, String revisionNumber, Boolean allEnvironments, List apIRevisionDeploymentDTO, MessageContext messageContext) throws APIManagementException; public Response updateAPI(String apiId, APIDTO APIDTO, String ifMatch, MessageContext messageContext) throws APIManagementException; - public Response updateAPIClientCertificateByAlias(String alias, String apiId, InputStream certificateInputStream, Attachment certificateDetail, String tier, MessageContext messageContext) throws APIManagementException; + public Response updateAPIClientCertificateByAlias(String alias, String apiId, InputStream certificateInputStream, Attachment certificateDetail, String tier, String endpointType, MessageContext messageContext) throws APIManagementException; public Response updateAPIDeployment(String apiId, String deploymentId, APIRevisionDeploymentDTO apIRevisionDeploymentDTO, MessageContext messageContext) throws APIManagementException; public Response updateAPIDocument(String apiId, String documentId, DocumentDTO documentDTO, String ifMatch, MessageContext messageContext) throws APIManagementException; public Response updateAPIGraphQLSchema(String apiId, String schemaDefinition, String ifMatch, MessageContext messageContext) throws APIManagementException; diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/ApisApiServiceImpl.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/ApisApiServiceImpl.java index 74c6536b6e1a..dda625065a78 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/ApisApiServiceImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl/ApisApiServiceImpl.java @@ -959,7 +959,7 @@ public Response getAPIClientCertificateByAlias(String alias, String apiId, public Response updateAPIClientCertificateByAlias(String alias, String apiId, InputStream certificateInputStream, Attachment certificateDetail, String tier, - MessageContext messageContext) { + String endpointType, MessageContext messageContext) { try { //validate if api exists CommonUtils.validateAPIExistence(apiId); @@ -987,12 +987,13 @@ public Response updateAPIClientCertificateByAlias(String alias, String apiId, return Response.ok().entity("Client Certificate is not updated for alias " + alias).build(); } int responseCode = apiProvider - .updateClientCertificate(base64EncodedCert, alias, apiTypeWrapper, tier, + .updateClientCertificate(base64EncodedCert, alias, apiTypeWrapper, tier, endpointType, tenantId, organization); if (ResponseCode.SUCCESS.getResponseCode() == responseCode) { ClientCertMetadataDTO clientCertMetadataDTO = new ClientCertMetadataDTO(); clientCertMetadataDTO.setAlias(alias); + clientCertMetadataDTO.setEndpointType(ClientCertMetadataDTO.EndpointTypeEnum.valueOf(endpointType)); clientCertMetadataDTO.setApiId(apiTypeWrapper.getUuid()); clientCertMetadataDTO.setTier(clientCertificateDTO.getTierName()); URI updatedCertUri = new URI(RestApiConstants.CLIENT_CERTS_BASE_PATH + "?alias=" + alias); @@ -1063,7 +1064,7 @@ public Response getAPIClientCertificates(String apiId, Integer limit, Integer of @Override public Response addAPIClientCertificate(String apiId, InputStream certificateInputStream, Attachment certificateDetail, String alias, String tier, - MessageContext messageContext) { + String endpointType, MessageContext messageContext) { try { APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider(); ContentDisposition contentDisposition = certificateDetail.getContentDisposition(); @@ -1087,7 +1088,8 @@ public Response addAPIClientCertificate(String apiId, InputStream certificateInp String userName = RestApiCommonUtil.getLoggedInUsername(); String base64EncodedCert = CertificateRestApiUtils.generateEncodedCertificate(certificateInputStream); int responseCode = apiProvider - .addClientCertificate(userName, apiTypeWrapper, base64EncodedCert, alias, tier, organization); + .addClientCertificate(userName, apiTypeWrapper, base64EncodedCert, alias, tier, endpointType, + organization); if (log.isDebugEnabled()) { log.debug(String.format("Add certificate operation response code : %d", responseCode)); } @@ -1096,6 +1098,7 @@ public Response addAPIClientCertificate(String apiId, InputStream certificateInp certificateDTO.setAlias(alias); certificateDTO.setApiId(apiId); certificateDTO.setTier(tier); + certificateDTO.setEndpointType(ClientCertMetadataDTO.EndpointTypeEnum.valueOf(endpointType)); URI createdCertUri = new URI(RestApiConstants.CLIENT_CERTS_BASE_PATH + "?alias=" + alias); return Response.created(createdCertUri).entity(certificateDTO).build(); } else if (ResponseCode.INTERNAL_SERVER_ERROR.getResponseCode() == responseCode) { diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/resources/publisher-api.yaml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/resources/publisher-api.yaml index 747da722370d..fa761a3bac38 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/resources/publisher-api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/resources/publisher-api.yaml @@ -4616,6 +4616,7 @@ paths: - alias - certificate - tier + - endpointType properties: certificate: type: string @@ -4629,6 +4630,12 @@ paths: tier: type: string description: API tier to which the certificate should be applied. + endpointType: + type: string + description: Whether the endpoint is production or sandbox + enum: + - PRODUCTION + - SANDBOX required: true responses: 200: @@ -4741,6 +4748,12 @@ paths: tier: type: string description: The tier of the certificate + endpointType: + type: string + description: Whether the endpoint is production or sandbox + enum: + - PRODUCTION + - SANDBOX responses: 200: description: | @@ -11328,6 +11341,12 @@ components: tier: type: string example: Gold + endpointType: + type: string + example: PRODUCTION + enum: + - PRODUCTION + - SANDBOX description: Meta data of certificate LifecycleState: title: Lifecycle State