From 5657a9cab925f05977fe1f553c71e1da18850fa5 Mon Sep 17 00:00:00 2001 From: rusirijayodaillesinghe Date: Mon, 22 Apr 2024 12:27:01 +0530 Subject: [PATCH] Fix Application with globalkeymanager and cross tenant subscription import fail through CURL command Fixes https://github.com/wso2/api-manager/issues/2800 --- .../java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 08d79d58f79c..d03b9ddfd704 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 @@ -9382,11 +9382,12 @@ public List getKeyManagerConfigurationsByOrganizatio public KeyManagerConfigurationDTO getKeyManagerConfigurationByID(String organization, String id) throws APIManagementException { - final String query = "SELECT * FROM AM_KEY_MANAGER WHERE UUID = ? AND ORGANIZATION = ?"; + final String query = "SELECT * FROM AM_KEY_MANAGER WHERE UUID = ? AND (ORGANIZATION = ? OR ORGANIZATION = ?)"; try (Connection conn = APIMgtDBUtil.getConnection(); PreparedStatement preparedStatement = conn.prepareStatement(query)) { preparedStatement.setString(1, id); preparedStatement.setString(2, organization); + preparedStatement.setString(3, APIConstants.GLOBAL_KEY_MANAGER_TENANT_DOMAIN); try (ResultSet resultSet = preparedStatement.executeQuery()) { if (resultSet.next()) { KeyManagerConfigurationDTO keyManagerConfigurationDTO = new KeyManagerConfigurationDTO(); @@ -9440,7 +9441,6 @@ public boolean isIDPExistInOrg(String organization, String resourceId) throws AP public KeyManagerConfigurationDTO getKeyManagerConfigurationByName(String organization, String name) throws APIManagementException { - final String query = "SELECT * FROM AM_KEY_MANAGER WHERE NAME = ? AND ORGANIZATION = ?"; try (Connection conn = APIMgtDBUtil.getConnection()) { return getKeyManagerConfigurationByName(conn, organization, name); } catch (SQLException | IOException e) { @@ -9454,10 +9454,11 @@ private KeyManagerConfigurationDTO getKeyManagerConfigurationByName(Connection c String name) throws SQLException, IOException, APIManagementException { - final String query = "SELECT * FROM AM_KEY_MANAGER WHERE NAME = ? AND ORGANIZATION = ?"; + final String query = "SELECT * FROM AM_KEY_MANAGER WHERE NAME = ? AND (ORGANIZATION = ? OR ORGANIZATION = ?)"; try (PreparedStatement preparedStatement = connection.prepareStatement(query)) { preparedStatement.setString(1, name); preparedStatement.setString(2, organization); + preparedStatement.setString(3, APIConstants.GLOBAL_KEY_MANAGER_TENANT_DOMAIN); try (ResultSet resultSet = preparedStatement.executeQuery()) { if (resultSet.next()) { KeyManagerConfigurationDTO keyManagerConfigurationDTO = new KeyManagerConfigurationDTO();