From e37bddea7f4619c32591fa35aa9099134abe7f01 Mon Sep 17 00:00:00 2001 From: Mitch Gaffigan Date: Sat, 26 Jul 2025 16:04:27 -0500 Subject: [PATCH] Remove legacy Java Security Manager use The Java Security Manager is deprecated for removal (JEP 411), and javac warns about the remaining uses. Drop the AccessController.doPrivileged class loader lookups and the SecurityManager thread group lookup, along with the @SuppressWarnings("removal") annotations that are no longer needed. Proxy classes now get their class loader directly from the interface. A custom restrictive policy may need RuntimePermission "getClassLoader". Signed-off-by: Mitch Gaffigan Signed-off-by: Tony Germano --- .../ui/panels/connectors/ConnectorSettingsPanel.java | 7 ++----- .../main/java/com/mirth/connect/client/core/Client.java | 6 ++---- .../util/javascript/MirthJavaScriptThreadFactory.java | 4 +--- .../glassfish/jersey/client/proxy/WebResourceFactory.java | 6 ++---- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/client/src/main/java/com/mirth/connect/client/ui/panels/connectors/ConnectorSettingsPanel.java b/client/src/main/java/com/mirth/connect/client/ui/panels/connectors/ConnectorSettingsPanel.java index 0daa860195..8ec8c945fb 100644 --- a/client/src/main/java/com/mirth/connect/client/ui/panels/connectors/ConnectorSettingsPanel.java +++ b/client/src/main/java/com/mirth/connect/client/ui/panels/connectors/ConnectorSettingsPanel.java @@ -13,7 +13,6 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; -import java.security.AccessController; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -23,8 +22,6 @@ import javax.swing.JPanel; import javax.swing.SwingWorker; -import org.glassfish.jersey.internal.util.ReflectionHelper; - import com.mirth.connect.client.core.ClientException; import com.mirth.connect.client.ui.ConnectorTypeDecoration; import com.mirth.connect.client.ui.PlatformUI; @@ -197,9 +194,9 @@ public final T getServlet(final Class servletInterface, final String work * A custom error message to display if an exception occurs during connector service * invocation */ - @SuppressWarnings({"removal", "unchecked"}) + @SuppressWarnings("unchecked") public final T getServlet(final Class servletInterface, final String workerDisplayText, final String errorText, final ResponseHandler responseHandler, final String workerId) { - return (T) Proxy.newProxyInstance(AccessController.doPrivileged(ReflectionHelper.getClassLoaderPA(servletInterface)), new Class[] { + return (T) Proxy.newProxyInstance(servletInterface.getClassLoader(), new Class[] { servletInterface }, new InvocationHandler() { @Override public Object invoke(final Object proxy, final Method method, final Object[] args) throws ClientException { diff --git a/server/src/main/java/com/mirth/connect/client/core/Client.java b/server/src/main/java/com/mirth/connect/client/core/Client.java index 6635335f42..cfa5805d1a 100644 --- a/server/src/main/java/com/mirth/connect/client/core/Client.java +++ b/server/src/main/java/com/mirth/connect/client/core/Client.java @@ -19,7 +19,6 @@ import java.lang.reflect.Proxy; import java.net.URI; import java.net.URISyntaxException; -import java.security.AccessController; import java.security.Provider; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -51,7 +50,6 @@ import org.glassfish.jersey.client.proxy.WebResourceFactory; import org.glassfish.jersey.client.spi.Connector; import org.glassfish.jersey.client.spi.ConnectorProvider; -import org.glassfish.jersey.internal.util.ReflectionHelper; import org.glassfish.jersey.media.multipart.MultiPartFeature; import org.reflections.Reflections; @@ -247,9 +245,9 @@ public T getServlet(Class servletInterface, ExecuteType executeType) { return getServlet(servletInterface, executeType, null); } - @SuppressWarnings({"removal", "unchecked"}) + @SuppressWarnings("unchecked") public T getServlet(final Class servletInterface, final ExecuteType executeType, final Map> customHeaders) { - return (T) Proxy.newProxyInstance(AccessController.doPrivileged(ReflectionHelper.getClassLoaderPA(servletInterface)), new Class[] { + return (T) Proxy.newProxyInstance(servletInterface.getClassLoader(), new Class[] { servletInterface }, new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws ClientException { diff --git a/server/src/main/java/com/mirth/connect/server/util/javascript/MirthJavaScriptThreadFactory.java b/server/src/main/java/com/mirth/connect/server/util/javascript/MirthJavaScriptThreadFactory.java index 58dc9b1b43..1e45e72f7f 100644 --- a/server/src/main/java/com/mirth/connect/server/util/javascript/MirthJavaScriptThreadFactory.java +++ b/server/src/main/java/com/mirth/connect/server/util/javascript/MirthJavaScriptThreadFactory.java @@ -18,10 +18,8 @@ public class MirthJavaScriptThreadFactory implements ThreadFactory { private final AtomicInteger threadNumber = new AtomicInteger(1); private final String namePrefix; - @SuppressWarnings("removal") MirthJavaScriptThreadFactory() { - SecurityManager securityManager = System.getSecurityManager(); - group = (securityManager != null) ? securityManager.getThreadGroup() : Thread.currentThread().getThreadGroup(); + group = Thread.currentThread().getThreadGroup(); namePrefix = "pool-" + poolNumber.getAndIncrement() + "-thread-"; } diff --git a/server/src/main/java/org/glassfish/jersey/client/proxy/WebResourceFactory.java b/server/src/main/java/org/glassfish/jersey/client/proxy/WebResourceFactory.java index 6930c8f651..87c64e5421 100644 --- a/server/src/main/java/org/glassfish/jersey/client/proxy/WebResourceFactory.java +++ b/server/src/main/java/org/glassfish/jersey/client/proxy/WebResourceFactory.java @@ -50,7 +50,6 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Proxy; import java.lang.reflect.Type; -import java.security.AccessController; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -82,7 +81,6 @@ import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; -import org.glassfish.jersey.internal.util.ReflectionHelper; import org.glassfish.jersey.media.multipart.Boundary; import org.glassfish.jersey.media.multipart.FormDataMultiPart; import org.glassfish.jersey.media.multipart.FormDataParam; @@ -140,7 +138,7 @@ public static C newResource(final Class resourceInterface, final WebTarge * @return Instance of a class implementing the resource interface that can * be used for making requests to the server. */ - @SuppressWarnings({"removal", "unchecked"}) + @SuppressWarnings("unchecked") public static C newResource(final Class resourceInterface, final WebTarget target, final boolean ignoreResourcePath, @@ -148,7 +146,7 @@ public static C newResource(final Class resourceInterface, final List cookies, final Form form) { - return (C) Proxy.newProxyInstance(AccessController.doPrivileged(ReflectionHelper.getClassLoaderPA(resourceInterface)), + return (C) Proxy.newProxyInstance(resourceInterface.getClassLoader(), new Class[] {resourceInterface}, new WebResourceFactory(ignoreResourcePath ? target : addPathFromAnnotation(resourceInterface, target), headers, cookies, form));