javax.jms.JMSSecurityException: Unable to validate user: null
Asked Answered
D

7

5

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?

Demilune answered 2/3, 2012 at 21:13 Comment(1)
I remember having this problem some time ago with JBoss 5.1.0GA . I remember fixing it by adding in the hornetq.sar/hornetq-users.xml the proper user / each queue . I don't know how hornetQ is used in JBoss 7 but maybe this hint will point you in the right direction.Sympathetic
M
0

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

Malissamalissia answered 25/4, 2012 at 19:10 Comment(0)
B
18

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();
Bonbon answered 8/7, 2012 at 3:15 Comment(0)
B
3

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");
Basis answered 9/8, 2017 at 9:52 Comment(0)
P
2

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

            <security-enabled>false</security-enabled> 
Provo answered 6/11, 2015 at 4:48 Comment(0)
I
2

If someone is using JBoss EAP 7.2 version, then here is the solution.

If you don't want to disable the security by adding the tag <security enabled="false"/>, and wish to authenticate with username and password, then please follow the below steps.

  1. Whatever username (say, 'jmsuser') and password (say, 'pass') you have written in your code, that exact user ('jmsuser') needs to be created first in JBoss. Please use the add-user utility under bin folder and add the user as an application user and assign it to the "guest" role, when prompted.

screenshot_add_user

  1. After the above step, the username and the role details can be found in the application-role.properties and application-users.properties file \standalone\configuration path.

  2. Restart the JBoss server.

  3. Assuming you are using JMS 2.0 specification, then create the JMSContext like below.

JMSContext jmsCtx = connectionFactory.createContext("jmsuser", "pass");
  1. Run the code now and you will not face this error again.
Improvise answered 8/6, 2021 at 19:9 Comment(0)
C
1

If you are using WildFly 10+ (I use WildFly 18), you have to disable security by adding:

<security enabled="false"/>

in your standalone-full.xml (wildFly directory/standalone/configuration) inside of:

    <subsystem xmlns="urn:jboss:domain:messaging-activemq:8.0">

and

<server name="default">

Something like that:

<subsystem xmlns="urn:jboss:domain:messaging-activemq:8.0">
                <server name="default">
			
                <!-- Disable security with the following row, otherwise of course it will give error without authentication in java -->
                <security enabled="false"/>
				
                <statistics enabled="${wildfly.messaging-activemq.statistics-enabled:${wildfly.statistics-enabled:false}}"/>
                <security-setting name="#">
                    <role name="guest" send="true" consume="true" create-non-durable-queue="true" delete-non-durable-queue="true"/>
                </security-setting>
                <address-setting name="#" dead-letter-address="jms.queue.DLQ" expiry-address="jms.queue.ExpiryQueue" max-size-bytes="10485760" page-size-bytes="2097152" message-counter-history-day-limit="10"/>
                <http-connector name="http-connector" socket-binding="http" endpoint="http-acceptor"/>
                <http-connector name="http-connector-throughput" socket-binding="http" endpoint="http-acceptor-throughput">
                    <param name="batch-delay" value="50"/>
                </http-connector>
                <in-vm-connector name="in-vm" server-id="0">
                    <param name="buffer-pooling" value="false"/>
                </in-vm-connector>
                <http-acceptor name="http-acceptor" http-listener="default"/>
                <http-acceptor name="http-acceptor-throughput" http-listener="default">
                    <param name="batch-delay" value="50"/>
                    <param name="direct-deliver" value="false"/>
                </http-acceptor>
                <in-vm-acceptor name="in-vm" server-id="0">
                    <param name="buffer-pooling" value="false"/>
                </in-vm-acceptor>
                <jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/>
                <jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/>
                <!-- Adding a new queue -->
		<jms-queue name="ShippingQueue" entries="java:jboss/exported/jms/queue/ShippingQueue"/>
				

                <connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>
                <connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector"/>
                <pooled-connection-factory name="activemq-ra" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm" transaction="xa"/>

            </server>
        </subsystem>

Check on: https://developer.jboss.org/thread/271457

Combustor answered 18/5, 2020 at 13:42 Comment(0)
M
0

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

Malissamalissia answered 25/4, 2012 at 19:10 Comment(0)
A
0

Add the queue to jboss using from cli:

jms-topic add --topic-address=testTopic -–entries=topic/test,java:jboss/exported/jms/topic/test

Add the user as follows:

add-user.bat -a -u mquser -p mqpassword -g guest

Consumer paste the code in main method:

Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,"org.wildfly.naming.client.WildFlyInitialContextFactory");
properties.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
properties.put("jboss.naming.client.ejb.context", true);
properties.put("java.naming.security.principal", "mquser");
properties.put("java.naming.security.credentials", "mqpassword");
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

QueueConnection cnn = null;
QueueSender sender = null;
QueueSession session = null;
InitialContext ctx = new InitialContext(properties);
Queue queue = (Queue) ctx.lookup("jms/queue/tests");
QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
cnn =  factory.createQueueConnection("mquser", "mqpassword");
cnn.start();

session = cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
TextMessage msg = session.createTextMessage("Hello World");
sender = session.createSender(queue);
sender.send(msg);

System.out.println("Message sent successfully to remote queue.");

@MessageDriven(name = "ExampleMDB", activationConfig = {
    @ActivationConfigProperty(propertyName = "destination", propertyValue = "testQueues"), @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")
public class ExampleMDB implements MessageListener {

    /**
     * Default constructor. 
     */
    public ExampleMDB() {
        // TODO Auto-generated constructor stub
    }


    @Override
    public void onMessage(Message arg0) {
        System.out.println("----------------");
        try {
            System.out.println("Received message" + ((TextMessage)arg0).getText());
        } catch (JMSException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println("----------------");

    }

}
Applicant answered 2/5, 2020 at 11:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.