Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HornetQ Unable to validate user

I am using jboss AS 6 Final on ubuntu with hornetQ

I have created a new Queue on the server named Message Buffer Queue using the admin panel.

I get the following error:

Unable to validate user: guest for check type CONSUME for address jms.queue.MessageBufferQueue

Here are my files:

package org.jboss.ejb3timers.example;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.UUID;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
import javax.jms.Queue;
import javax.jms.QueueBrowser;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.naming.Context;
import javax.naming.InitialContext;

public class TestClass {

    ConnectionFactory Hconnection=null;
    Queue  q=null;
    Connection Hconn=null;
    Context lContext=null;
    MessageConsumer messageConsumer=null;
    MessageProducer messageProducer=null;
    javax.jms.Session session=null;

    /**
     * @param args
     */

    public void sendMessagetoJMS(String sender,String receiver,String Message,String smsc,String Credit,String userid,long ctime,String savenumber)
    {
        int count=0;
        Hashtable<String, String> ht = new Hashtable<String, String>();
        ht.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
        ht.put(Context.PROVIDER_URL, "127.0.0.1");
        ht.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
        try{
            lContext = new InitialContext(ht);
            Hconnection = (ConnectionFactory) lContext.lookup("ConnectionFactory");
            q = (Queue) lContext.lookup("queue/MessageBufferQueue");
            Hconn = (Connection) Hconnection.createConnection("guest","guest");
            session =  Hconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
            messageProducer = session.createProducer(q);
            /*
             * Insert into Database
             */
            UUID id=UUID.randomUUID();

            Hconn.start();

            textmsg msg = new textmsg();
            msg.setReciever(receiver);
            msg.setSender(sender);
            msg.setText(Message);
            msg.setSmsc(smsc);
            msg.setCredit(Credit);
            msg.setUserid(userid);
            msg.setCtime(ctime);
            msg.setId(id.toString());
            ObjectMessage message = session.createObjectMessage();
            message.setObject(msg);
            messageProducer.send(message);
            System.out.println("Message sent ");
            Hconn.close();
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }

    public int getQueueSize()
    {
        Hashtable<String, String> ht = new Hashtable<String, String>();
        ht.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
        ht.put(Context.PROVIDER_URL, "127.0.0.1");
        ht.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
        InitialContext ctx;
        int numMsgs = 0;
        try {
            ctx = new InitialContext(ht);
            QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
            Queue queue = (Queue) ctx.lookup("queue/MessageBufferQueue");                                                                        
            QueueConnection queueConn = connFactory.createQueueConnection("guest","guest");
            QueueSession queueSession = queueConn.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
            QueueBrowser queueBrowser = queueSession.createBrowser(queue);
            queueConn.start();
            Enumeration e = queueBrowser.getEnumeration();
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS");;   
            String s=null;
            while (e.hasMoreElements()) {
                Message message = (Message) e.nextElement();
                s = df.format(message.getJMSTimestamp());
                System.out.println("=================1===================Timestamp it got to the queue"+s);
                numMsgs++;
            }
            queueConn.close();
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            System.out.println(e1.getMessage());
        }
        return numMsgs;
    }

    public static void main(String[] args) {
        int i = 0;
        TestClass tc = new TestClass();
        System.out.println(tc.getQueueSize());
        tc.sendMessagetoJMS("jk", "gv", "Hey there", "somesmsc", "34", "thedon", 234233634, "2423487");
        System.out.println(tc.getQueueSize());
    }
}

My HornetQ config file is

<configuration xmlns="urn:hornetq"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="urn:hornetq /schema/hornetq-configuration.xsd">

<!-- Make Queue Persistent -->
<persistence-enabled>true</persistence-enabled>
   <log-delegate-factory-class-name>org.hornetq.integration.logging.Log4jLogDelegateFactory</log-delegate-factory-class-name>

   <bindings-directory>${jboss.server.data.dir}/hornetq/bindings</bindings-directory>

   <journal-directory>${jboss.server.data.dir}/hornetq/journal</journal-directory>

   <!-- Default journal file size is set to 1Mb for faster first boot -->
   <journal-file-size>${hornetq.journal.file.size:1048576}</journal-file-size>

   <!-- Default journal min file is 2, increase for higher average msg rates -->
   <journal-min-files>${hornetq.journal.min.files:2}</journal-min-files>

<!-- create new user named guest as the default user -->
<defaultuser name="guest" password="guest">
        <role name="guest"/>
    </defaultuser>
<!-- create new user named admin with admin stuff -->
<user name="admin" password="admin">
        <role name="admin"/>
    </user>


   <large-messages-directory>${jboss.server.data.dir}/hornetq/largemessages</large-messages-directory>

   <paging-directory>${jboss.server.data.dir}/hornetq/paging</paging-directory>

   <connectors>
      <connector name="netty">
         <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
         <param key="host"  value="${jboss.bind.address:localhost}"/>
         <param key="port"  value="${hornetq.remoting.netty.port:5445}"/>
      </connector>

      <connector name="netty-throughput">
         <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
         <param key="host"  value="${jboss.bind.address:localhost}"/>
         <param key="port"  value="${hornetq.remoting.netty.batch.port:5455}"/>
         <param key="batch-delay" value="50"/>
      </connector>

      <connector name="in-vm">
         <factory-class>org.hornetq.core.remoting.impl.invm.InVMConnectorFactory</factory-class>
         <param key="server-id" value="${hornetq.server-id:0}"/>
      </connector>

   </connectors>

   <acceptors>  
      <acceptor name="netty">
         <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
         <param key="host"  value="${jboss.bind.address:localhost}"/>
         <param key="port"  value="${hornetq.remoting.netty.port:5445}"/>
      </acceptor>

      <acceptor name="netty-throughput">
         <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
         <param key="host"  value="${jboss.bind.address:localhost}"/>
         <param key="port"  value="${hornetq.remoting.netty.batch.port:5455}"/>
         <param key="batch-delay" value="50"/>
         <param key="direct-deliver" value="false"/>
      </acceptor>

      <acceptor name="in-vm">
        <factory-class>org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory</factory-class>
        <param key="server-id" value="0"/>
      </acceptor>
      </acceptors>

   <security-settings>
      <security-setting match="#">
         <permission type="createNonDurableQueue" roles="guest"/>
         <permission type="deleteNonDurableQueue" roles="guest"/>

<!-- Admin can create durable and non durable queues -->
<!-- Add permisions to make  a durabe queue for guest -->
         <permission type="createDurableQueue" roles="admin"/>
<!-- Add permisions to make  a durabe queue for guest -->
         <permission type="deleteDurableQueue" roles="admin"/>

         <permission type="consume" roles="guest"/>
         <permission type="send" roles="guest"/>
      </security-setting>
   </security-settings>

   <address-settings>
      <!--default for catch all-->
      <address-setting match="#">
         <dead-letter-address>jms.queue.DLQ</dead-letter-address>
         <expiry-address>jms.queue.ExpiryQueue</expiry-address>
         <redelivery-delay>0</redelivery-delay>
         <max-size-bytes>10485760</max-size-bytes>      
         <message-counter-history-day-limit>10</message-counter-history-day-limit>
         <address-full-policy>BLOCK</address-full-policy>
      </address-setting>
   </address-settings>

</configuration>

my stack trace is :

log4j:WARN No appenders could be found for logger (org.jnp.interfaces.TimedSocketFactory).
log4j:WARN Please initialize the log4j system properly.
Unable to validate user: guest for check type CONSUME for address jms.queue.MessageBufferQueue
0
javax.jms.JMSSecurityException: Unable to validate user: guest for check type SEND for address jms.queue.MessageBufferQueue
    at org.hornetq.core.protocol.core.impl.ChannelImpl.sendBlocking(ChannelImpl.java:287)
    at org.hornetq.core.client.impl.ClientProducerImpl.doSend(ClientProducerImpl.java:285)
    at org.hornetq.core.client.impl.ClientProducerImpl.send(ClientProducerImpl.java:139)
    at org.hornetq.jms.client.HornetQMessageProducer.doSend(HornetQMessageProducer.java:451)
    at org.hornetq.jms.client.HornetQMessageProducer.send(HornetQMessageProducer.java:199)
    at org.jboss.ejb3.timerservice.example.TestClass.sendMessagetoJMS(TestClass.java:70)
    at org.jboss.ejb3.timerservice.example.TestClass.main(TestClass.java:117)
Caused by: HornetQException[errorCode=105 message=Unable to validate user: guest for check type SEND for address jms.queue.MessageBufferQueue]
    ... 7 more
Unable to validate user: guest for check type CONSUME for address jms.queue.MessageBufferQueue
0
11 Apr, 2011 7:35:54 PM org.hornetq.core.logging.impl.JULLogDelegate warn
WARNING: I'm closing a JMS connection you left open. Please make sure you close all JMS connections explicitly before letting them go out of scope!

What seems to be the problem the problem ?

like image 781
Rishi Kolvekar Avatar asked Apr 11 '11 15:04

Rishi Kolvekar


1 Answers

it took me a long time to solve this issue, and the answer is the HornetQ reference documentation:

JBoss can be configured to allow client login, basically this is when a Java EE component such as a Servlet or EJB sets security credentials on the current security context and these are used throughout the call.

If you would like these credentials to be used by HornetQ when sending or consuming messages then set allowClientLogin to true. This will bypass HornetQ authentication and propgate the provided Security Context. If you would like HornetQ to authenticate using the propogated security then set the authoriseOnClientLogin to true also.

The important part is: if you would like these credentials to be used by HornetQ when sending or consuming messages then set allowClientLogin to true

In my case, for test purpose I disactivated authentication in my application, and thus the credentials were not propagated anymore in the security context.

While trying to create queues with
queueConnection = connectionFactory.createQueueConnection("guest", "guest"); I got the exception: HornetQException[errorCode=105 message=Unable to validate user: guest

And when trying to create queues with
queueConnection = connectionFactory.createQueueConnection(); I got the exception: HornetQException[errorCode=105 message=Unable to validate user: null

After setting allowClientLogin to true in $JBOSS_HOME/server//deploy/hornetq/hornetq-jboss-beans.xml, I finally succed in creating the queues.

<bean name="HornetQSecurityManager" class="org.hornetq.integration.jboss.security.JBossASSecurityManager"> <start ignored="true"/> <stop ignored="true"/> <depends>JBossSecurityJNDIContextEstablishment</depends> <property name="allowClientLogin">true</property> <property name="authoriseOnClientLogin">true</property> </bean>

like image 135
Akram Ben Aissi Avatar answered Nov 08 '22 17:11

Akram Ben Aissi