Java JBoss EAP 7.2通过SSL保护JMS

Java JBoss EAP 7.2通过SSL保护JMS,java,jms,jboss-eap-7,Java,Jms,Jboss Eap 7,通过创建一个安全域并将其映射到管理界面,我在JBoss EAP 7.2上启用了SSL。那很好。现在我尝试在JBoss EAP上保护JMS队列(ActiveMQ)。首先,我在standalone full.xml上指定了一个队列,并通过指向https连接器和接受器提到了一个远程连接工厂 我已经更新了远程处理子系统,将连接器ref作为默认的https使用 当我尝试访问http-remoting://127.0.0.1:8443从一个独立的Java类中,我在获取连接工厂时遇到以下错误 WFNA

通过创建一个安全域并将其映射到管理界面,我在JBoss EAP 7.2上启用了SSL。那很好。现在我尝试在JBoss EAP上保护JMS队列(ActiveMQ)。首先,我在
standalone full.xml
上指定了一个队列,并通过指向
https连接器
接受器
提到了一个远程连接工厂


我已经更新了远程处理子系统,将连接器ref作为默认的https使用


当我尝试访问
http-remoting://127.0.0.1:8443
从一个独立的Java类中,我在获取连接工厂时遇到以下错误

WFNAM00018: Failed to connect to remote host [Root exception is java.io.IOException: Invalid response]
    at org.wildfly.naming.client.remote.RemoteNamingProvider.getPeerIdentityForNaming(RemoteNamingProvider.java:110)
    at org.wildfly.naming.client.remote.RemoteNamingProvider.getPeerIdentityForNaming(RemoteNamingProvider.java:53)
    at org.wildfly.naming.client.NamingProvider.getPeerIdentityForNamingUsingRetry(NamingProvider.java:105)
    at org.wildfly.naming.client.remote.RemoteNamingProvider.getPeerIdentityForNamingUsingRetry(RemoteNamingProvider.java:91)
    at org.wildfly.naming.client.remote.RemoteContext.lambda$lookupNative$0(RemoteContext.java:189)
    at org.wildfly.naming.client.NamingProvider.performExceptionAction(NamingProvider.java:222)
    at org.wildfly.naming.client.remote.RemoteContext.performWithRetry(RemoteContext.java:100)
    at org.wildfly.naming.client.remote.RemoteContext.lookupNative(RemoteContext.java:188)
    at org.wildfly.naming.client.AbstractFederatingContext.lookup(AbstractFederatingContext.java:74)
    at org.wildfly.naming.client.AbstractFederatingContext.lookup(AbstractFederatingContext.java:60)
    at org.wildfly.naming.client.WildFlyRootContext.lookup(WildFlyRootContext.java:144)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at com.cibc.jboss.queue.PostMessage.main(PostMessage.java:43)
Caused by: java.io.IOException: Invalid response

请帮忙解决。我是否缺少任何配置。

在EAP 7.2上保护JMS的最佳方法是使用Elytron。使用--interactive模式使用Elytron保护服务器。这将使用在Elyton子系统上创建的sslConext设置密钥库和信任库

您的服务器单机版将如下所示

-<tls>
-<key-stores>
-<key-store name="key-store-8ce838a4-6109-46e4-b243-a71489bb842f">
<credential-reference clear-text="password"/>
<implementation type="JKS"/>
<file relative-to="jboss.server.config.dir" path="jks-source.jks" required="false"/>
</key-store>
</key-stores>
-<key-managers>
-<key-manager name="key-manager-8ce838a4-6109-46e4-b243-a71489bb842f" key-store="key-store-8ce838a4-6109-46e4-b243-a71489bb842f">
<credential-reference clear-text="password"/>
</key-manager>
</key-managers>
-<server-ssl-contexts>
<server-ssl-context name="ssl-context-8ce838a4-6109-46e4-b243-a71489bb842f" key-manager="key-manager-8ce838a4-6109-46e4-b243-a71489bb842f" use-cipher-suites-order="false" authentication-optional="false" need-client-auth="false" want-client-auth="false" protocols="TLSv1.2" cipher-suite-filter="DEFAULT"/>
</server-ssl-contexts>
</tls>
-
-
-
-
-
-
在activemq子系统中的httpconnector上启用ssl

-<http-connector name="http-connector2" socket-binding="https" endpoint="http-acceptor2">

<param name="ssl-enabled" value="true"/>

</http-connector>
-
如果客户端拥有自己的信任库,请确保将服务器的公共证书添加到其信任库中。为了测试上述内容,我们可以使用独立的JMS客户端向https发送请求-remoting://localhost:8443. 添加来自服务器的自签名证书以包含在JDK的信任库(cacerts)中是个坏主意,但这是在Jboss EAP上测试安全JMS的一个快速选项

public class PostMessage {

    // Set up all the default values
    private static final String DEFAULT_MESSAGE = "Hello, World! successfull";
    private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
    private static final String DEFAULT_DESTINATION = "TestQueue";
    private static final String DEFAULT_MESSAGE_COUNT = "1";
    private static final String DEFAULT_USERNAME = "jmsuser";
    private static final String DEFAULT_PASSWORD = "jmsuser123";
    private static final String INITIAL_CONTEXT_FACTORY = "org.wildfly.naming.client.WildFlyInitialContextFactory";
    private static final String PROVIDER_URL = "https-remoting://127.0.0.1:8443";


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

        Context namingContext = null;

       // System.setProperty("javax.net.debug","all");

        try {
             String userName = System.getProperty("username", DEFAULT_USERNAME);
             String password = System.getProperty("password", DEFAULT_PASSWORD);

            // Set up the namingContext 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));
            namingContext = new InitialContext(env);

            // Perform the JNDI lookups
            String connectionFactoryString = System.getProperty("connection.factory", DEFAULT_CONNECTION_FACTORY);
            ConnectionFactory connectionFactory = (ConnectionFactory) namingContext.lookup(connectionFactoryString);
            System.out.println("Able to look up connection factory with the naming context "  );
            Queue destination = (Queue) namingContext.lookup(DEFAULT_DESTINATION);
            System.out.println("Able to look up Queue with the naming context" );
                JMSContext jmsContext = connectionFactory.createContext(DEFAULT_USERNAME, DEFAULT_PASSWORD);
            jmsContext.createProducer().send(destination, DEFAULT_MESSAGE);
            System.out.println("><><><><><><>< MESSAGE POSTED <><><><><><><>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" );

        } catch (NamingException e) {
            e.printStackTrace();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        finally {
            if (namingContext != null) {
                try {
                    namingContext.close();
                } catch (NamingException e) {
                }
            }
        }
    }
}
public类PostMessage{
//设置所有默认值
private static final String DEFAULT_MESSAGE=“Hello,World!successfull”;
私有静态最终字符串DEFAULT\u CONNECTION\u FACTORY=“jms/RemoteConnectionFactory”;
私有静态最终字符串DEFAULT_DESTINATION=“TestQueue”;
私有静态最终字符串默认\u消息\u COUNT=“1”;
私有静态最终字符串DEFAULT_USERNAME=“jmsuser”;
私有静态最终字符串DEFAULT_PASSWORD=“jmsuser123”;
私有静态最终字符串INITIAL\u CONTEXT\u FACTORY=“org.wildfly.naming.client.WildFlyInitialContextFactory”;
私有静态最终字符串提供程序\u URL=“https-remoting://127.0.0.1:8443";
公共静态void main(字符串[]args)引发JMSException{
Context namingContext=null;
//setProperty(“javax.net.debug”、“all”);
试一试{
字符串userName=System.getProperty(“用户名”,默认用户名);
字符串password=System.getProperty(“password”,默认密码);
//为JNDI查找设置namingContext
最终属性env=新属性();
环境放置(Context.INITIAL\u Context\u工厂,INITIAL\u Context\u工厂);
put(Context.PROVIDER\u URL,System.getProperty(Context.PROVIDER\u URL,PROVIDER\u URL));
namingContext=新的初始上下文(env);
//执行JNDI查找
String connectionFactoryString=System.getProperty(“connection.factory”,默认连接工厂);
ConnectionFactory ConnectionFactory=(ConnectionFactory)namingContext.lookup(connectionFactoryString);
System.out.println(“能够使用命名上下文查找连接工厂”);
队列目的地=(队列)namingContext.lookup(默认目的地);
println(“能够使用命名上下文查找队列”);
JMSContext JMSContext=connectionFactory.createContext(默认用户名、默认密码);
jmsContext.createProducer().send(目标,默认消息);
System.out.println(“>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>”;
}捕获(NamingE例外){
e、 printStackTrace();
}
捕获(例外e){
e、 printStackTrace();
}
最后{
if(namingContext!=null){
试一试{
namingContext.close();
}捕获(NamingE例外){
}
}
}
}
}