Repository: wso2/product-microgateway
Issue: Incorrect API-UUID is published to analytics for Internal-Key invocation

### Description:
The API UUID published to the analytics for internal Key invocation, is incorrect at the moment. Instead of the UUID assigned from APIM Publisher, it publishes a hash value.

This is due to authentication Context's API  UUID is not being populated properly when InternalKey Authentication is used.

### Steps to reproduce:

### Affected Product Version:
<!-- Members can use Affected/*** labels -->

### Environment details (with versions):
- OS:
- Client:
- Env (Docker/K8s):

---
### Optional Fields
#### Related Issues:
<!-- Any related issues from this/other repositories-->

#### Suggested Labels:
<!--Only to be used by non-members-->

#### Suggested Assignees:
<!--Only to be used by non-members-->


Changed files:
enforcer/src/main/java/org/wso2/choreo/connect/enforcer/util/FilterUtils.java
enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/jwt/InternalAPIKeyAuthenticator.java

diff --git a/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/jwt/InternalAPIKeyAuthenticator.java b/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/jwt/InternalAPIKeyAuthenticator.java
index cdeaa3615..69c91686b 100644
--- a/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/jwt/InternalAPIKeyAuthenticator.java
+++ b/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/security/jwt/InternalAPIKeyAuthenticator.java
@@ -178,7 +178,8 @@ public class InternalAPIKeyAuthenticator implements Authenticator {
                         log.debug("Internal Key authentication successful.");
                     }
                     return FilterUtils.generateAuthenticationContext(tokenIdentifier, payload, api,
-                            requestContext.getMatchedAPI().getAPIConfig().getTier());
+                            requestContext.getMatchedAPI().getAPIConfig().getTier(),
+                            requestContext.getMatchedAPI().getAPIConfig().getUuid());
                 } else {
                     CacheProvider.getGatewayInternalKeyDataCache().invalidate(payload.getJWTID());
                     CacheProvider.getInvalidGatewayInternalKeyCache().put(payload.getJWTID(), "carbon.super");
diff --git a/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/util/FilterUtils.java b/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/util/FilterUtils.java
index e0b67ec6d..4ba7378a2 100644
--- a/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/util/FilterUtils.java
+++ b/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/util/FilterUtils.java
@@ -202,7 +202,10 @@ public class FilterUtils {
         authContext.setStopOnQuotaReach(true);
         authContext.setConsumerKey(null);
         authContext.setCallerToken(null);
-
+        String apiUUID = requestContext.getMatchedAPI().getAPIConfig().getUuid();
+        if (!StringUtils.isEmpty(apiUUID)) {
+            authContext.setApiUUID(apiUUID);
+        }
         return authContext;
     }
 
@@ -293,7 +296,8 @@ public class FilterUtils {
      * @throws java.text.ParseException
      */
     public static AuthenticationContext generateAuthenticationContext(String tokenIdentifier, JWTClaimsSet payload,
-                                                                      JSONObject api, String apiLevelPolicy)
+                                                                      JSONObject api, String apiLevelPolicy,
+                                                                      String apiUUID)
             throws java.text.ParseException {
 
         AuthenticationContext authContext = new AuthenticationContext();
@@ -305,7 +309,6 @@ public class FilterUtils {
         } else {
             authContext.setKeyType(APIConstants.API_KEY_TYPE_PRODUCTION);
         }
-
         authContext.setApiTier(apiLevelPolicy);
         if (api != null) {
             authContext.setTier(APIConstants.UNLIMITED_TIER);
@@ -313,6 +316,9 @@ public class FilterUtils {
             authContext.setApiPublisher(api.getAsString(APIConstants.JwtTokenConstants.API_PUBLISHER));
 
         }
+        if (!StringUtils.isEmpty(apiUUID)) {
+            authContext.setApiUUID(apiUUID);
+        }
         authContext.setApplicationName(APIConstants.JwtTokenConstants.INTERNAL_KEY_APP_NAME);
         authContext.setApplicationId(UUID.nameUUIDFromBytes(APIConstants.JwtTokenConstants.INTERNAL_KEY_APP_NAME.
                 getBytes(StandardCharsets.UTF_8)).toString());