Skip to content

Commit

Permalink
Merge pull request #86 from GoogleCloudPlatform/fix-ip
Browse files Browse the repository at this point in the history
Fix issue with truncating recorded ip addresses in datastore
lesv committed Feb 9, 2016

Verified

This commit was signed with the committer’s verified signature.
Mamaduka George Mamadashvili
2 parents 486352c + 5e5ffa6 commit 5de140c
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -51,9 +51,11 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOExc
String userIp = req.getRemoteAddr();
InetAddress address = InetAddress.getByName(userIp);
if (address instanceof Inet6Address) {
userIp = userIp.substring(0, userIp.indexOf(":", 2)) + ":*:*:*:*:*:*";
// nest indexOf calls to find the second occurrence of a character in a string
// an alternative is to use Apache Commons Lang: StringUtils.ordinalIndexOf()
userIp = userIp.substring(0, userIp.indexOf(":", userIp.indexOf(":") + 1)) + ":*:*:*:*:*:*";
} else if (address instanceof Inet4Address) {
userIp = userIp.substring(0, userIp.indexOf(".", 2)) + ".*.*";
userIp = userIp.substring(0, userIp.indexOf(".", userIp.indexOf(".") + 1)) + ".*.*";
}

Datastore datastore = DatastoreOptions.defaultInstance().service();

0 comments on commit 5de140c

Please sign in to comment.