JBoss JMS: ERROR: JBREM000200: Remote connection failed: javax.security.sasl.SaslException: Authentication failed: Server presented

I am writing a JMS consumer example, a producer example in JBoss AS 7.1.1. I followed the tutorials closely and followed the following steps -

The user testuser / testpassword is created with testrole and testrole is present in the standalone-full.xml file

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

      

I am using default connectionfactory and destination as stated in standalone-full.xml file -

    <connection-factory name="InVmConnectionFactory">
        <connectors>
            <connector-ref connector-name="in-vm" />
        </connectors>
        <entries>
            <entry name="java:/ConnectionFactory" />
        </entries>
    </connection-factory>
    <connection-factory name="RemoteConnectionFactory">
        <connectors>
            <connector-ref connector-name="netty" />
        </connectors>
        <entries>
            <entry name="RemoteConnectionFactory" />
            <entry name="java:jboss/exported/jms/RemoteConnectionFactory" />
        </entries>
    </connection-factory>

    <jms-queue name="testQueue">
        <entry name="queue/test" />
        <entry name="java:jboss/exported/testQueue" />
    </jms-queue>

      

Here is the POM file -

    <dependency>
        <groupId>org.hornetq</groupId>
        <artifactId>hornetq-core</artifactId>
        <version>2.0.0.GA</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.hornetq</groupId>
        <artifactId>hornetq-jms</artifactId>
        <version>2.0.0.GA</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.hornetq</groupId>
        <artifactId>hornetq-transports</artifactId>
        <version>2.0.0.GA</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.netty</groupId>
        <artifactId>netty</artifactId>
        <version>3.1.0.GA</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.javaee</groupId>
        <artifactId>jboss-jms-api</artifactId>
        <version>1.1.0.GA</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss</groupId>
        <artifactId>jboss-ejb-client</artifactId>
        <version>2.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.jboss</groupId>
        <artifactId>jboss-remote-naming</artifactId>
        <version>2.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.xnio</groupId>
        <artifactId>xnio-api</artifactId>
        <version>3.2.3.Final</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.xnio</groupId>
        <artifactId>xnio-nio</artifactId>
        <version>3.2.3.Final</version>
    </dependency>

      

Here is my example code -

package com.howtodoinjava;

import java.util.logging.Logger;
import java.util.Properties;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;

public class HelloWorldJMS {
    private static final Logger log = Logger.getLogger(HelloWorldJMS.class.getName());

    // Set up all the default values
    private static final String DEFAULT_MESSAGE = "Hello, World!";
    private static final String DEFAULT_CONNECTION_FACTORY = "RemoteConnectionFactory";
    private static final String DEFAULT_DESTINATION = "testQueue";
    private static final String DEFAULT_MESSAGE_COUNT = "1";
    private static final String DEFAULT_USERNAME = "testuser";
    private static final String DEFAULT_PASSWORD = "testpassword";
    private static final String INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";
    private static final String PROVIDER_URL = "remote://localhost:4447";

    public static void main(String[] args) throws Exception {

        ConnectionFactory connectionFactory = null;
        Connection connection = null;
        Session session = null;
        MessageProducer producer = null;
        MessageConsumer consumer = null;
        Destination destination = null;
        TextMessage message = null;
        Context context = null;

        try {
            // Set up the context for the JNDI lookup
            final Properties env = new Properties();
            env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
            env.put(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL, PROVIDER_URL));
            env.put(Context.SECURITY_PRINCIPAL, System.getProperty("username", DEFAULT_USERNAME));
            env.put(Context.SECURITY_CREDENTIALS, System.getProperty("password", DEFAULT_PASSWORD));
            env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false"); 
            context = new InitialContext(env);

            // Perform the JNDI lookups
            String connectionFactoryString = System.getProperty("connection.factory", DEFAULT_CONNECTION_FACTORY);
            log.info("Attempting to acquire connection factory \"" + connectionFactoryString + "\"");
            connectionFactory = (ConnectionFactory) context.lookup(connectionFactoryString);

            String destinationString = System.getProperty("destination", DEFAULT_DESTINATION);
            destination = (Destination) context.lookup(destinationString);

            // Create the JMS connection, session, producer, and consumer
            connection = connectionFactory.createConnection(System.getProperty("username", DEFAULT_USERNAME), System.getProperty("password", DEFAULT_PASSWORD));
            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            producer = session.createProducer(destination);
            consumer = session.createConsumer(destination);
            connection.start();

            int count = Integer.parseInt(System.getProperty("message.count", DEFAULT_MESSAGE_COUNT));
            String content = System.getProperty("message.content", DEFAULT_MESSAGE);

            log.info("Sending " + count + " messages with content: " + content);

            // Send the specified number of messages
            for (int i = 0; i < count; i++) {
                message = session.createTextMessage(content);
                producer.send(message);
            }

            // Then receive the same number of messages that were sent
            for (int i = 0; i < count; i++) {
                message = (TextMessage) consumer.receive(5000);
                log.info("Received message with content " + message.getText());
            }
        } catch (Exception e) {
            log.severe(e.getMessage());
            throw e;
        } finally {
            if (context != null) {
                context.close();
            }

            // closing the connection takes care of the session, producer, and consumer
            if (connection != null) {
                connection.close();
            }
        }
    }
}

      

Please note that my JBoss AS is running on the same machine from where I run this application - this is me using localhost as the remote server.

I started the server with standalone-full.xml.

If I execute the application, then it gives the following error:

Sep 9, 2014 12:11:53 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.2.3.Final
Sep 9, 2014 12:11:53 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.2.3.Final
Sep 9, 2014 12:11:53 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.0.Final
Sep 9, 2014 12:11:53 PM com.howtodoinjava.HelloWorldJMS main
INFO: Attempting to acquire connection factory "RemoteConnectionFactory"
Sep 9, 2014 12:11:53 PM org.jboss.remoting3.remote.RemoteConnection handleException
ERROR: JBREM000200: Remote connection failed: javax.security.sasl.SaslException: Authentication failed: the server presented no authentication mechanisms
Sep 9, 2014 12:11:53 PM com.howtodoinjava.HelloWorldJMS main
SEVERE: Failed to connect to any server. Servers tried: [remote://localhost:4447 (Authentication failed: the server presented no authentication mechanisms)]
Exception in thread "main" javax.naming.AuthenticationException: Failed to connect to any server. Servers tried: [remote:// localhost:4447 (Authentication failed: the server presented no authentication mechanisms)] [Root exception is javax.security.sasl.SaslException: Authentication failed: the server presented no authentication mechanisms]
    at org.jboss.naming.remote.client.HaRemoteNamingStore.failOverSequence(HaRemoteNamingStore.java:238)
    at org.jboss.naming.remote.client.HaRemoteNamingStore.namingStore(HaRemoteNamingStore.java:149)
    at org.jboss.naming.remote.client.HaRemoteNamingStore.namingOperation(HaRemoteNamingStore.java:130)
    at org.jboss.naming.remote.client.HaRemoteNamingStore.lookup(HaRemoteNamingStore.java:272)
    at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:87)
    at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:129)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at com.howtodoinjava.HelloWorldJMS.main(HelloWorldJMS.java:69)
Caused by: javax.security.sasl.SaslException: Authentication failed: the server presented no authentication mechanisms

      

I followed this JMS post on a remote server to start the server with -b 0.0.0.0 but no help.

If I open the url localhost: 4447 in a browser, one file is downloaded called "download", so it means the server is listening on that port.

I tried with other connection files as mentioned in the XML file - no help

I tried with "http-remoting" as the protocol but I get the error - XNIO000812: Connection closed unexpectedly

+3


source to share


1 answer


This may be a late answer, but for reference I am adding how I solved it. I disabled protection in standalone-full.xml as follows

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

      



In your code, env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");

you are setting this to false, but just leave out the security. Hope this helps someone.

+2


source







All Articles