title: JBoss JMS: ERROR: JBREM000200: Remote connection failed: javax.security.sasl.SaslException: Authentication failed: the server presented
body: <p>I am writing sample JMS consumer, producer example in JBoss AS 7.1.1. I followed the tutorials carefully and carried out the following steps –</p>
  
  <p>User testuser/testpassword is created with testrole and testrole is present in standalone-full.xml file</p>
  
  <pre><code>    &lt;security-settings&gt;
          &lt;security-setting match="#"&gt;
              &lt;permission type="send" roles="testrole guest" /&gt;
              &lt;permission type="consume" roles="testrole guest" /&gt;
          &lt;/security-setting&gt;
      &lt;/security-settings&gt;
  </code></pre>
  
  <p>I am using the default connectionfactory and destination as mentioned in the standalone-full.xml file –</p>
  
  <pre><code>    &lt;connection-factory name="InVmConnectionFactory"&gt;
          &lt;connectors&gt;
              &lt;connector-ref connector-name="in-vm" /&gt;
          &lt;/connectors&gt;
          &lt;entries&gt;
              &lt;entry name="java:/ConnectionFactory" /&gt;
          &lt;/entries&gt;
      &lt;/connection-factory&gt;
      &lt;connection-factory name="RemoteConnectionFactory"&gt;
          &lt;connectors&gt;
              &lt;connector-ref connector-name="netty" /&gt;
          &lt;/connectors&gt;
          &lt;entries&gt;
              &lt;entry name="RemoteConnectionFactory" /&gt;
              &lt;entry name="java:jboss/exported/jms/RemoteConnectionFactory" /&gt;
          &lt;/entries&gt;
      &lt;/connection-factory&gt;
  
      &lt;jms-queue name="testQueue"&gt;
          &lt;entry name="queue/test" /&gt;
          &lt;entry name="java:jboss/exported/testQueue" /&gt;
      &lt;/jms-queue&gt;
  </code></pre>
  
  <p>Here is the POM file –</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;org.hornetq&lt;/groupId&gt;
          &lt;artifactId&gt;hornetq-core&lt;/artifactId&gt;
          &lt;version&gt;2.0.0.GA&lt;/version&gt;
          &lt;scope&gt;compile&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hornetq&lt;/groupId&gt;
          &lt;artifactId&gt;hornetq-jms&lt;/artifactId&gt;
          &lt;version&gt;2.0.0.GA&lt;/version&gt;
          &lt;scope&gt;compile&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hornetq&lt;/groupId&gt;
          &lt;artifactId&gt;hornetq-transports&lt;/artifactId&gt;
          &lt;version&gt;2.0.0.GA&lt;/version&gt;
          &lt;scope&gt;compile&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.jboss.netty&lt;/groupId&gt;
          &lt;artifactId&gt;netty&lt;/artifactId&gt;
          &lt;version&gt;3.1.0.GA&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.jboss.javaee&lt;/groupId&gt;
          &lt;artifactId&gt;jboss-jms-api&lt;/artifactId&gt;
          &lt;version&gt;1.1.0.GA&lt;/version&gt;
          &lt;scope&gt;compile&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.jboss&lt;/groupId&gt;
          &lt;artifactId&gt;jboss-ejb-client&lt;/artifactId&gt;
          &lt;version&gt;2.0.1.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.jboss&lt;/groupId&gt;
          &lt;artifactId&gt;jboss-remote-naming&lt;/artifactId&gt;
          &lt;version&gt;2.0.1.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.jboss.xnio&lt;/groupId&gt;
          &lt;artifactId&gt;xnio-api&lt;/artifactId&gt;
          &lt;version&gt;3.2.3.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.jboss.xnio&lt;/groupId&gt;
          &lt;artifactId&gt;xnio-nio&lt;/artifactId&gt;
          &lt;version&gt;3.2.3.Final&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>Here is my sample code –</p>
  
  <pre><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 &lt; count; i++) {
                  message = session.createTextMessage(content);
                  producer.send(message);
              }
  
              // Then receive the same number of messages that were sent
              for (int i = 0; i &lt; 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();
              }
          }
      }
  }
  </code></pre>
  
  <p>Please notice that my JBoss AS is running in the same machine from where I am running this application – that is I am using localhost as remote server.</p>
  
  <p>I started the server with standalone-full.xml.</p>
  
  <p>If I execute the application, then it is giving the following error –</p>
  
  <pre><code>Sep 9, 2014 12:11:53 PM org.xnio.Xnio &lt;clinit&gt;
  INFO: XNIO version 3.2.3.Final
  Sep 9, 2014 12:11:53 PM org.xnio.nio.NioXnio &lt;clinit&gt;
  INFO: XNIO NIO Implementation Version 3.2.3.Final
  Sep 9, 2014 12:11:53 PM org.jboss.remoting3.EndpointImpl &lt;clinit&gt;
  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
  </code></pre>
  
  <p>I followed this <a href="https://stackoverflow.com/questions/1795983/jms-message-to-remote-server">JMS message to remote server</a>  suggestion to start the server with –b 0.0.0.0 – but no help.</p>
  
  <p>If I open URL localhost:4447 in browser, one file named “download” is being downloaded – so it means that the server is listening in that port.</p>
  
  <p>I tried with other connectionfactories as mentioned in the XML file – no help</p>
  
  <p>I tried with “http-remoting” as the protocol, but I get the error - XNIO000812: Connection closed unexpectedly</p>