activemq User is not authorized to create: topic:/

2019-07-29 18:44发布

问题:

I am trying to use authorization in activemq, but stuck for some time now.

Here is my java code, everything works fine when I remove the authorization plugin. I am trying to create a topic named "room2".

        Context jndiContext = new InitialContext();
        ConnectionFactory connectionFactory;
        connectionFactory = (ConnectionFactory) jndiContext
                .lookup("ConnectionFactory");
        connection = connectionFactory.createConnection("system", "manager");
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic t = session.createTopic("room2");

Here is my activemq.xml :

<plugins>
                <simpleAuthenticationPlugin>
                        <users>
                                <authenticationUser username="system" password="manager"
                                        groups="admins,publishers,consumers"/>
                                <authenticationUser username="user" password="password"
                                        groups="admins,users,publishers"/>
                                <authenticationUser username="guest" password="password" groups="guests"/>
                        </users>
                </simpleAuthenticationPlugin>
                 <authorizationPlugin>
                        <map>
                                <authorizationMap>
                                        <authorizationEntries>
                                                <authorizationEntry topic="room2" read="consumers" write="publishers" admin="admins" />
                                        </authorizationEntries>
                                </authorizationMap>
                        </map>
                </authorizationPlugin> 
        </plugins>

This is the error that I get :

User system is not authorized to create: topic://ActiveMQ.Advisory.Connection

If I use <authorizationEntry topic=">" read="consumers" write="publishers" admin="admins" />, then it works fine, so what exactly does > mean?

回答1:

You need to assign roles to allow for the creation of Advisory Topics unless you just disable them. An example from the website is below.

<authorizationEntry topic="ActiveMQ.Advisory.>" read="guests,users" write="guests,users" admin="guests,users"/>

Refer to the documentation here.