Question

Environment:

Jboss 7.1.0 OS Windows

I am trying a simple test to try out JMS using Jboss with the built in HornetQ JMS provider. After a lot of playing around i managed to get a response with this configuration

        final Properties env = new Properties();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
        env.put(Context.PROVIDER_URL, "remote://localhost:4447");
        env.put(Context.SECURITY_PRINCIPAL, "appuser2");
        env.put(Context.SECURITY_CREDENTIALS, "s3cr3t");        

The problem though is that when i run it i get the following error:

javax.jms.JMSSecurityException: Unable to validate user: null
    at org.hornetq.core.protocol.core.impl.ChannelImpl.sendBlocking(ChannelImpl.java:286)
    at org.hornetq.core.client.impl.ClientSessionFactoryImpl.createSessionInternal(ClientSessionFactoryImpl.java:695)
    at org.hornetq.core.client.impl.ClientSessionFactoryImpl.createSession(ClientSessionFactoryImpl.java:264)
    at org.hornetq.jms.client.HornetQConnection.authorize(HornetQConnection.java:589)
    at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:694)
    at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:121)
    at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:116)
    at com.jms.client.ConsoleClient.runExample(ConsoleClient.java:51)
    at com.jms.client.ConsoleClient.main(ConsoleClient.java:20)
Caused by: HornetQException[errorCode=105 message=Unable to validate user: null]
    ... 9 more

I have been looking around on Google and every example seems to point to how to configure the security settings with HornetQ as a standalone server. I cant figure out how to configure the user on Jboss and whether i even need to.

Any ideas?

Was it helpful?

Solution

I agree with Sergiu and would add the queue can be set up without requiring username and password.

OTHER TIPS

It seems that you create a QueueConnection with a username and password as following:

QueueConnection qcon = qconFactory.createQueueConnection("appuser2","s3cr3t");

If you don't do this you will get this error

Unable to validate user: null.

And if you do not want to use username and password, you can set security-enabled with value false as following:

<subsystem xmlns="urn:jboss:domain:messaging:1.1">
     <hornetq-server>
         <security-enabled>false</security-enabled>
         ......
     </hornetq-server>
</subsystem>

Then you can create a QueueConnection without a username and password as following:

QueueConnection qcon = qconFactory.createQueueConnection();

it worked for me. I just added following in standalone-full.xml:

            <security-enabled>false</security-enabled> 

Check your standalone-full.xml. If the configurations for role in urn:jboss:domain:messaging-activemq:1.0 look like this:

<security-setting name="#">
   <role name="guest" send="true" consume="true" create-non-durable-queue="true" delete-non-durable-queue="true"/>
</security-setting>

Then, you have to:

  1. Create a guest user (make sure you set the role guest to the user);
  2. Set initial context as below:
Properties props = new Properties();
props.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
props.put(Context.SECURITY_PRINCIPAL, "username");
props.put(Context.SECURITY_CREDENTIALS, "password");
InitialContext ctx = new InitialContext(props);
  1. Create context as below:
ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
Queue queue = (Queue) ctx.lookup("jms/queue/queueName");
JMSContext context = cf.createContext("username", "password");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top