changeset 6646:fd073e7b57f9

7199324: IPv6: JMXConnectorServer.getConnectionIDs() return IDs contradicting to address grammar Reviewed-by: alanb, sjiang Contributed-by: jaroslav.bachorik@oracle.com
author nloodin
date Thu, 27 Jun 2013 16:02:54 +0200
parents 70b91714c76e
children b9f86896cd0a e2c7640fcacb
files src/share/classes/javax/management/remote/rmi/RMIServerImpl.java test/javax/management/remote/mandatory/connection/ConnectionTest.java
diffstat 2 files changed, 33 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/javax/management/remote/rmi/RMIServerImpl.java	Fri Jun 14 16:38:13 2013 +0100
+++ b/src/share/classes/javax/management/remote/rmi/RMIServerImpl.java	Thu Jun 27 16:02:54 2013 +0200
@@ -474,6 +474,15 @@
         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);
         }
--- a/test/javax/management/remote/mandatory/connection/ConnectionTest.java	Fri Jun 14 16:38:13 2013 +0100
+++ b/test/javax/management/remote/mandatory/connection/ConnectionTest.java	Thu Jun 27 16:02:54 2013 +0200
@@ -44,6 +44,7 @@
 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 @@
         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 @@
                                "\"");
             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 + "\"");