Skip to content

Commit

Permalink
Add custom policy replacement in key template
Browse files Browse the repository at this point in the history
- Update validateCustomPolicy to check for the presence of CUSTOM_PROPERTY in messageContext
- Iterates through CUSTOM_PROPERTY Map to replace customProperty placeholders in the key template
  • Loading branch information
SavinduDimal committed Oct 31, 2024
1 parent eba3229 commit 302e2aa
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,15 @@ public boolean validateCustomPolicy(String userID, String appKey, String resourc
if (clientIp != null) {
key = key.replaceAll("\\$clientIp", APIUtil.ipToBigInteger(clientIp).toString());
}
Object customPropertyObj = messageContext.getProperty(APIMgtGatewayConstants.CUSTOM_PROPERTY);
if (customPropertyObj != null) {
Map<String, Object> customProperties = (Map<String, Object>) customPropertyObj;
for (Map.Entry<String, Object> entry : customProperties.entrySet()) {
String customKey = "\\$customProperty\\." + entry.getKey();
String customValue = entry.getValue() != null ? entry.getValue().toString() : "";
key = key.replaceAll(customKey, customValue);
}
}
if (getThrottleDataHolder().isThrottled(key)) {
long timestamp = getThrottleDataHolder().getThrottleNextAccessTimestamp(key);
messageContext.setProperty(APIThrottleConstants.THROTTLED_NEXT_ACCESS_TIMESTAMP, timestamp);
Expand Down

0 comments on commit 302e2aa

Please sign in to comment.