AMQ-9431: Add org.apache.activemq.broker.BouncyCastleNotAdded system property to not load BouncyCastle in BrokerService

(cherry picked from commit 0a90f323ce)
This commit is contained in:
Jean-Baptiste Onofré 2024-03-02 08:28:31 +01:00
parent 0e7c607758
commit 012cac88dc
1 changed files with 13 additions and 10 deletions

View File

@ -271,17 +271,20 @@ public class BrokerService implements Service {
static { static {
try { try {
ClassLoader loader = BrokerService.class.getClassLoader(); Boolean bouncyCastleNotAdded = Boolean.getBoolean("org.apache.activemq.broker.BouncyCastleNotAdded");
Class<?> clazz = loader.loadClass("org.bouncycastle.jce.provider.BouncyCastleProvider"); if (bouncyCastleNotAdded == null || bouncyCastleNotAdded == false) {
Provider bouncycastle = (Provider) clazz.getDeclaredConstructor().newInstance(); ClassLoader loader = BrokerService.class.getClassLoader();
Integer bouncyCastlePosition = Integer.getInteger("org.apache.activemq.broker.BouncyCastlePosition"); Class<?> clazz = loader.loadClass("org.bouncycastle.jce.provider.BouncyCastleProvider");
int ret; Provider bouncycastle = (Provider) clazz.getDeclaredConstructor().newInstance();
if (bouncyCastlePosition != null) { Integer bouncyCastlePosition = Integer.getInteger("org.apache.activemq.broker.BouncyCastlePosition");
ret = Security.insertProviderAt(bouncycastle, bouncyCastlePosition); int ret;
} else { if (bouncyCastlePosition != null) {
ret = Security.addProvider(bouncycastle); ret = Security.insertProviderAt(bouncycastle, bouncyCastlePosition);
} else {
ret = Security.addProvider(bouncycastle);
}
LOG.info("Loaded the Bouncy Castle security provider at position: {}", ret);
} }
LOG.info("Loaded the Bouncy Castle security provider at position: {}", ret);
} catch(Throwable e) { } catch(Throwable e) {
// No BouncyCastle found so we use the default Java Security Provider // No BouncyCastle found so we use the default Java Security Provider
} }