当客户端在 bluemix 中时,通过 HTTPS 调用安全 RESTful Web 服务
Invoking Secure RESTful Web Service over HTTPS When client is in bluemix
我的应用程序是 BlueMix 中的 运行,它必须通过 SSL restful 调用另一个应用程序。我想知道在哪里以及如何添加这些信息
> trustStoreType, trustStore and trustStorePassword
所以 bluemix 中的应用程序 运行 可以使用它吗?当我从我修改的本地服务器 class-path 进行测试时,我可以在客户端应用程序 运行 的 bluemix liberty 服务器中做一些类似的事情吗?或者有什么更简单更好的方法吗?
如果您依赖于 Liberty 服务器,您可以离线自定义它并将其推送到 Bluemix。
.
https://www.ibm.com/developerworks/community/blogs/msardana/entry/developing_with_bluemix_customizing_the_liberty_build_pack_to_add_your_configurations?lang=en
你的网络服务在哪里运行?如果它是在内部部署的,那么您必须使用 Bluemix 中可用的云集成代理来建立安全隧道并获取到您的内部部署 Web 服务的代理 IP。以下 link 中提供了相同的详细信息:
https://www.ibm.com/developerworks/community/blogs/96960515-2ea1-4391-8170-b0515d08e4da/entry/cloud_to_on_premise_web_services_bluemix_cloud_integrators?lang=en
您应该能够在 Eclipse 中编辑 server.xml 并设置类似
的内容
<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>websocket-1.0</feature>
<feature>localConnector-1.0</feature>
<feature>jndi-1.0</feature>
<feature>jsp-2.2</feature>
<feature>jdbc-4.0</feature>
<feature>ejbLite-3.1</feature>
<feature>ssl-1.0</feature>
<feature>jaxb-2.2</feature>
</featureManager>
<ssl clientAuthenticationSupported="true" id="defaultSSLConfig" keyStoreRef="defaultKeyStore" trustStoreRef="defaultTrustStore"/>
<keyStore id="defaultKeyStore"location="${server.config.dir}/resources/security/keystore.jks" password="passw0rd" type="JKS"/>
<keyStore id="defaultTrustStore" location="${server.config.dir}/resources/security/trustStore.jks" password="passw0rd" type="JKS"/>
<ssl clientAuthenticationSupported="true" id="defaultSSLConfig" keyStoreRef="serverKeyStore" trustStoreRef="serverTrustStore"/>
<keyStore id="serverKeyStore" location="${server.config.dir}/resources/security/serverKey.jks" password="passw0rd" type="JKS"/>
<keyStore id="serverTrustStore" location="${server.config.dir}/resources/security/serverTrust.jks"> password="passw0rd" type="JKS"/>
<!-- customize SSL configuration -->
<ssl id="customizeSSLConfig" keyStoreRef="clientKeyStore" trustStoreRef="clientTrustStore"/>
<keyStore id="clientKeyStore" location="${server.config.dir}/resources/security/clientKey.jks" password="passw0rd" type="JKS"/>
<keyStore id="clientTrustStore" location="${server.config.dir}/resources/security/clientTrust.jks" password="passw0rd" type="JKS"/>
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint httpPort="8080" httpsPort="9443" id="defaultHttpEndpoint"/>
<applicationMonitor updateTrigger="mbean"/>
</server>
最简单的方法是使用用于 eclipse 的 Bluemix 插件并使用 Websphere Libery Profile Server
尽管我认为所有这些都是有效的选择,但我最终的做法略有不同。这就是最终对我有用的东西
public static HttpClient getCustomClient() throws GeneralSecurityException, IOException {
KeyStore trustStore = KeyStore.getInstance("jks");
// Load the truststore from the classpath using the password
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream resourceAsStream = classLoader.getResourceAsStream("/clienttruststore");
trustStore.load(resourceAsStream, "password".toCharArray());
SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(trustStore).build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext);
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
resourceAsStream.close();
return httpclient;
}
//get custom httpclient
Unirest.setHttpClient(getCustomClient());
//send request...
HttpResponse<String> response =
Unirest.get("https://xyz.abc.com/").asString();
基本上用 war 打包了自定义信任库并让应用程序使用它。我也会尝试其他选项,但使用前一个选项时,我的自定义服务器崩溃了,不确定是否是因为资源问题。
我的应用程序是 BlueMix 中的 运行,它必须通过 SSL restful 调用另一个应用程序。我想知道在哪里以及如何添加这些信息
> trustStoreType, trustStore and trustStorePassword
所以 bluemix 中的应用程序 运行 可以使用它吗?当我从我修改的本地服务器 class-path 进行测试时,我可以在客户端应用程序 运行 的 bluemix liberty 服务器中做一些类似的事情吗?或者有什么更简单更好的方法吗?
如果您依赖于 Liberty 服务器,您可以离线自定义它并将其推送到 Bluemix。 . https://www.ibm.com/developerworks/community/blogs/msardana/entry/developing_with_bluemix_customizing_the_liberty_build_pack_to_add_your_configurations?lang=en
你的网络服务在哪里运行?如果它是在内部部署的,那么您必须使用 Bluemix 中可用的云集成代理来建立安全隧道并获取到您的内部部署 Web 服务的代理 IP。以下 link 中提供了相同的详细信息: https://www.ibm.com/developerworks/community/blogs/96960515-2ea1-4391-8170-b0515d08e4da/entry/cloud_to_on_premise_web_services_bluemix_cloud_integrators?lang=en
您应该能够在 Eclipse 中编辑 server.xml 并设置类似
的内容<server description="new server"> <!-- Enable features --> <featureManager> <feature>websocket-1.0</feature> <feature>localConnector-1.0</feature> <feature>jndi-1.0</feature> <feature>jsp-2.2</feature> <feature>jdbc-4.0</feature> <feature>ejbLite-3.1</feature> <feature>ssl-1.0</feature> <feature>jaxb-2.2</feature> </featureManager> <ssl clientAuthenticationSupported="true" id="defaultSSLConfig" keyStoreRef="defaultKeyStore" trustStoreRef="defaultTrustStore"/> <keyStore id="defaultKeyStore"location="${server.config.dir}/resources/security/keystore.jks" password="passw0rd" type="JKS"/> <keyStore id="defaultTrustStore" location="${server.config.dir}/resources/security/trustStore.jks" password="passw0rd" type="JKS"/> <ssl clientAuthenticationSupported="true" id="defaultSSLConfig" keyStoreRef="serverKeyStore" trustStoreRef="serverTrustStore"/> <keyStore id="serverKeyStore" location="${server.config.dir}/resources/security/serverKey.jks" password="passw0rd" type="JKS"/> <keyStore id="serverTrustStore" location="${server.config.dir}/resources/security/serverTrust.jks"> password="passw0rd" type="JKS"/> <!-- customize SSL configuration --> <ssl id="customizeSSLConfig" keyStoreRef="clientKeyStore" trustStoreRef="clientTrustStore"/> <keyStore id="clientKeyStore" location="${server.config.dir}/resources/security/clientKey.jks" password="passw0rd" type="JKS"/> <keyStore id="clientTrustStore" location="${server.config.dir}/resources/security/clientTrust.jks" password="passw0rd" type="JKS"/> <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" --> <httpEndpoint httpPort="8080" httpsPort="9443" id="defaultHttpEndpoint"/> <applicationMonitor updateTrigger="mbean"/> </server>
最简单的方法是使用用于 eclipse 的 Bluemix 插件并使用 Websphere Libery Profile Server
尽管我认为所有这些都是有效的选择,但我最终的做法略有不同。这就是最终对我有用的东西
public static HttpClient getCustomClient() throws GeneralSecurityException, IOException {
KeyStore trustStore = KeyStore.getInstance("jks");
// Load the truststore from the classpath using the password
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream resourceAsStream = classLoader.getResourceAsStream("/clienttruststore");
trustStore.load(resourceAsStream, "password".toCharArray());
SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(trustStore).build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext);
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
resourceAsStream.close();
return httpclient;
}
//get custom httpclient
Unirest.setHttpClient(getCustomClient());
//send request...
HttpResponse<String> response =
Unirest.get("https://xyz.abc.com/").asString();
基本上用 war 打包了自定义信任库并让应用程序使用它。我也会尝试其他选项,但使用前一个选项时,我的自定义服务器崩溃了,不确定是否是因为资源问题。