java JBoss JMS:错误:JBREM000200:远程连接失败:javax.security.sasl.SaslException:身份验证失败:服务器提供

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25738786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 08:35:03  来源:igfitidea点击:

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

javamavenjbossjms

提问by nsinha

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 –

我正在 JBoss AS 7.1.1 中编写示例 JMS 消费者、生产者示例。我仔细按照教程进行了以下步骤 -

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

用户 testuser/testpassword 是使用 testrole 创建的,并且 testrole 存在于 standalone-full.xml 文件中

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

I am using the default connectionfactory and destination as mentioned in the standalone-full.xml file –

我正在使用 standalone-full.xml 文件中提到的默认连接工厂和目的地 -

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

这是 POM 文件 -

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

请注意,我的 JBoss AS 运行在我运行此应用程序的同一台机器上——也就是说,我使用 localhost 作为远程服务器。

I started the server with standalone-full.xml.

我用standalone-full.xml 启动了服务器。

If I execute the application, then it is giving 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 message to remote serversuggestion to start the server with –b 0.0.0.0 – but no help.

我按照这条JMS 消息向远程服务器建议使用 –b 0.0.0.0 启动服务器 – 但没有帮助。

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.

如果我在浏览器中打开 URL localhost:4447,就会下载一个名为“download”的文件——这意味着服务器正在监听那个端口。

I tried with other connectionfactories as mentioned in the XML file – no help

我尝试使用 XML 文件中提到的其他连接工厂 – 没有帮助

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

我尝试使用“http-remoting”作为协议,但出现错误 - XNIO000812:连接意外关闭

采纳答案by Isuru Gunawardana

This may be a late reply, but for the reference I am adding how I resolved this. I disabled security in standalone-full.xml as follows

这可能是一个迟到的回复,但作为参考,我正在添加我如何解决这个问题。我在 standalone-full.xml 中禁用了安全性,如下所示

<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 it just skip the security. Hope this help someone.

在您的代码中,env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");您将其设置为 false,但它只是跳过了安全性。希望这有助于某人。