- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我使用 Apache Camel CXF 作为生产者来调用 SOAP Web 服务。我不使用 Spring 配置,而是以编程方式执行所有操作(我是初学者,希望避免同时学习 Spring 和 Apache Camel)。 Web 服务使用带有自签名证书的 SSL。我将它添加到一个信任库中,并希望能够将它添加到 CxfEndpoint 中,类似于我使用 https4 所做的那样:
KeyStoreParameters ksp = new KeyStoreParameters();
ksp.setResource("src/main/resources/truststore.jks");
ksp.setPassword("...");
KeyManagersParameters kmp = new KeyManagersParameters();
kmp.setKeyStore(ksp);
kmp.setKeyPassword("...");
SSLContextParameters scp = new SSLContextParameters();
scp.setKeyManagers(kmp);
CamelContext context = new DefaultCamelContext();
context.addRoutes(routeBuilder);
HttpComponent httpComponent = context.getComponent("https4", HttpComponent.class);
httpComponent.setSslContextParameters(scp);
——但这似乎不适用于 CxfComponent。我找到了很多关于使用 Spring 添加 TlsClientParameters 和配置 CxfEndpoint 的文档,例如:apache camel cxf https not working在这里 Calling secure webservice using CXF and Camel .但是,我没有找到任何关于如何像使用 https4 甚至在路由定义中那样简单地将信任库添加到组件的提示,即:
from(ENDPOINT_URI)
.setProperty(SecurityConstants.PASSWORD, constant(PASSWORD))
.setProperty(SecurityConstants.USERNAME, constant(USERNAME))
.to("cxf://" + SERVICE_URL + "?" +
"wsdlURL=" + WSDL_URL + "&" +
"serviceName=" + SERVICE_NAME + "&" +
"portName=" + PORT_NAME + "&" +
"dataFormat=CXF_MESSAGE&" +
"synchronous=true&" +
"defaultOperationName=" + DEFAULT_OPERATION_NAME)
.streamCaching();
我认为这一定是一个非常简单的问题,所以我仍然希望有一些巧妙的方法来简单地添加信任库(或者甚至接受任何证书,因为它与我们的用例无关)。如果有一种简单的编程方式,我会非常高兴。有人知道吗?
最佳答案
我通过将证书添加到 jre/lib/cacerts 中的 JVM 信任库解决了这个问题。这是可行的,因为我可以访问运行应用程序的机器上的 JVM。这似乎是最简单的解决方案。
更新
如果有人对更合适的解决方案感兴趣:CxfEndpoint 提供了一种影响 HTTPConduit 及其 TLS 参数的方法。这是修改后的代码:
getContext().getTypeConverterRegistry().addTypeConverter(CxfEndpointConfigurer.class, String.class, new SageEndpointConfigurerConverter());
配置 TLSParameters 并简单地从 TypeConverter 返回 CxfEndpointConfigurer
private class SageEndpointConfigurerConverter extends TypeConverterSupport {
@Override
public <T> T convertTo(Class<T> type, Exchange exchange, Object value) throws TypeConversionException {
CxfEndpointConfigurer configurer = new CxfEndpointConfigurer() {
@Override
public void configure(AbstractWSDLBasedEndpointFactory factoryBean) {
// do nothing
}
@Override
public void configureClient(Client client) {
URLConnectionHTTPConduit conduit = (URLConnectionHTTPConduit) client.getConduit();
TLSClientParameters tlsParams = new TLSClientParameters();
tlsParams.setDisableCNCheck(true);
tlsParams.setTrustManagers(new TrustManager[]{new TrustAllTrustManager()});
conduit.setTlsClientParameters(tlsParams);
}
@Override
public void configureServer(Server server) {
//do nothing
}
};
return (T) configurer;
}
}
TrustAllManager 就是这样实现的
public class TrustAllTrustManager implements X509TrustManager {
private static Logger LOG = LoggerFactory.getLogger(TrustAllTrustManager.class);
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String authType) throws CertificateException {
//do nothing, trust all certificates
logMessage(x509Certificates, authType);
}
@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String authType) throws CertificateException {
//do nothing, trust all certificates
logMessage(x509Certificates, authType);
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
private void logMessage(X509Certificate[] x509Certificates, String authType) {
StringBuilder message = new StringBuilder();
String lineSeparator = System.getProperty("line.separator");
message.append("Trusted following certificates for authentication type '").append(authType).append("'").append(lineSeparator);
for (X509Certificate certificate : x509Certificates) {
message.append(certificate).append(lineSeparator);
}
LOG.trace(message.toString());
}
}
关于 Apache Camel CXF : add TlsClientParameters programmatically,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35776030/
我正在使用 CXF 2.7.3 并希望禁用 CN checkin 代码: TLSClientParameters tlsParams = conduit.getTlsClientParameters(
我使用 Apache Camel CXF 作为生产者来调用 SOAP Web 服务。我不使用 Spring 配置,而是以编程方式执行所有操作(我是初学者,希望避免同时学习 Spring 和 Apach
我正在尝试在 cxf 客户端和网络服务之间建立 SSL 连接。为了进行概念验证,我正在使用 SpringJunit4TestRunner 运行测试。在我的客户端 spring 配置中,我使用了以下内容
我是一名优秀的程序员,十分优秀!