[AMQ-9563] Remove usage of java.security.AccessController where possible. Document JDK 21 refactor TODO

This commit is contained in:
Matt Pavlovich 2024-09-03 10:01:40 -05:00 committed by Matt Pavlovich
parent 5debe1facc
commit 7c81d73d8a
2 changed files with 10 additions and 29 deletions

View File

@ -205,6 +205,7 @@ public class AnnotatedMBean extends StandardMBean {
objects = (objects == null) ? new Object[]{} : objects; objects = (objects == null) ? new Object[]{} : objects;
JMXAuditLogEntry entry = null; JMXAuditLogEntry entry = null;
if (audit != OFF) { if (audit != OFF) {
// [AMQ-9563] TODO: JDK 21 use Subject.current() instead
Subject subject = Subject.getSubject(AccessController.getContext()); Subject subject = Subject.getSubject(AccessController.getContext());
String caller = "anonymous"; String caller = "anonymous";
if (subject != null) { if (subject != null) {

View File

@ -19,8 +19,6 @@ package org.apache.activemq;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.*; import java.util.*;
import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.RejectedExecutionHandler;
@ -67,23 +65,12 @@ public class ActiveMQConnectionFactory extends JNDIBaseStorable implements Conne
String host = null; String host = null;
String port = null; String port = null;
try { try {
host = AccessController.doPrivileged(new PrivilegedAction<String>() { host = System.getProperty("org.apache.activemq.AMQ_HOST");
@Override host = (host==null||host.isBlank()) ? System.getProperty("AMQ_HOST","localhost") : host;
public String run() {
String result = System.getProperty("org.apache.activemq.AMQ_HOST"); port = System.getProperty("org.apache.activemq.AMQ_PORT");
result = (result==null||result.isEmpty()) ? System.getProperty("AMQ_HOST","localhost") : result; port = (port==null||port.isBlank()) ? System.getProperty("AMQ_PORT","61616") : port;
return result; } catch(Throwable e){
}
});
port = AccessController.doPrivileged(new PrivilegedAction<String>() {
@Override
public String run() {
String result = System.getProperty("org.apache.activemq.AMQ_PORT");
result = (result==null||result.isEmpty()) ? System.getProperty("AMQ_PORT","61616") : result;
return result;
}
});
}catch(Throwable e){
LOG.debug("Failed to look up System properties for host and port",e); LOG.debug("Failed to look up System properties for host and port",e);
} }
host = (host == null || host.isEmpty()) ? "localhost" : host; host = (host == null || host.isEmpty()) ? "localhost" : host;
@ -92,7 +79,6 @@ public class ActiveMQConnectionFactory extends JNDIBaseStorable implements Conne
DEFAULT_BROKER_PORT = Integer.parseInt(port); DEFAULT_BROKER_PORT = Integer.parseInt(port);
} }
public static final String DEFAULT_BROKER_BIND_URL; public static final String DEFAULT_BROKER_BIND_URL;
static{ static{
@ -100,15 +86,9 @@ public class ActiveMQConnectionFactory extends JNDIBaseStorable implements Conne
String bindURL = null; String bindURL = null;
try { try {
bindURL = AccessController.doPrivileged(new PrivilegedAction<String>() { bindURL = System.getProperty("org.apache.activemq.BROKER_BIND_URL");
@Override bindURL = (bindURL==null||bindURL.isEmpty()) ? System.getProperty("BROKER_BIND_URL",defaultURL) : bindURL;
public String run() { } catch(Throwable e){
String result = System.getProperty("org.apache.activemq.BROKER_BIND_URL");
result = (result==null||result.isEmpty()) ? System.getProperty("BROKER_BIND_URL",defaultURL) : result;
return result;
}
});
}catch(Throwable e){
LOG.debug("Failed to look up System properties for host and port",e); LOG.debug("Failed to look up System properties for host and port",e);
} }
bindURL = (bindURL == null || bindURL.isEmpty()) ? defaultURL : bindURL; bindURL = (bindURL == null || bindURL.isEmpty()) ? defaultURL : bindURL;