From 7c11aba793969a8658b1e90625965791a7219317 Mon Sep 17 00:00:00 2001 From: Jaroslav Bachorik Date: Thu, 2 May 2013 13:21:09 +0200 Subject: [PATCH] 7199324: Connection ID for IPv6 addresses is not generated accordingly to the specification RemoteServer.getClientHost is returning a String with an IPv6 literal address and we need to enclose it in [] when building the connection id Reviewed-by: alanb, sjiang --- .../management/remote/rmi/RMIServerImpl.java | 9 +++++++ .../mandatory/connection/ConnectionTest.java | 24 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/jdk/src/share/classes/javax/management/remote/rmi/RMIServerImpl.java b/jdk/src/share/classes/javax/management/remote/rmi/RMIServerImpl.java index 0b6ad75e4cb..2226f6c8162 100644 --- a/jdk/src/share/classes/javax/management/remote/rmi/RMIServerImpl.java +++ b/jdk/src/share/classes/javax/management/remote/rmi/RMIServerImpl.java @@ -474,6 +474,15 @@ public abstract class RMIServerImpl implements Closeable, RMIServer { String clientHost = ""; try { clientHost = RemoteServer.getClientHost(); + /* + * According to the rules specified in the javax.management.remote + * package description, a numeric IPv6 address (detected by the + * presence of otherwise forbidden ":" character) forming a part + * of the connection id must be enclosed in square brackets. + */ + if (clientHost.contains(":")) { + clientHost = "[" + clientHost + "]"; + } } catch (ServerNotActiveException e) { logger.trace("makeConnectionId", "getClientHost", e); } diff --git a/jdk/test/javax/management/remote/mandatory/connection/ConnectionTest.java b/jdk/test/javax/management/remote/mandatory/connection/ConnectionTest.java index c375ca1ea8e..d26be3bfd53 100644 --- a/jdk/test/javax/management/remote/mandatory/connection/ConnectionTest.java +++ b/jdk/test/javax/management/remote/mandatory/connection/ConnectionTest.java @@ -44,6 +44,7 @@ import java.util.Set; import java.util.StringTokenizer; import java.security.Principal; +import java.util.regex.Pattern; import javax.security.auth.Subject; import javax.management.MBeanServer; @@ -239,6 +240,18 @@ public class ConnectionTest { return true; } + private static final String IPV4_PTN = "^(?:[0-9]{1,3}\\.){3}[0-9]{1,3}(\\:[1-9][0-9]{3})?$"; + + /** + * Checks the connection id for validity. + * The {@link + * javax.management.remote package description} describes the + * conventions for connection IDs. + * @param proto Connection protocol + * @param clientConnId The connection ID + * @return Returns {@code true} if the connection id conforms to the specification; {@code false} otherwise. + * @throws Exception + */ private static boolean checkConnectionId(String proto, String clientConnId) throws Exception { StringTokenizer tok = new StringTokenizer(clientConnId, " ", true); @@ -249,6 +262,17 @@ public class ConnectionTest { "\""); return false; } + + int hostAddrInd = s.indexOf("//"); + if (hostAddrInd > -1) { + s = s.substring(hostAddrInd + 2); + if (!Pattern.matches(IPV4_PTN, s)) { + if (!s.startsWith("[") || !s.endsWith("]")) { + System.out.println("IPv6 address must be enclosed in \"[]\""); + return false; + } + } + } s = tok.nextToken(); if (!s.equals(" ")) { System.out.println("Expected \" \", found \"" + s + "\"");