8

我在 ubuntu 上使用 jboss AS 6 Final 和 hornetQ

我使用管理面板在名为 Message Buffer Queue 的服务器上创建了一个新队列。

我收到以下错误:

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

这是我的文件:

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());
    }
}

我的 HornetQ 配置文件是

<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>

我的堆栈跟踪是:

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!

问题似乎是什么问题?

4

2 回答 2

2

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>

于 2012-02-25T17:58:12.320 回答
0

我对 Jboss6 Final 也有类似的问题。

  • 您是否使用安全域(例如在您的 jboss.xml 中<security-domain>unirepo</security-domain>)?
  • 用户“guest”“guest”是否在您的安全域中进行了身份验证?(我知道它不应该是必要的,但似乎 Jboss 6 的奇怪行为)。

您也可以在这里查看:https ://issues.jboss.org/browse/JBAS-8895 和此处:http: //community.jboss.org/message/587605

它可能会在 jboss 6.1 中修复 :(

于 2011-06-09T14:09:24.280 回答