This is an automated email from the ASF dual-hosted git repository.
jbonofre pushed a commit to branch activemq-6.0.x
in repository https://gitbox.apache.org/repos/asf/activemq.git
The following commit(s) were added to refs/heads/activemq-6.0.x by this push:
new f1b7b8387 [AMQ-9216] Remove SeucrityManager usage from activemq-client
IdGenerator
f1b7b8387 is described below
commit f1b7b83870a46201a3eee2e0397213c90c4c4adc
Author: Matt Pavlovich <[email protected]>
AuthorDate: Wed Nov 22 10:41:00 2023 -0600
[AMQ-9216] Remove SeucrityManager usage from activemq-client IdGenerator
(cherry picked from commit e24c756e8d7902657f5fa7d4052879e8af217ae1)
---
.../transport/amqp/client/util/IdGenerator.java | 65 +++++++---------
.../java/org/apache/activemq/util/IdGenerator.java | 89 ++++++++++------------
2 files changed, 66 insertions(+), 88 deletions(-)
diff --git
a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/util/IdGenerator.java
b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/util/IdGenerator.java
index bdad73b25..60971b1f4 100644
---
a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/util/IdGenerator.java
+++
b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/client/util/IdGenerator.java
@@ -41,47 +41,36 @@ public class IdGenerator {
static {
String stub = "";
- boolean canAccessSystemProps = true;
+
+ int idGeneratorPort = 0;
+ ServerSocket ss = null;
try {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- sm.checkPropertiesAccess();
+ idGeneratorPort =
Integer.parseInt(System.getProperty(PROPERTY_IDGENERATOR_PORT, "0"));
+ LOG.trace("Using port {}", idGeneratorPort);
+ hostName = getLocalHostName();
+ ss = new ServerSocket(idGeneratorPort);
+ stub = "-" + ss.getLocalPort() + "-" + System.currentTimeMillis()
+ "-";
+ Thread.sleep(100);
+ } catch (Exception e) {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("could not generate unique stub by using DNS and
binding to local port", e);
+ } else {
+ LOG.warn("could not generate unique stub by using DNS and
binding to local port: {} {}", e.getClass().getCanonicalName(), e.getMessage());
}
- } catch (SecurityException se) {
- canAccessSystemProps = false;
- }
- if (canAccessSystemProps) {
- int idGeneratorPort = 0;
- ServerSocket ss = null;
- try {
- idGeneratorPort =
Integer.parseInt(System.getProperty(PROPERTY_IDGENERATOR_PORT, "0"));
- LOG.trace("Using port {}", idGeneratorPort);
- hostName = getLocalHostName();
- ss = new ServerSocket(idGeneratorPort);
- stub = "-" + ss.getLocalPort() + "-" +
System.currentTimeMillis() + "-";
- Thread.sleep(100);
- } catch (Exception e) {
- if (LOG.isTraceEnabled()) {
- LOG.trace("could not generate unique stub by using DNS and
binding to local port", e);
- } else {
- LOG.warn("could not generate unique stub by using DNS and
binding to local port: {} {}", e.getClass().getCanonicalName(), e.getMessage());
- }
-
- // Restore interrupted state so higher level code can deal
with it.
- if (e instanceof InterruptedException) {
- Thread.currentThread().interrupt();
- }
- } finally {
- if (ss != null) {
- try {
- ss.close();
- } catch (IOException ioe) {
- if (LOG.isTraceEnabled()) {
- LOG.trace("Closing the server socket failed", ioe);
- } else {
- LOG.warn("Closing the server socket failed" + "
due " + ioe.getMessage());
- }
+ // Restore interrupted state so higher level code can deal with it.
+ if (e instanceof InterruptedException) {
+ Thread.currentThread().interrupt();
+ }
+ } finally {
+ if (ss != null) {
+ try {
+ ss.close();
+ } catch (IOException ioe) {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Closing the server socket failed", ioe);
+ } else {
+ LOG.warn("Closing the server socket failed" + " due "
+ ioe.getMessage());
}
}
}
diff --git
a/activemq-client/src/main/java/org/apache/activemq/util/IdGenerator.java
b/activemq-client/src/main/java/org/apache/activemq/util/IdGenerator.java
index 09a565803..1404536da 100644
--- a/activemq-client/src/main/java/org/apache/activemq/util/IdGenerator.java
+++ b/activemq-client/src/main/java/org/apache/activemq/util/IdGenerator.java
@@ -41,63 +41,52 @@ public class IdGenerator {
static {
String stub = "";
- boolean canAccessSystemProps = true;
- try {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- sm.checkPropertiesAccess();
- }
- } catch (SecurityException se) {
- canAccessSystemProps = false;
- }
-
- if (canAccessSystemProps) {
- hostName = System.getProperty(PROPERTY_IDGENERATOR_HOSTNAME);
- int localPort =
Integer.parseInt(System.getProperty(PROPERTY_IDGENERATOR_LOCALPORT, "0"));
+ hostName = System.getProperty(PROPERTY_IDGENERATOR_HOSTNAME);
+ int localPort =
Integer.parseInt(System.getProperty(PROPERTY_IDGENERATOR_LOCALPORT, "0"));
- int idGeneratorPort = 0;
- ServerSocket ss = null;
- try {
- if( hostName==null ) {
- hostName = InetAddressUtil.getLocalHostName();
- }
- if( localPort==0 ) {
- idGeneratorPort =
Integer.parseInt(System.getProperty(PROPERTY_IDGENERATOR_PORT, "0"));
- LOG.trace("Using port {}", idGeneratorPort);
- ss = new ServerSocket(idGeneratorPort);
- localPort = ss.getLocalPort();
- stub = "-" + localPort + "-" + System.currentTimeMillis()
+ "-";
- Thread.sleep(100);
- } else {
- stub = "-" + localPort + "-" + System.currentTimeMillis()
+ "-";
- }
- } catch (Exception e) {
- if (LOG.isTraceEnabled()) {
- LOG.trace("could not generate unique stub by using DNS and
binding to local port", e);
- } else {
- LOG.warn("could not generate unique stub by using DNS and
binding to local port: {} {}", e.getClass().getCanonicalName(), e.getMessage());
- }
+ int idGeneratorPort = 0;
+ ServerSocket ss = null;
+ try {
+ if( hostName==null ) {
+ hostName = InetAddressUtil.getLocalHostName();
+ }
+ if( localPort==0 ) {
+ idGeneratorPort =
Integer.parseInt(System.getProperty(PROPERTY_IDGENERATOR_PORT, "0"));
+ LOG.trace("Using port {}", idGeneratorPort);
+ ss = new ServerSocket(idGeneratorPort);
+ localPort = ss.getLocalPort();
+ stub = "-" + localPort + "-" + System.currentTimeMillis() +
"-";
+ Thread.sleep(100);
+ } else {
+ stub = "-" + localPort + "-" + System.currentTimeMillis() +
"-";
+ }
+ } catch (Exception e) {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("could not generate unique stub by using DNS and
binding to local port", e);
+ } else {
+ LOG.warn("could not generate unique stub by using DNS and
binding to local port: {} {}", e.getClass().getCanonicalName(), e.getMessage());
+ }
- // Restore interrupted state so higher level code can deal
with it.
- if (e instanceof InterruptedException) {
- Thread.currentThread().interrupt();
- }
- } finally {
- if (ss != null) {
- try {
- // TODO: replace the following line with
IOHelper.close(ss) when Java 6 support is dropped
- ss.close();
- } catch (IOException ioe) {
- if (LOG.isTraceEnabled()) {
- LOG.trace("Closing the server socket failed", ioe);
- } else {
- LOG.warn("Closing the server socket failed" + "
due " + ioe.getMessage());
- }
+ // Restore interrupted state so higher level code can deal with it.
+ if (e instanceof InterruptedException) {
+ Thread.currentThread().interrupt();
+ }
+ } finally {
+ if (ss != null) {
+ try {
+ // TODO: replace the following line with
IOHelper.close(ss) when Java 6 support is dropped
+ ss.close();
+ } catch (IOException ioe) {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Closing the server socket failed", ioe);
+ } else {
+ LOG.warn("Closing the server socket failed" + " due "
+ ioe.getMessage());
}
}
}
}
+
// fallback
if (hostName == null) {
hostName = "localhost";