Nelly Junior
Nelly Junior

Reputation: 566

Create a security level through authentification when connecting to a ActiveMQ destination

I use Apache Activemq version 5.14.4 to send some messages into a queue and to read them. I want to implement a security level so as when I connect to the destination to be asked to give a username and a password.

Reading the official documentation for ActiveMQ security and looking at a lot of examples including these: example1, example2, I choose to use the Simple Authentication Plugin to achieve this.

So, in my activemq.xml, inside broker element I wrote the plugin:

<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}">

    <simpleAuthenticationPlugin>
        <users>
            <authenticationUser username="Admin01" password="anything" groups="users,admins"/>
        </users>
    </simpleAuthenticationPlugin>


    <authorizationPlugin>
        <map>
            <authorizationMap>
                <authorizationEntries>
                    <authorizationEntry queue=">" write="producers" read="consumers" admin="admins" />  
                    <authorizationEntry topic="ActiveMQ.Advisory.>" admin="admins" />                       
                </authorizationEntries>
            </authorizationMap>
        </map>
    </authorizationPlugin>
 ...
</broker>

Doing so, I expected to be asked about a username and a password in order to connect to a destination to consume the messages from the queue.

I create the connection and destination this way:

String username = "Admin01";
String password = "anithing"
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
factory.setTrustedPackages(Arrays.asList("myClass.package_name"));
Connection connection = null;
Session session = null;
Destination destination = null;
    try {
        connection = factory.createConnection(username, password);
        connection.start();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        destination = session.createQueue("myQueue");
...

The ActiveMQ broker is created and when the events that I want to sent occurs, they are sent to myQueue. (I also tryed withowt setting any username and password to the factory with factory.setPassword() and factory.setUserName() or setting the username and password only to the connection, or both and there is no exception thrown when I don't set any username and password).

Well If I want to consume the messages from the queue I intentionally not set any password and there is no exception thrown and the messages are consumed. (I expected to be thrown an exception asking for the username and password. Also I tried with wrong username and password).

    private void consumeMessage() {
        String userName = "Admin01";
        String password = "anything";
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
//      factory.setUserName(userName);
//      factory.setPassword(password);
        factory.setTrustAllPackages(true);
        Destination destination = null;
        try {
            connection = factory.createConnection();
            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            destination = session.createQueue("myQueue");
            consumer = session.createConsumer(destination);
            consumer.setMessageListener(this);
            connection.start();
        }catch(JMSException e) {
            e.printStackTrace();
        } 
    }

I have overridden the credentials.properties file: Default values:

activemq.username=system
activemq.password=manager
guest.password=password

Overridden:

activemq.username=Admin01
activemq.password=anything

I also overridden the files: groups.properties file to admins=Admin01 and users.properties to admin=Admin01 and still no password asked.

All files mentioned above are in \apache-activemq-5.14.4\conf directory.

What can I do to implement this security level on ActiveMQ so as, when I want to connect to the destination in order to consume the messages from "myQueue" to be asked for the username and password?

Upvotes: 0

Views: 745

Answers (1)

Hassen Bennour
Hassen Bennour

Reputation: 3913

By default <simpleAuthenticationPlugin anonymousAccessAllowed="false"> deny anonymous access.

Upvotes: 2

Related Questions