Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何通过CXF客户端对web服务使用TLS/SSL Http身份验证?_Java_Web Services_Ssl_Cxf_Ws Security - Fatal编程技术网

Java 如何通过CXF客户端对web服务使用TLS/SSL Http身份验证?

Java 如何通过CXF客户端对web服务使用TLS/SSL Http身份验证?,java,web-services,ssl,cxf,ws-security,Java,Web Services,Ssl,Cxf,Ws Security,我正在尝试访问由证书保护的web服务。 安全设置在IIS上,web服务在其后面 我认为WS-SECURITY不会进行这种类型的身份验证。 当您调用web服务时,是否有任何方法可以传递客户端证书 我刚刚收到一个IIS错误页面,上面写着“该页面需要 客户证书” 我使用的是CXF2.1.4,是的,这在使用CXF时是可能的。您需要设置客户端管道。您可以指定包含允许您访问IIS中web服务的证书的密钥库。只要您在这里使用的证书是IIS中已知允许的客户端,您就可以了 <http:conduit nam

我正在尝试访问由证书保护的web服务。 安全设置在IIS上,web服务在其后面

我认为WS-SECURITY不会进行这种类型的身份验证。 当您调用web服务时,是否有任何方法可以传递客户端证书

我刚刚收到一个IIS错误页面,上面写着“该页面需要 客户证书”


我使用的是CXF2.1.4,是的,这在使用CXF时是可能的。您需要设置客户端管道。您可以指定包含允许您访问IIS中web服务的证书的密钥库。只要您在这里使用的证书是IIS中已知允许的客户端,您就可以了

<http:conduit name="{http://apache.org/hello_world}HelloWorld.http-conduit">

   <http:tlsClientParameters>
       <sec:keyManagers keyPassword="password">
            <sec:keyStore type="JKS" password="password"
                 file="src/test/java/org/apache/cxf/systest/http/resources/Morpit.jks"/>
       </sec:keyManagers>
       <sec:trustManagers>
           <sec:keyStore type="JKS" password="password"
                file="src/test/java/org/apache/cxf/systest/http/resources/Truststore.jks"/>
       </sec:trustManagers>

       ...

   </http:tlsClientParameters>

...

样本来源:

以上答案是正确的,但除此之外

您的客户端bean应该如下所示(对于此SSL工作正常):


如果将客户端bean定义为以下内容,则SSL将不起作用:

<bean id="proxyFactory" 
class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="demo.spring.HelloWorld"/>
<property name="address" value="http://localhost:9002/HelloWorld"/>
</bean> 

若要以编程方式进行此操作,请创建一个拦截器,并将其添加到您的
JaxWsProxyFactoryBean
中,使用
factory.getOutInterceptors().add(新的TLSInterceptor())

公共类TLSInterceptor扩展了AbstractPhaseInterceptor{
公共TLS接收器(){
超级(阶段设置);
}
@凌驾
public void handleMessage(最终消息)引发错误{
最终管道=message.getExchange().getconductor(message);
if(HTTPCONDUCTOR的导管实例){
最终高温超导导管高温超导导管=(高温超导导管)导管;
final TLSClientParameters TLSClientParameters=ObjectUtils.firstNonNull(HttpConductor.getTlsClientParameters(),new TLSClientParameters());
//配置参数
HttpConductor.SettlesclientParameters(tlsClientParameters);
}
}
}

正如@geg所提到的,您需要将拦截器添加到您的JaxWsProxyFactoryBean中,并使用httpconductor

是您可以参考的示例代码。
代码将指导如何设置TLSClientParameters

<bean id="proxyFactory" 
class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="demo.spring.HelloWorld"/>
<property name="address" value="http://localhost:9002/HelloWorld"/>
</bean>