From 8646c41ad91f0f051040601a498c10e30cf4ad01 Mon Sep 17 00:00:00 2001 From: Uwe Trottmann Date: Thu, 11 May 2023 15:30:16 +0200 Subject: [PATCH] endpoints-control: strip brackets of IPv6 addresses for check API. https://github.com/cloudendpoints/endpoints-management-java/issues/66 --- .../main/java/com/google/api/control/ControlFilter.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/endpoints-control/src/main/java/com/google/api/control/ControlFilter.java b/endpoints-control/src/main/java/com/google/api/control/ControlFilter.java index 3cef4e6..61264b9 100644 --- a/endpoints-control/src/main/java/com/google/api/control/ControlFilter.java +++ b/endpoints-control/src/main/java/com/google/api/control/ControlFilter.java @@ -1,5 +1,6 @@ /* * Copyright 2016 Google Inc. All Rights Reserved. + * Copyright 2023 Uwe Trottmann * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -370,6 +371,10 @@ private CheckRequestInfo createCheckInfo(HttpServletRequest request, String uri, apiKey = findDefaultApiKeyParam(request); } + // The Service Control check API expects IPv6 addresses formatted without brackets ('[' and ']'), so strip them. + String ipAddress = request.getRemoteAddr(); + String strippedIpAddress = ipAddress.replace("[", "").replace("]", ""); + return new CheckRequestInfo(new OperationInfo() .setApiKey(apiKey) .setApiKeyValid(!Strings.isNullOrEmpty(apiKey)) @@ -378,7 +383,7 @@ private CheckRequestInfo createCheckInfo(HttpServletRequest request, String uri, .setOperationId(nextOperationId()) .setOperationName(info.getSelector()) .setServiceName(serviceName)) - .setClientIp(request.getRemoteAddr()) + .setClientIp(strippedIpAddress) .setAndroidPackageName(request.getHeader(X_ANDROID_PACKAGE)) .setAndroidCertificateFingerprint(request.getHeader(X_ANDROID_CERT)) .setIosBundleId(request.getHeader(X_IOS_BUNDLE_ID));