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 309a235906d5..8131b9f39d56 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 @@ -8233,18 +8233,19 @@ public Set getAllSharedScopeKeys(String tenantDomain) throws APIManageme @Override public Scope getSharedScopeByUUID(String sharedScopeId, String tenantDomain) throws APIManagementException { + Scope sharedScope; if (log.isDebugEnabled()) { log.debug("Retrieving shared scope: " + sharedScopeId); } - Scope scope = ApiMgtDAO.getInstance().getSharedScope(sharedScopeId); - if (scope != null) { - scope = KeyManagerHolder.getKeyManagerInstance().getScopeByName(scope.getKey(), tenantDomain); - scope.setId(sharedScopeId); + String scopeKey = ApiMgtDAO.getInstance().getSharedScopeKeyByUUID(sharedScopeId); + if (scopeKey != null) { + sharedScope = KeyManagerHolder.getKeyManagerInstance().getScopeByName(scopeKey, tenantDomain); + sharedScope.setId(sharedScopeId); } else { throw new APIMgtResourceNotFoundException("Shared Scope not found for scope ID: " + sharedScopeId, ExceptionCodes.from(ExceptionCodes.SHARED_SCOPE_NOT_FOUND, sharedScopeId)); } - return scope; + return sharedScope; } /** 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 33712980d968..58d76f06b908 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 @@ -15095,29 +15095,27 @@ public void deleteSharedScope(String scopeName, String tenantDomain) throws APIM } /** - * Get shared scope by uuid. + * Get shared scope key by uuid. * * @param uuid UUID of shared scope - * @return Shared scope object with UUID and scope key + * @return Shared scope key * @throws APIManagementException if an error occurs while getting shared scope */ - public Scope getSharedScope(String uuid) throws APIManagementException { + public String getSharedScopeKeyByUUID(String uuid) throws APIManagementException { - Scope scope = null; + String scopeKey = null; try (Connection connection = APIMgtDBUtil.getConnection(); PreparedStatement statement = connection.prepareStatement(SQLConstants.GET_SHARED_SCOPE_BY_UUID)) { statement.setString(1, uuid); try (ResultSet rs = statement.executeQuery()) { while (rs.next()) { - scope = new Scope(); - scope.setKey(rs.getString("NAME")); - scope.setId(uuid); + scopeKey = rs.getString("NAME"); } } } catch (SQLException e) { handleException("Failed to get Shared Scope : " + uuid, e); } - return scope; + return scopeKey; } /** 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 2d0b9970691e..bec08521baa2 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 @@ -3445,7 +3445,7 @@ public static class RevokedJWTConstants { //Shared Scopes related constants public static final String ADD_SHARED_SCOPE = "INSERT INTO AM_SHARED_SCOPE (NAME, UUID, TENANT_ID) VALUES (?,?,?)"; public static final String DELETE_SHARED_SCOPE = "DELETE FROM AM_SHARED_SCOPE WHERE NAME = ? AND TENANT_ID = ?"; - public static final String GET_SHARED_SCOPE_BY_UUID = "SELECT * FROM AM_SHARED_SCOPE WHERE UUID = ?"; + public static final String GET_SHARED_SCOPE_BY_UUID = "SELECT NAME FROM AM_SHARED_SCOPE WHERE UUID = ?"; public static final String GET_ALL_SHARED_SCOPE_KEYS_BY_TENANT = "SELECT NAME FROM AM_SHARED_SCOPE WHERE TENANT_ID = ?"; public static final String IS_SHARED_SCOPE_NAME_EXISTS = @@ -3513,7 +3513,7 @@ public static class KeyMgtConstants { "INSERT INTO AM_KM_MGT_APPLICATION (CONSUMER_KEY,CONSUMER_SECRET,TENANT_ID) VALUES (?,?,?)"; public static final String GET_KM_APPLICATION_FOR_TENANT = - "SELECT * FROM AM_KM_MGT_APPLICATION WHERE TENANT_ID = ?"; + "SELECT CONSUMER_KEY, CONSUMER_SECRET FROM AM_KM_MGT_APPLICATION WHERE TENANT_ID = ?"; } //TODO: Need remove after KM seperation