gpt4 book ai didi

java - JBoss JMS : ERROR: JBREM000200: Remote connection failed: javax. security.sasl.SaslException:身份验证失败:服务器出现

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:23:19 26 4
gpt4 key购买 nike

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

用户 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>

我正在使用 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>

这是 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>

这是我的示例代码 –

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();
}
}
}
}

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

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

如果我执行该应用程序,则会出现以下错误 –

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

我关注了这个JMS message to remote server建议使用 –b 0.0.0.0 启动服务器 – 但没有帮助。

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

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

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

最佳答案

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

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

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

关于java - JBoss JMS : ERROR: JBREM000200: Remote connection failed: javax. security.sasl.SaslException:身份验证失败:服务器出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25738786/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com