Skip to content

Commit ab5cfed

Browse files
committed
Add JvmSslContextBrokerPlugin to set JVM default SSLContext from broker configuration
1 parent 9f38a49 commit ab5cfed

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.activemq.plugin;
18+
19+
import javax.net.ssl.SSLContext;
20+
21+
import org.apache.activemq.broker.BrokerPluginSupport;
22+
import org.apache.activemq.broker.SslContext;
23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
25+
26+
/**
27+
* A broker plugin that reads the broker's {@code <sslContext>} configuration of {@code activemq.xml} file
28+
* and sets it as the JVM default {@link SSLContext}.
29+
*
30+
* <p>This is useful as a workaround for older ActiveMQ versions (pre 6.3.x) where {@code ManagementContext} does
31+
* not support an {@code sslContext} property (See issue https://issues.apache.org/jira/browse/AMQ-9857)
32+
*
33+
* By setting the JVM default SSLContext, any component that uses {@code SSLContext.getDefault()}
34+
* (for instanceJMX configured via JVM flags with {@code -Dcom.sun.management.jmxremote.ssl=true}) will use the broker's
35+
* keyStore and trustStore.</p>
36+
*/
37+
public class JvmSslContextBrokerPlugin extends BrokerPluginSupport {
38+
39+
private static final Logger LOG = LoggerFactory.getLogger(JvmSslContextBrokerPlugin.class);
40+
41+
@Override
42+
public void start() throws Exception {
43+
super.start();
44+
45+
final SslContext brokerSslContext = getBrokerService().getSslContext();
46+
if (brokerSslContext != null) {
47+
final SSLContext ctx = brokerSslContext.getSSLContext();
48+
SSLContext.setDefault(ctx); // will override default JVM SSL Context
49+
LOG.info("JVM default SSLContext set from broker's sslContext (protocol: {})", ctx.getProtocol());
50+
51+
} else {
52+
LOG.debug("No sslContext configured on broker — JVM default SSLContext unchanged");
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)