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 28, 2024
1 parent f3adc4d commit 98b114c
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,19 @@ 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 instanceof Map<?, ?>) {
try {
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);
}
} catch (ClassCastException e) {
log.warn("Exception occurred while getting the custom properties map.");
}
}
if (getThrottleDataHolder().isThrottled(key)) {
long timestamp = getThrottleDataHolder().getThrottleNextAccessTimestamp(key);
messageContext.setProperty(APIThrottleConstants.THROTTLED_NEXT_ACCESS_TIMESTAMP, timestamp);
Expand Down

0 comments on commit 98b114c

Please sign in to comment.