如何通过OSGi(karaf)API和自定义trustManager注册webservice

我正在研究通过以下调用注册WS的软件:

initiatingBundle.getBundleContext() .registerService( interfaces, serviceObject, this.convertMapToDictionary( initiatingBundle.getBundleContext(), serviceAttributes ) ); 

这是OSGi API的帮助 :

 org.osgi.framework.BundleContext ServiceRegistration registerService(java.lang.String[] clazzes, java.lang.Object service, java.util.Dictionary properties) 

是否有任何方法(使用properties属性的示例)来创建具有自定义TrustManager的Web服务,如下所示?

 TrustManager trustManager = new X509TrustManager() { @Override public void checkClientTrusted( X509Certificate[] x509Certificates, String s ) throws CertificateException { System.out.println( "=== interception point at checkClientTrusted ===" ); System.out.println( x509Certificates[0].getSubjectDN().getName() ); System.out.println( "================================================" ); throw new CertificateException( "interception point at checkClientTrusted" ); } @Override public void checkServerTrusted( X509Certificate[] x509Certificates, String s ) throws CertificateException { System.out.println( "checkServerTrusted" ); } @Override public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } }; 

Karaf使用Pax Web进行HttpService实现,还有更多。 通常,如果使用基于SSL的连接,则需要X509证书。 因此,您只需要根据OSGi规范和特殊的Pax Web属性配置HttpService。

要启用SSL支持,您必须设置以下属性:
org.osgi.service.http.secure.enabledtrue
org.ops4j.pax.web.ssl.keystore到要使用的密钥库的路径。 如果未设置,则使用默认路径$ {user.home} / .keystore。
org.ops4j.pax.web.ssl.password到用于密钥库完整性检查的密码。 该值可以是纯文本或模糊处理(从OBF开始:),如jetty docummentation的第4步所述
org.ops4j.pax.web.ssl.keypassword为密钥库使用的密码。 该值可以是纯文本或模糊处理(从OBF开始:),如jetty docummentation的第4步所述
您还可以设置以下内容:
org.osgi.service.http.port.secure更改端口。 默认值为8443

此外,对于证书,您需要设置以下内容: org.ops4j.pax.web.ssl.clientauthwanted = wanted
如果服务器上基于证书的客户端身份validation是“需要” ,则此属性指定。

org.ops4j.pax.web.ssl.clientauthneeded = required
如果服务器上基于证书的客户端身份validation是“必需的” ,则此属性指定。

更多细节可以在Pax Web项目中找到。 GitHub项目也提供样品。