activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tarjei Skorgenes (JIRA)" <>
Subject [jira] [Created] (AMQ-4249) Race condition in PropertiesLoginModule
Date Sat, 12 Jan 2013 00:52:12 GMT
Tarjei Skorgenes created AMQ-4249:

             Summary: Race condition in PropertiesLoginModule
                 Key: AMQ-4249
             Project: ActiveMQ
          Issue Type: Bug
          Components: Broker
    Affects Versions: 5.7.0, 5.6.0, 5.5.1
         Environment: ActiveMQ 5.5.1 with JAAS authentication via PropertiesLoginModule configured,
Spring JMS 3.0.5, 64-bit, Intel quad core CPU (i7 950), Windows 7

            Reporter: Tarjei Skorgenes
            Priority: Minor

h1. Problem

While setting up a connection pool towards ActiveMq 5.5.1 using Bitronix 2.1.3 I've been having
some issues related to authentication and authorization of the JMS connections.

When doing a clean restart of the JMS-clients JVM the connection pool has been unable to connect
successfully with one or more of the 14 connections it's been set up to use.

The error messages I've been getting has usually been one of the following two:

# User system is not authorized to read from: ActiveMQ.Advisory.TempQueue,ActiveMQ.Advisory.TempTopic
# User name or password is invalid.

The broker has been set up using a very simplistic configuration:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
	xmlns:xsi="" xmlns:context=""

	<context:property-placeholder />

	<broker brokerId="localhost" xmlns=""
		dataDirectory="${datadir}" start="false">
			<managementContext connectorHost=""
				connectorPort="14522" createConnector="true" />
			<jaasAuthenticationPlugin configuration="activemq-domain"
				discoverLoginConfig="true" />
							<authorizationEntry queue=">" read="admins"
								write="admins" admin="admins" />

							<authorizationEntry topic=">" read="admins"
								write="admins" admin="admins" />

							<authorizationEntry topic="ActiveMQ.Advisory.>"
								read="guests,users" write="guests,users" admin="guests,users" />
			<transportConnector id="openwire" uri="tcp://" />

The JAAS-configuration has been verified to match username and password used by the client
when connecting (username = system):

h4. login.config

activemq-domain {
    org.apache.activemq.jaas.PropertiesLoginModule required



h1. Cause

After debugging the problem it seems as if the problem is caused by a race condition introduced
in PropertiesLoginModule in revision [1086219|]
(AMQ-3244). When the reload-support was added the users- and groups-fields were changed into
static fields. But no additional synchronization was introduced, thereby introducing a race
condition when several threads are entering the initialize- and commit-methods are the same

The following section of the initialize-method in PropertiesLoginModule contains the first
part of the race condition. Please note the unsynchronized modification of both the users-
and groups static fields:

        if (reload || users == null || uf.lastModified() > usersReloadTime) {
            if (debug) {
                LOG.debug("Reloading users from " + uf.getAbsolutePath());
            try {
                users = new Properties(); // XXX Here be dragons
       in = new;
                usersReloadTime = System.currentTimeMillis();
            } catch (IOException ioe) {
                LOG.warn("Unable to load user properties file " + uf);

        groupsFile = (String) options.get(GROUP_FILE) + "";
        File gf = baseDir != null ? new File(baseDir, groupsFile) : new File(groupsFile);
        if (reload || groups == null || gf.lastModified() > groupsReloadTime) {
            if (debug) {
                LOG.debug("Reloading groups from " + gf.getAbsolutePath());
            try {
                groups = new Properties(); // XXX Here be dragons
       in = new;
                groupsReloadTime = System.currentTimeMillis();
            } catch (IOException ioe) {
                LOG.warn("Unable to load group properties file " + gf);

The next part comes in the login-method when the users password is retrieved:

        String password = users.getProperty(user); 

The final part of the puzzle occurs in the commit-method:
            for (Enumeration<?> enumeration = groups.keys(); enumeration.hasMoreElements();)
                String name = (String)enumeration.nextElement();
                String[] userList = ((String)groups.getProperty(name) + "").split(",");
                for (int i = 0; i < userList.length; i++) {
                    if (user.equals(userList[i])) {
                        principals.add(new GroupPrincipal(name));

The retrieval of the user password will fail if invoked by a thread immediately after a different
thread has assigned an empty Properties-object to the users field in the initialize-method.

Similarly population of the GroupPrincipals into the Subject in the commit-method will silently
fail if executed by a thread immediately after a different thread has assigned an empty Properties-object
to the groups-field in the initialize-method.

h1. Proposed solution

I've created a testcase that illustrates the problem and an additional patch that introduces
a wrapper around the Properties-objects for the users- and groups-fields. The wrapper uses
a read-write lock to synchronize access and modification of the properties-objects containing
the users and groups.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message