Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.Chapter 4. Securing an Apache ActiveMQ Broker
Abstract
Apache ActiveMQ provides two layers of security: an SSL/TLS security layer, which can authenticate the broker to its clients, encrypt messages, and guarantee message integrity, and a JAAS security layer, which can authenticate clients to the broker. This chapter describes the approach you should take to enable both of these security layers, when the broker is deployed in the Red Hat JBoss Fuse OSGi container.
4.1. Tutorial I: SSL/TLS Security Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Overview Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The purpose of this tutorial is to show how you can deploy a secure Apache ActiveMQ broker in the OSGi container, where one or more of the broker's endpoints has SSL/TLS enabled. Unlike an insecure broker, you cannot deploy a secure broker simply by dropping its XML configuration file into the hot deploy directory, as described in section "Hot Deployment" in "Deploying into the Container". This is because a secure broker must be accompanied by X.509 certificates and their keys. It is necessary, therefore, to package the broker configuration file together with its certificates and keys in a single OSGi bundle.
This tutorial explains how to use the Maven build tool to create an OSGi bundle containing the secure broker's configuration and its accompanying certificates and keys. After deploying the broker into the OSGi container, you test it using the sample JMS clients from the standalone Apache ActiveMQ distribution (which you can obtain from the Red Hat JBoss Fuse download page).
Prerequisites Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The following prerequisites are needed for this tutorial:
- Maven installation—Maven is a free, open source build tool from Apache. You can download the latest version from http://maven.apache.org/download.html (minimum is 2.2).
- Internet connection—whilst performing a build, Maven dynamically searches external repositories and downloads the required artifacts on the fly. In order for this to work, your build machine must be connected to the Internet.
- Apache ActiveMQ installation—the standalone installation of Apache ActiveMQ has some demonstration code that is not available in Red Hat JBoss Fuse. Download and install Apache ActiveMQ 5.8.0.redhat-60024 from fusesource.com.
Tutorial steps Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
To configure SSL/TLS security for a broker deployed in the OSGi container, perform the following steps:
Generate a Maven project Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The
maven-archetype-quickstart
archetype creates a generic Maven project, which you can then customize for whatever purpose you like. To generate a Maven project with the coordinates, org.jbossfuse.example:esb-security
, enter the following command:
mvn archetype:create -DarchetypeArtifactId=maven-archetype-quickstart -DgroupId=org.jbossfuse.example -DartifactId=esb-security
mvn archetype:create
-DarchetypeArtifactId=maven-archetype-quickstart
-DgroupId=org.jbossfuse.example
-DartifactId=esb-security
The result of this command is a directory,
ProjectDir/esb-security
, containing the files for the generated project.
Note
Be careful not to choose a group ID for your artifact that clashes with the group ID of an existing product! This could lead to clashes between your project's packages and the packages from the existing product (because the group ID is typically used as the root of a project's Java package names).
Customize the POM file Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
You must customize the POM file in order to generate an OSGi bundle, as follows:
- Follow the POM customization steps described in section "Generating a Bundle Project" in "Deploying into the Container".
- In the configuration of the Maven bundle plug-in, modify the bundle instructions to import additional Java packages, as follows:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Note
Not all of these packages are required by the current tutorial. It is convenient, however, to add all of the packages required by the subsequent tutorials at this point.
Install sample keystore files Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The broker requires the following keystore files:
- Key store containing broker's own certificate and private key—used to identify the broker during an SSL handshake.
- Trust store containing CA certificate—used to verify that a received client certificate is correctly signed (strictly speaking, the trust store file is only needed by the broker, if the
transport.needClientAuth
options is set totrue
on the broker URI).
For this tutorial, you can use the demonstration certificates provided with the standalone version of Apache ActiveMQ. In the Maven project, create the following
conf
directory to store the broker's keystore files:
ProjectDir/esb-security/src/main/resources/conf
ProjectDir/esb-security/src/main/resources/conf
Copy the
broker.ks
and broker.ts
files from the Apache ActiveMQ standalone conf
directory, ActiveMQInstallDir/conf
, to the conf
directory that you just created.
Warning
Configure the broker Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
To configure the broker, create the following
spring
directory to store Spring XML files:
ProjectDir/esb-security/src/main/resources/META-INF/spring
ProjectDir/esb-security/src/main/resources/META-INF/spring
In the
spring
directory that you just created, use your favorite text editor to create the file, broker-spring.xml
, containing the following XML configuration:
Note the following key aspects of the broker configuration:
- The Openwire network connector is configured to use SSL,
ssl://localhost:61001
. - The key store and trust store file locations and passwords are specified by the broker's
sslContext
element.
Build the broker bundle Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Use Maven to build the broker bundle. Open a command prompt, switch the current directory to
ProjectDir/esb-security
, and enter the following command:
mvn install
mvn install
This command builds the broker bundle and installs it in your local Maven repository.
Deploy the broker bundle Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
If you have not already done so, start up the Apache ServiceMix console (and container instance) by entering the following command in a new command prompt:
servicemix
servicemix
To deploy and activate the broker bundle, enter the following console command:
JBossFuse:karaf@root> osgi:install -s mvn:org.jbossfuse.example/esb-security
JBossFuse:karaf@root> osgi:install -s mvn:org.jbossfuse.example/esb-security
The preceding command loads the broker bundle from your local Maven repository. You might need to configure the Mvn URL handler with the location of your local Maven repository, if the broker bundle cannot be found (see section "Mvn URL Handler" in "Deploying into the Container").
Configure the consumer and the producer clients Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
To test the broker configured in the OSGi container, you are going to use the example consumer tool and producer tool supplied with the standalone version of Red Hat JBoss A-MQ.
Configure the consumer and the producer clients to pick up the client trust store. Edit the Ant build file,
ActiveMQInstallDir/example/build.xml
, and add the javax.net.ssl.trustStore
and javax.net.ssl.trustStorePassword
JSSE system properties to the consumer target and the producer target as shown in the following example:
In the context of the Ant build tool, this is equivalent to adding the system properties to the command line.
Run the consumer with the SSL protocol Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
To connect the consumer tool to the
ssl://localhost:61001
endpoint (Openwire over SSL), change directory to ActiveMQInstallDir/example
and enter the following command:
ant consumer -Durl=ssl://localhost:61001 -Dmax=100
ant consumer -Durl=ssl://localhost:61001 -Dmax=100
You should see some output like the following:
Run the producer with the SSL protocol Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
To connect the producer tool to the
ssl://localhost:61001
endpoint, open a new command prompt, change directory to example
and enter the following command:
ant producer -Durl=ssl://localhost:61001 -Dmax=100
ant producer -Durl=ssl://localhost:61001 -Dmax=100
In the window where the consumer tool is running, you should see some output like the following:
[java] Received: Message: 0 sent at: Thu Feb 05 09:27:43 GMT 2009 ... [java] Received: Message: 1 sent at: Thu Feb 05 09:27:43 GMT 2009 ... [java] Received: Message: 2 sent at: Thu Feb 05 09:27:43 GMT 2009 ... [java] Received: Message: 3 sent at: Thu Feb 05 09:27:43 GMT 2009 ...
[java] Received: Message: 0 sent at: Thu Feb 05 09:27:43 GMT 2009 ...
[java] Received: Message: 1 sent at: Thu Feb 05 09:27:43 GMT 2009 ...
[java] Received: Message: 2 sent at: Thu Feb 05 09:27:43 GMT 2009 ...
[java] Received: Message: 3 sent at: Thu Feb 05 09:27:43 GMT 2009 ...
Uninstall the broker bundle Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
To uninstall the broker bundle, you need to know its bundle ID, BundleID, in which case you can uninstall it by entering the following console command:
JBossFuse:karaf@root> osgi:uninstall BundleID
JBossFuse:karaf@root> osgi:uninstall BundleID
If you are unsure of the broker's bundle ID, list the installed bundles using the
osgi:list
command, as follows:
JBossFuse:karaf@root> osgi:list
JBossFuse:karaf@root> osgi:list
Which should produce output like the following:
... [ 231] [Active ] [ ] [ ] [ 60] camel-jms (2.4.0.fuse-00-00) [ 232] [Active ] [ ] [ ] [ 60] activemq-camel (5.4.0.fuse-00-00) [ 245] [Installed ] [ ] [ ] [ 60] esb-security (1.0.0.SNAPSHOT)
...
[ 231] [Active ] [ ] [ ] [ 60] camel-jms (2.4.0.fuse-00-00)
[ 232] [Active ] [ ] [ ] [ 60] activemq-camel (5.4.0.fuse-00-00)
[ 245] [Installed ] [ ] [ ] [ 60] esb-security (1.0.0.SNAPSHOT)
From the preceding output, you can see that the
esb-security
bundle has the bundle ID, 245
.