![](/img/trans.png)
[英]javax.security.sasl.SaslException: Authentic Failed while connecting to Jboss 7 server from remote client
[英]JBoss JMS: ERROR: JBREM000200: Remote connection failed: javax.security.sasl.SaslException: Authentication failed: the server presented
我正在JBoss AS 7.1.1中编写示例JMS使用者,生产者示例。 我仔细按照教程进行了以下步骤 -
使用testrole创建用户testuser / testpassword,并在standalone-full.xml文件中提供testrole
<security-settings>
<security-setting match="#">
<permission type="send" roles="testrole guest" />
<permission type="consume" roles="testrole guest" />
</security-setting>
</security-settings>
我正在使用standalone-full.xml文件中提到的默认connectionfactory和destination -
<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在运行此应用程序的同一台机器上运行 - 即我使用localhost作为远程服务器。
我使用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消息跟踪到远程服务器建议以使用-b 0.0.0.0启动服务器 - 但没有帮助。
如果我在浏览器中打开URL localhost:4447,则会下载一个名为“download”的文件 - 这意味着服务器正在侦听该端口。
我尝试使用XML文件中提到的其他connectionfactories - 没有帮助
我尝试使用“http-remoting”作为协议,但我收到错误 - 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,但它只是跳过安全性。 希望这能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.