济南卓远网站建设,wordpress自适应汉化主题,信阳做网站的,有哪些做婚品的网站jboss ejb加密客户端和服务器之间的通信可为您的系统提供改进的安全性和隐私保护。 这可能是客户的一项重要要求#xff0c;尤其是在客户端或服务器需要在不受保护的网络中工作时。 本文向您展示了如何在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 CNlocalhost, Othoughts-on-java.org 我们将需要将此密钥存储提供给JBoss应用服务器。 因此我更喜欢将其存储在JBoss配置目录中。 但是只要JBoss服务器可以访问它就可以将其存储在所需的任何位置。 服务器配置 现在我们必须在JBoss配置中引用密钥库。 因此我们在应用程序领域的安全领域配置中添加了一个服务器标识元素。 以下代码片段显示了使用标准ApplicationRealm配置和位于JBoss配置目录中的server.keystore文件的示例配置 managementsecurity-realmssecurity-realm nameManagementRealmauthenticationproperties pathmgmt-users.properties relative-tojboss.server.config.dir//authentication/security-realmsecurity-realm nameApplicationRealmserver-identitiessslkeystore pathserver.keystore relative-tojboss.server.config.dir password123456//ssl/server-identitiesauthenticationproperties pathapplication-users.properties relative-tojboss.server.config.dir//authentication/security-realm/security-realms... 这就是需要在服务器端完成的所有工作。 客户 在客户端我们需要执行以下操作 将服务器的公钥导入客户端密钥库 在EJBClientProperties中定义SSL加密并 提供带有公用密钥JVM参数的密钥存储区的位置和密码。 导入密钥 首先我们需要导出添加到服务器密钥库中的密钥对的公钥。 也可以使用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 123456 EJBClientProperties 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 ContextSelectorEJBClientContext contextSelector new ConfigBasedEJBClientContextSelector(clientConfiguration);
EJBClientContext.setSelector(contextSelector);// create InitialContext
final HashtableObject, 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.trustStoresrc\test\resources\client.keystore -Djavax.net.ssl.trustStorePassword123456 使用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.htmljboss ejb