8003703: Update RMI connection dialog box
authorsla
Tue, 19 Mar 2013 13:26:42 +0100
changeset 18197 ae73e4f50e08
parent 18196 07dfacf3d73e
child 18198 eeec61029574
8003703: Update RMI connection dialog box Reviewed-by: skoivu, ahgross, mchung, jbachorik
jdk/src/share/classes/sun/tools/jconsole/Messages.java
jdk/src/share/classes/sun/tools/jconsole/ProxyClient.java
jdk/src/share/classes/sun/tools/jconsole/VMPanel.java
jdk/src/share/classes/sun/tools/jconsole/resources/messages.properties
--- a/jdk/src/share/classes/sun/tools/jconsole/Messages.java	Mon Mar 18 11:55:16 2013 +0100
+++ b/jdk/src/share/classes/sun/tools/jconsole/Messages.java	Tue Mar 19 13:26:42 2013 +0100
@@ -156,6 +156,7 @@
     public static String IMPACT;
     public static String INFO;
     public static String INFO_CAPITALIZED;
+    public static String INSECURE;
     public static String INVALID_PLUGIN_PATH;
     public static String INVALID_URL;
     public static String IS;
@@ -303,6 +304,8 @@
     public static String WRITABLE;
     public static String CONNECTION_FAILED1;
     public static String CONNECTION_FAILED2;
+    public static String CONNECTION_FAILED_SSL1;
+    public static String CONNECTION_FAILED_SSL2;
     public static String CONNECTION_LOST1;
     public static String CONNECTING_TO1;
     public static String CONNECTING_TO2;
--- a/jdk/src/share/classes/sun/tools/jconsole/ProxyClient.java	Mon Mar 18 11:55:16 2013 +0100
+++ b/jdk/src/share/classes/sun/tools/jconsole/ProxyClient.java	Tue Mar 19 13:26:42 2013 +0100
@@ -307,10 +307,10 @@
         }
     }
 
-    void connect() {
+    void connect(boolean requireSSL) {
         setConnectionState(ConnectionState.CONNECTING);
         try {
-            tryConnect();
+            tryConnect(requireSSL);
             setConnectionState(ConnectionState.CONNECTED);
         } catch (Exception e) {
             if (JConsole.isDebug()) {
@@ -320,7 +320,7 @@
         }
     }
 
-    private void tryConnect() throws IOException {
+    private void tryConnect(boolean requireRemoteSSL) throws IOException {
         if (jmxUrl == null && "localhost".equals(hostName) && port == 0) {
             // Monitor self
             this.jmxc = null;
@@ -340,6 +340,10 @@
                     this.jmxUrl = new JMXServiceURL(lvm.connectorAddress());
                 }
             }
+            Map<String, Object> env = new HashMap<String, Object>();
+            if (requireRemoteSSL) {
+                env.put("jmx.remote.x.check.stub", "true");
+            }
             // Need to pass in credentials ?
             if (userName == null && password == null) {
                 if (isVmConnector()) {
@@ -348,12 +352,11 @@
                         checkSslConfig();
                     }
                     this.jmxc = new RMIConnector(stub, null);
-                    jmxc.connect();
+                    jmxc.connect(env);
                 } else {
-                    this.jmxc = JMXConnectorFactory.connect(jmxUrl);
+                    this.jmxc = JMXConnectorFactory.connect(jmxUrl, env);
                 }
             } else {
-                Map<String, String[]> env = new HashMap<String, String[]>();
                 env.put(JMXConnector.CREDENTIALS,
                         new String[] {userName, password});
                 if (isVmConnector()) {
--- a/jdk/src/share/classes/sun/tools/jconsole/VMPanel.java	Mon Mar 18 11:55:16 2013 +0100
+++ b/jdk/src/share/classes/sun/tools/jconsole/VMPanel.java	Tue Mar 19 13:26:42 2013 +0100
@@ -55,6 +55,7 @@
     private VMInternalFrame vmIF = null;
     private static ArrayList<TabInfo> tabInfos = new ArrayList<TabInfo>();
     private boolean wasConnected = false;
+    private boolean shouldUseSSL = true;
 
     // The everConnected flag keeps track of whether the window can be
     // closed if the user clicks Cancel after a failed connection attempt.
@@ -286,7 +287,7 @@
             new Thread("VMPanel.connect") {
 
                 public void run() {
-                    proxyClient.connect();
+                    proxyClient.connect(shouldUseSSL);
                 }
             }.start();
         }
@@ -460,8 +461,12 @@
             msgTitle = Messages.CONNECTION_LOST1;
             msgExplanation = Resources.format(Messages.CONNECTING_TO2, getConnectionName());
             buttonStr = Messages.RECONNECT;
+        } else if (shouldUseSSL) {
+            msgTitle = Messages.CONNECTION_FAILED_SSL1;
+            msgExplanation = Resources.format(Messages.CONNECTION_FAILED_SSL2, getConnectionName());
+            buttonStr = Messages.INSECURE;
         } else {
-            msgTitle =Messages.CONNECTION_FAILED1;
+            msgTitle = Messages.CONNECTION_FAILED1;
             msgExplanation = Resources.format(Messages.CONNECTION_FAILED2, getConnectionName());
             buttonStr = Messages.CONNECT;
         }
@@ -483,6 +488,9 @@
 
                     if (value == Messages.RECONNECT || value == Messages.CONNECT) {
                         connect();
+                    } else if (value == Messages.INSECURE) {
+                        shouldUseSSL = false;
+                        connect();
                     } else if (!everConnected) {
                         try {
                             getFrame().setClosed(true);
--- a/jdk/src/share/classes/sun/tools/jconsole/resources/messages.properties	Mon Mar 18 11:55:16 2013 +0100
+++ b/jdk/src/share/classes/sun/tools/jconsole/resources/messages.properties	Tue Mar 19 13:26:42 2013 +0100
@@ -114,6 +114,7 @@
 IMPACT=Impact
 INFO=Info
 INFO_CAPITALIZED=INFO
+INSECURE=Insecure connection
 INVALID_PLUGIN_PATH=Warning: Invalid plugin path: {0}
 INVALID_URL=Invalid URL: {0}
 IS=Is
@@ -261,6 +262,8 @@
 WRITABLE=Writable
 CONNECTION_FAILED1=Connection Failed: Retry?
 CONNECTION_FAILED2=The connection to {0} did not succeed.<br>Would you like to try again?
+CONNECTION_FAILED_SSL1=Secure connection failed. Retry insecurely?
+CONNECTION_FAILED_SSL2=The connection to {0} could not be made using SSL.<br>Would you like to try without SSL?<br>(Username and password will be sent in plain text.)
 CONNECTION_LOST1=Connection Lost: Reconnect?
 CONNECTING_TO1=Connecting to {0}
 CONNECTING_TO2=You are currently being connected to {0}.<br>This will take a few moments.