Skip to content

Commit a1c2f07

Browse files
authored
Merge pull request #136 from SAP/pr-3922e8ae6c557b4deb94d592619d17910c2e4fc3-sap
sap: Merge 3922e8a
2 parents 8d77393 + 3922e8a commit a1c2f07

File tree

18 files changed

+73
-11
lines changed

18 files changed

+73
-11
lines changed

application/org.openjdk.jmc.browser/src/main/java/org/openjdk/jmc/browser/wizards/ConnectionWizardPage.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public class ConnectionWizardPage extends RelinkableWizardPage {
9393
private final ConnectionWizardModel model;
9494
private Text hostNameField;
9595
private Text usernameField;
96+
private Button requireSecureConnectionButton;
9697
private Text portField;
9798
private Text javaCommandField;
9899
private Label javaCommandCaption;
@@ -408,15 +409,15 @@ private boolean hasServiceUrl() {
408409
private void createHostPortServiceURLComposite(Composite outer) {
409410
// FIXME: Make sure to fix the layout to align for all components, for example commandline, pid and service url (for JDP)
410411
Composite inner = new Composite(outer, SWT.NONE);
411-
GridLayout l = new GridLayout(1, false);
412+
GridLayout l = new GridLayout(2, false);
412413
inner.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 2));
413414

414415
l.marginWidth = 0;
415416
l.marginHeight = 0;
416417
inner.setLayout(l);
417418

418419
fieldStack = new Composite(inner, SWT.NONE);
419-
fieldStack.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
420+
fieldStack.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
420421
fieldStackLayout = new StackLayout();
421422
fieldStack.setLayout(fieldStackLayout);
422423
createHostPortComposite(fieldStack);
@@ -425,6 +426,10 @@ private void createHostPortServiceURLComposite(Composite outer) {
425426
}
426427

427428
private void createCustomURLButtonComposite(Composite inner) {
429+
requireSecureConnectionButton = new Button(inner, SWT.CHECK);
430+
requireSecureConnectionButton.setText(Messages.ConnectionWizardPage_REQUIRE_SECURE_CONNECTION_LABEL);
431+
requireSecureConnectionButton
432+
.setLayoutData(new GridData(SWT.LEFT, GridData.VERTICAL_ALIGN_BEGINNING, false, false));
428433
CustomURLSelector customURLSelector = new CustomURLSelector();
429434
customUrlButton = new Button(inner, SWT.TOGGLE);
430435
customUrlButton.setText(Messages.ConnectionWizardPage_BUTTON_CUSTOM_JMX_SERVICE_URL_TEXT);
@@ -487,6 +492,9 @@ private void initializeFields() {
487492
if (server != null) {
488493
currentUrl = server.getConnectionUrl();
489494
name = server.getServerHandle().getServerDescriptor().getDisplayName();
495+
if (server.getServerHandle().getConnectionDescriptor().requireSecureConnection()) {
496+
this.requireSecureConnectionButton.setSelection(true);
497+
}
490498
ICredentials credential = server.getCredentials();
491499
if (credential != null) {
492500
try {
@@ -670,7 +678,7 @@ void updateModel() {
670678

671679
ServerModelCredentials credentials = new ServerModelCredentials(username, password, storePassword);
672680
IConnectionDescriptor cd = new ConnectionDescriptorBuilder().url(currentUrl).credentials(credentials)
673-
.build();
681+
.requireSecureConnection(isSecureConnectionRequired()).build();
674682

675683
Server newServer;
676684
if (server != null) {
@@ -694,6 +702,10 @@ void updateModel() {
694702
}
695703
}
696704

705+
private boolean isSecureConnectionRequired() {
706+
return requireSecureConnectionButton.getSelection();
707+
}
708+
697709
private Exception testConnection() {
698710
if (model.createdServer == null) {
699711
updateModel();

application/org.openjdk.jmc.browser/src/main/java/org/openjdk/jmc/browser/wizards/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public class Messages extends NLS {
7474
public static String ConnectionWizardPage_PASSWORD_TOOLTIP;
7575
public static String ConnectionWizardPage_PORT_CAPTION;
7676
public static String ConnectionWizardPage_PORT_TOOLTIP;
77+
public static String ConnectionWizardPage_REQUIRE_SECURE_CONNECTION_LABEL;
7778
public static String ConnectionWizardPage_SERVICE_URL_CAPTION;
7879
public static String ConnectionWizardPage_SERVICE_URL_TOOLTIP;
7980
public static String ConnectionWizardPage_STATUS_CAPTION;

application/org.openjdk.jmc.browser/src/main/resources/org/openjdk/jmc/browser/wizards/messages.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ ConnectionWizardPage_STATUS_IS_UNTESTED=Untested
8585
ConnectionWizardPage_STATUS_IS_CONNECTED=OK
8686
ConnectionWizardPage_STATUS_IS_NOT_CONNECTED=Unable to connect
8787
ConnectionWizardPage_COULD_NOT_CONNECT_DISABLE_NEXT=Could not connect to {0}. Click Finish to create the connection without connecting.
88-
88+
ConnectionWizardPage_REQUIRE_SECURE_CONNECTION_LABEL=Require secure connection
8989
ServerSelectionWizardPage_NEW_CONNECTION=Create a new connection
9090
ServerConnectWizardPage_SERVER_SELECT_DESCRIPTION=Select a JVM to connect to
9191
ServerConnectWizardPage_TOOL_SELECT_DESCRIPTION=Select a tool to connect to {0}

application/org.openjdk.jmc.console.ui/src/main/java/org/openjdk/jmc/console/ui/editor/internal/ConsoleEditor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ public void run() {
123123
WorkbenchToolkit.asyncCloseEditor(ConsoleEditor.this);
124124
// FIXME: Show stacktrace? (Need to show our own ExceptionDialog in that case, or maybe create our own DetailsAreaProvider, see WorkbenchStatusDialogManager.setDetailsAreaProvider)
125125
return new Status(IStatus.ERROR, ConsolePlugin.PLUGIN_ID, IStatus.ERROR,
126-
NLS.bind(Messages.ConsoleEditor_COULD_NOT_CONNECT, getEditorInput().getName(), e.getMessage()),
127-
e);
126+
NLS.bind(e.getLocalizedMessage(), getEditorInput().getName(), e.getMessage()), e);
128127
}
129128
}
130129
}

application/org.openjdk.jmc.jolokia/src/main/java/org/openjdk/jmc/jolokia/JmcJolokiaPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2024, 2025, Kantega AS. All rights reserved.
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2025, Kantega AS. All rights reserved.
44
*
55
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
66
*

core/org.openjdk.jmc.rjmx.common/src/main/java/org/openjdk/jmc/rjmx/common/ConnectionDescriptorBuilder.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class ConnectionDescriptorBuilder {
5353
private String password;
5454
private int port = DEFAULT_PORT;
5555
private ICredentials credentials;
56+
private boolean requireSecureConnection;
5657

5758
/**
5859
* Port number designator meaning that the default port for the selected protocol should be
@@ -142,6 +143,16 @@ public ConnectionDescriptorBuilder password(String password) {
142143
return this;
143144
}
144145

146+
/**
147+
* @param requireSecureConnection
148+
* force connection to use TLS. Fail if not possible.
149+
* @return the Builder currently being configured.
150+
*/
151+
public ConnectionDescriptorBuilder requireSecureConnection(boolean requireSecureConnection) {
152+
this.requireSecureConnection = requireSecureConnection;
153+
return this;
154+
}
155+
145156
/**
146157
* Builds the {@link IConnectionDescriptor}.
147158
*
@@ -169,6 +180,6 @@ public IConnectionDescriptor build() throws IllegalStateException {
169180
}
170181
}
171182

172-
return new JMXConnectionDescriptor(url, credentials);
183+
return new JMXConnectionDescriptor(url, credentials, requireSecureConnection);
173184
}
174185
}

core/org.openjdk.jmc.rjmx.common/src/main/java/org/openjdk/jmc/rjmx/common/IConnectionDescriptor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
*/
5353
public interface IConnectionDescriptor {
5454

55+
// JMX convention. See e.g.
56+
// https://github.com/openjdk/jdk/blob/master/src/java.management.rmi/share/classes/javax/management/remote/rmi/RMIConnector.java
57+
static final String JMX_REMOTE_X_CHECK_STUB = "jmx.remote.x.check.stub"; //$NON-NLS-1$
58+
5559
/**
5660
* Returns a JMX service URL based on the settings in the descriptor. Some implementations may
5761
* want to just return a pre-configured service URL, whilst others may want to resolve the URL
@@ -70,4 +74,8 @@ public interface IConnectionDescriptor {
7074
* @return the JMX environment. Usually contains credentials and similar.
7175
*/
7276
Map<String, Object> getEnvironment();
77+
78+
default boolean requireSecureConnection() {
79+
return "true".equals(getEnvironment().get(JMX_REMOTE_X_CHECK_STUB));
80+
}
7381
}

core/org.openjdk.jmc.rjmx.common/src/main/java/org/openjdk/jmc/rjmx/common/internal/JMXConnectionDescriptor.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,26 @@
6767
*/
6868
public final class JMXConnectionDescriptor implements IConnectionDescriptor {
6969

70+
// JMX convention. See e.g.
71+
// https://github.com/openjdk/jdk/blob/master/src/java.management.rmi/share/classes/javax/management/remote/rmi/RMIConnector.java
72+
private static final String JMX_REMOTE_X_CHECK_STUB = "jmx.remote.x.check.stub"; //$NON-NLS-1$
73+
7074
/**
7175
* The JMX service URL.
7276
*/
7377
private final JMXServiceURL url;
7478

7579
private final ICredentials credentials;
7680

81+
private boolean requireSecureConnection;
82+
7783
/**
7884
* Full constructor.
7985
*/
80-
public JMXConnectionDescriptor(JMXServiceURL url, ICredentials credentials) {
86+
public JMXConnectionDescriptor(JMXServiceURL url, ICredentials credentials, boolean requireSecureConnection) {
8187
this.url = url;
8288
this.credentials = credentials;
89+
this.requireSecureConnection = requireSecureConnection;
8390
}
8491

8592
@Override
@@ -112,6 +119,9 @@ public Map<String, Object> getEnvironment() {
112119
} catch (SecurityException e) {
113120
throw new RuntimeException(e);
114121
}
122+
if (requireSecureConnection) {
123+
env.put(JMX_REMOTE_X_CHECK_STUB, "true"); //$NON-NLS-1$
124+
}
115125
return env;
116126
}
117127

core/org.openjdk.jmc.rjmx.common/src/main/java/org/openjdk/jmc/rjmx/common/internal/RJMXConnection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,8 @@ public boolean connect() throws ConnectionException {
361361
return true;
362362
} catch (Exception e) {
363363
m_server = null;
364-
throw new WrappedConnectionException(m_serverDescriptor.getDisplayName(), url, e);
364+
throw new WrappedConnectionException(m_serverDescriptor.getDisplayName(), url,
365+
m_connectionDescriptor.requireSecureConnection(), e);
365366
}
366367
}
367368
}

core/org.openjdk.jmc.rjmx.common/src/main/java/org/openjdk/jmc/rjmx/common/internal/WrappedConnectionException.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,19 @@ public class WrappedConnectionException extends ConnectionException {
5151

5252
private final JMXServiceURL url;
5353
private final String serverName;
54+
private boolean requireSecureConnection;
5455

5556
public WrappedConnectionException(String serverName, JMXServiceURL url, Exception cause) {
5657
super(cause.getMessage());
5758
initCause(cause); // yes, still 1.4 compatible
5859
this.url = url;
5960
this.serverName = serverName;
61+
}
6062

63+
public WrappedConnectionException(String serverName, JMXServiceURL url, boolean requireSecureConnection,
64+
Exception cause) {
65+
this(serverName, url, cause);
66+
this.requireSecureConnection = requireSecureConnection;
6167
}
6268

6369
@Override
@@ -89,6 +95,10 @@ public String getLocalizedMessage() {
8995
return String.format(Messages.getString(Messages.ConnectionException_MSARMI_CHECK_PASSWORD), serverName,
9096
url);
9197
}
98+
if (rootCause instanceof SecurityException && requireSecureConnection) {
99+
return String.format(Messages.getString(Messages.ConnectionException_COULD_NOT_MAKE_SECURE_CONNECTION),
100+
serverName, rootCause.getLocalizedMessage()); //$NON-NLS-1$
101+
}
92102
if (rootCause instanceof SecurityException || rootCause instanceof GeneralSecurityException) {
93103
return String.format(Messages.getString(Messages.ConnectionException_UNABLE_TO_RESOLVE_CREDENTIALS),
94104
serverName, rootCause.getLocalizedMessage());

0 commit comments

Comments
 (0)