我需要编写自己的类来告诉 mule 与服务(wsdl)的 https 连接已验证。我的 mule 项目已经接近完成,但最后一块丢失了,在特定的 url 发送文件。
我想要实现的目标:
建立连接并将 xml 发送到目标 url
读取 xml 格式的响应
服务器使用自签名证书的安全性。到目前为止,我所做的是从该链接获取证书并将其导入到 .jks 中。然后我遵循了可能所有“教程”如何使用 https 连接器连接到 mule 中的服务器,但在我的情况下没有任何效果。
我认为最好的事情是如果有人可以帮助我创建 java 类来绕过密钥检查并返回 true (已验证)。就像是:
URL url = new URL("https://www.google.com");
HttpsURLConnection conn= (HttpsURLConnection) url.openConnection();
conn.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String arg0, SSLSession arg1) {
return true;
}
});
我怎样才能在骡子中做到这一点?我希望它会是这样的this http://www.mulesoft.org/documentation-3.2/display/32X/WS-Security+Example.
我正在使用当前的 mule 版本(3.5.0)
谢谢你!
EDIT:
我的配置:
<https:connector name="HttpsConnector" cookieSpec="netscape" validateConnections="true" sendBufferSize="0" receiveBufferSize="0" receiveBacklog="0" clientSoTimeout="10000" serverSoTimeout="10000" socketSoLinger="0" doc:name="HTTP\HTTPS" dynamicNotification="true" >
<https:tls-server path="${keystore.path}" storePassword="${keystore.pass}" />
</https:connector>
<sub-flow name="toSOAP" doc:name="toSOAP">
<cxf:proxy-client payload="body" doc:name="SOAP" enableMuleSoapHeaders="false">
<cxf:outInterceptors>
<spring:ref bean="WSS4JOutInterceptorBean"/>
</cxf:outInterceptors>
</cxf:proxy-client>
<https:outbound-endpoint exchange-pattern="one-way" host="${pref.host}" port="${pref.port}" path="${pref.path}" method="POST" connector-ref="HttpsConnector" doc:name="HTTP"/>
</sub-flow>
对我有用的是在 HTTPS 连接器上设置 TrustManagerFactory。我是这样做的。
首先,创建一个密钥库,其中包含您要信任的 SSL 服务器的证书。您可以使用 JDK 附带的工具创建密钥库(这是一个例子 http://docs.oracle.com/cd/E19509-01/820-3503/ggfen/index.html).
然后,创建一个 FactoryBean,它为您提供一个 TrustManagerFactory(给定 JKS 密钥库和密码)。这是我使用 Spring 资源制作的一个,以便我可以从类路径或文件系统提供密钥库:
public class ExampleFactoryBean implements FactoryBean<TrustManagerFactory> {
private Resource keystore;
private String password;
@Override
public TrustManagerFactory getObject() throws Exception {
KeyStore truststore = KeyStore.getInstance("JKS");
truststore.load(keystore.getInputStream(), password.toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(truststore);
return tmf;
}
@Override
public Class<?> getObjectType() {
return TrustManagerFactory.class;
}
@Override
public boolean isSingleton() {
return true;
}
public void setKeystore(Resource keystore) {
this.keystore = keystore;
}
public void setPassword(String password) {
this.password = password;
}
}
最后,在 HTTP 连接器上设置 TrustManagerFactory,如下所示:
<https:connector name="myHttpsConnector">
<spring:property name="trustManagerFactory">
<spring:bean class="com.mycompany.ssl.ExampleFactoryBean">
<spring:property name="keystore" value="classpath:mykeystore.keystore" />
<spring:property name="password" value="mypassword" />
</spring:bean>
</spring:property>
</https:connector>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)