|
6 | 6 | import org.apache.commons.lang3.StringUtils;
|
7 | 7 | import org.apache.commons.logging.Log;
|
8 | 8 | import org.apache.commons.logging.LogFactory;
|
| 9 | +import org.apache.commons.validator.routines.InetAddressValidator; |
9 | 10 | import org.apache.synapse.MessageContext;
|
10 | 11 | import org.apache.synapse.core.axis2.Axis2MessageContext;
|
11 | 12 | import org.apache.synapse.transport.passthru.util.RelayUtils;
|
|
22 | 23 | import org.wso2.carbon.databridge.agent.DataPublisher;
|
23 | 24 |
|
24 | 25 | import java.io.IOException;
|
25 |
| -import java.net.Inet4Address; |
26 |
| -import java.net.Inet6Address; |
27 |
| -import java.net.InetAddress; |
28 |
| -import java.net.UnknownHostException; |
29 | 26 | import java.nio.charset.Charset;
|
30 | 27 | import java.util.ArrayList;
|
31 | 28 | import java.util.Collections;
|
32 | 29 | import java.util.HashMap;
|
33 | 30 | import java.util.Map;
|
34 |
| -import java.util.regex.Pattern; |
35 | 31 | import javax.xml.stream.XMLStreamException;
|
36 | 32 |
|
37 | 33 | import static org.wso2.carbon.apimgt.api.APIConstants.AIAPIConstants.*;
|
|
44 | 40 | */
|
45 | 41 | public class DataProcessAndPublishingAgent implements Runnable {
|
46 | 42 | private static final Log log = LogFactory.getLog(DataProcessAndPublishingAgent.class);
|
47 |
| - private static final Pattern IPV4_PATTERN = Pattern.compile( |
48 |
| - "^((25[0-5]|(2[0-4]|1\\d|[1-9]|)\\d)\\.?\\b){4}$"); |
49 |
| - private static final Pattern IPV6_PATTERN = Pattern.compile( |
50 |
| - "([0-9a-fA-F]{1,4}:){7}([0-9a-fA-F]{1,4})"); |
51 | 43 | private static String streamID = "org.wso2.throttle.request.stream:1.0.0";
|
52 | 44 | private MessageContext messageContext;
|
53 | 45 | private DataPublisher dataPublisher;
|
54 | 46 |
|
55 |
| - |
56 |
| - |
57 | 47 | String applicationLevelThrottleKey;
|
58 | 48 | String applicationLevelTier;
|
59 | 49 | String apiLevelThrottleKey;
|
@@ -243,10 +233,11 @@ public void run() {
|
243 | 233 | log.warn("Client port will be ignored and only the IP address (IPV4) will concern from " + ipAddress);
|
244 | 234 | ipAddress = ipAddress.split(":")[0];
|
245 | 235 | }
|
246 |
| - if (IPV4_PATTERN.matcher(ipAddress).matches()) { |
| 236 | + InetAddressValidator validator = InetAddressValidator.getInstance(); |
| 237 | + if (validator.isValidInet4Address(ipAddress)) { |
247 | 238 | jsonObMap.put(APIThrottleConstants.IP, APIUtil.ipToLong(ipAddress));
|
248 | 239 | jsonObMap.put(APIThrottleConstants.IPv6, 0);
|
249 |
| - } else if (IPV6_PATTERN.matcher(ipAddress).matches()) { |
| 240 | + } else if (validator.isValidInet6Address(ipAddress)) { |
250 | 241 | jsonObMap.put(APIThrottleConstants.IPv6, APIUtil.ipToBigInteger(ipAddress));
|
251 | 242 | jsonObMap.put(APIThrottleConstants.IP, 0);
|
252 | 243 | } else {
|
|
0 commit comments