From f86956a7cce890fbf018b6b28c5e6c7c4d3824bd Mon Sep 17 00:00:00 2001 From: Tharsanan1 Date: Wed, 11 Sep 2024 16:12:39 +0530 Subject: [PATCH] Fix NPE --- .../org/wso2/apk/enforcer/security/AuthFilter.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/security/AuthFilter.java b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/security/AuthFilter.java index b6d62e667..bbe72fd9e 100644 --- a/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/security/AuthFilter.java +++ b/gateway/enforcer/org.wso2.apk.enforcer/src/main/java/org/wso2/apk/enforcer/security/AuthFilter.java @@ -128,10 +128,16 @@ public boolean handleRequest(RequestContext requestContext) { // Any auth token has been provided for application-level security or not boolean canAuthenticated = false; if (requestContext.getMatchedAPI() != null && requestContext.getMatchedAPI().getAiProvider() != null) { - requestContext.addMetadataToMap("aitoken:prompttokenid", requestContext.getMatchedAPI().getAiProvider().getPromptTokens().getValue()); - requestContext.addMetadataToMap("aitoken:completiontokenid", requestContext.getMatchedAPI().getAiProvider().getCompletionToken().getValue()); - requestContext.addMetadataToMap("aitoken:totaltokenid", requestContext.getMatchedAPI().getAiProvider().getTotalToken().getValue()); - requestContext.addMetadataToMap("aitoken:extracttokenfrom", requestContext.getMatchedAPI().getAiProvider().getCompletionToken().getIn()); + if (requestContext.getMatchedAPI().getAiProvider().getPromptTokens() != null) { + requestContext.addMetadataToMap("aitoken:prompttokenid", requestContext.getMatchedAPI().getAiProvider().getPromptTokens().getValue()); + } + if (requestContext.getMatchedAPI().getAiProvider().getCompletionToken() != null) { + requestContext.addMetadataToMap("aitoken:extracttokenfrom", requestContext.getMatchedAPI().getAiProvider().getCompletionToken().getIn()); + requestContext.addMetadataToMap("aitoken:completiontokenid", requestContext.getMatchedAPI().getAiProvider().getCompletionToken().getValue()); + } + if (requestContext.getMatchedAPI().getAiProvider().getTotalToken() != null) { + requestContext.addMetadataToMap("aitoken:totaltokenid", requestContext.getMatchedAPI().getAiProvider().getTotalToken().getValue()); + } } for (Authenticator authenticator : authenticators) { if (authenticator.canAuthenticate(requestContext)) {