jboss ejb_使用JBoss AS 7进行SSL加密的EJB调用
jboss ejb
加密客戶端和服務器之間的通信可為您的系統提供改進的安全性和隱私保護。 這可能是客戶的一項重要要求,尤其是在客戶端或服務器需要在不受保護的網絡中工作時。
本文向您展示了如何在JBoss AS 7中設置SSL加密的EJB調用。
服務器
在服務器端只需完成兩件事:
無論是否加密,應用程序的源代碼都保持不變。
創建密鑰
Java提供了工具keytool ,我們將使用它來管理密鑰庫和創建??私鑰/公鑰對。 下面的示例使用RSA算法創建一對1024位密鑰,并將它們添加到密鑰存儲server.keystore中 。 如果密鑰庫不存在,則將創建它。
keytool -genkey -alias jboss -keyalg RSA -keysize 1024 -keystore server.keystore -validity 365?-keypass 123456 -storepass 123456 -dname "CN=localhost, O=thoughts-on-java.org"我們將需要將此密鑰存儲提供給JBoss應用服務器。 因此,我更喜歡將其存儲在JBoss配置目錄中。 但是,只要JBoss服務器可以訪問它,就可以將其存儲在所需的任何位置。
服務器配置
現在,我們必須在JBoss配置中引用密鑰庫。 因此,我們在應用程序領域的安全領域配置中添加了一個服務器標識元素。
以下代碼片段顯示了使用標準ApplicationRealm配置和位于JBoss配置目錄中的server.keystore文件的示例配置:
<management><security-realms><security-realm name="ManagementRealm"><authentication><properties path="mgmt-users.properties" relative-to="jboss.server.config.dir"/></authentication></security-realm><security-realm name="ApplicationRealm"><server-identities><ssl><keystore path="server.keystore" relative-to="jboss.server.config.dir" password="123456"/></ssl></server-identities><authentication><properties path="application-users.properties" relative-to="jboss.server.config.dir"/></authentication></security-realm></security-realms>...這就是需要在服務器端完成的所有工作。
客戶
在客戶端,我們需要執行以下操作:
導入密鑰
首先,我們需要導出添加到服務器密鑰庫中的密鑰對的公鑰。 也可以使用keytool來完成:
keytool -export -keystore server.keystore -alias jboss -file server.cer -keypass 123456 -storepass 123456如果密鑰庫不存在,則將創建它。
好的,現在我們可以將密鑰添加到客戶端密鑰庫中:
keytool -import -trustcacerts -alias jboss -file server.cer -keystore client.keystore -keypass 123456 -storepass 123456EJBClientProperties
EJBClientProperties中沒有太大的區別。 需要將屬性remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED和remote.connection.default.connect.options.org.xnio.Options.SSL_STARTTLS設置為true 。 其余的保持不變。
以下代碼段顯示了到服務器的SSL加密連接的創建以及SLSB的查找。
// define EJB client properties final Properties props = new Properties(); // define SSL encryption props.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED","true"); props.put("remote.connection.default.connect.options.org.xnio.Options.SSL_STARTTLS","true"); // connection properties props.put("remote.connections", "default"); props.put("remote.connection.default.host", "localhost"); props.put("remote.connection.default.port", "4447"); // user credentials props.put("remote.connection.default.username", "test"); props.put("remote.connection.default.password", "1234");props.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS","JBOSS-LOCAL-USER"); props.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT","false"); props.put("remote.connection.default.connect.options.org.jboss.remoting3.RemotingOptions.HEARTBEAT_INTERVAL","600000");// create EJB client configuration final EJBClientConfiguration clientConfiguration = new PropertiesBasedEJBClientConfiguration(props);// create and set a context selector final ContextSelector<EJBClientContext> contextSelector = new ConfigBasedEJBClientContextSelector(clientConfiguration); EJBClientContext.setSelector(contextSelector);// create InitialContext final Hashtable<Object, Object> contextProperties = new Hashtable<>(); ejbURLContextFactory.class.getName(); contextProperties.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming"); InitialContext initialContext = new InitialContext(contextProperties);// lookup SLSB GreeterRemote greeter = (GreeterRemote) initialContext.lookup("ejb:/test/Greeter!blog.thoughts.on.java.ssl.remote.GreeterRemote"); Assert.assertEquals("Hello World!", greeter.greet("World"));JVM參數
好的,現在我們快完成了。 唯一缺少的是對客戶端密鑰存儲的引用。 可以使用JVM參數javax.net.ssl.trustStore作為位置,并使用javax.net.ssl.trustStorePassword作為密鑰存儲區的密碼來完成,例如:
-Djavax.net.ssl.trustStore=src\test\resources\client.keystore -Djavax.net.ssl.trustStorePassword=123456使用JBoss AS 7設置SSL加密的EJB調用需要完成所有這些工作。
故障排除
如果存在任何通信問題,則可以設置-Djavax.net.debug = true以啟用調試消息。
結論
在本文中,我們研究了使用JBoss AS 7設置加密的EJB調用的配置和代碼更改,這可以在幾分鐘內完成,并為您的通信提供了改進的安全性和隱私保護。
翻譯自: https://www.javacodegeeks.com/2014/05/ssl-encrypted-ejb-calls-with-jboss-as-7.html
jboss ejb
總結
以上是生活随笔為你收集整理的jboss ejb_使用JBoss AS 7进行SSL加密的EJB调用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 什么是间接引语 间接引语的简介
- 下一篇: 签字背书什么意思 签字背书介绍