我試圖訪問由證書保護的Web服務。 安全性設置在IIS上,並且Web服務位於其後面。如何使用CXF客戶端的TLS/SSL Http驗證到Web服務?
我不認爲WS-SECURITY會執行這種類型的身份驗證。 當您調用Web服務時,有任何方法可以傳遞客戶端證書嗎?
我剛剛收到一個說明「頁面需要 客戶端證書」的IIS錯誤頁面。
我正在使用CXF 2.1.4
我試圖訪問由證書保護的Web服務。 安全性設置在IIS上,並且Web服務位於其後面。如何使用CXF客戶端的TLS/SSL Http驗證到Web服務?
我不認爲WS-SECURITY會執行這種類型的身份驗證。 當您調用Web服務時,有任何方法可以傳遞客戶端證書嗎?
我剛剛收到一個說明「頁面需要 客戶端證書」的IIS錯誤頁面。
我正在使用CXF 2.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>
樣品來自:CXF Wiki
以上的答案是正確的,但添加到....
你的客戶端Bean應該是如下(此SSL工作正常):
<jaxws:client id="helloClient" serviceClass="demo.spring.HelloWorld" address="http://localhost:9002/HelloWorld" />
如果您將客戶端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(new TLSInterceptor())
。
public class TLSInterceptor extends AbstractPhaseInterceptor<Message> {
public TLSInterceptor() {
super(Phase.SETUP);
}
@Override
public void handleMessage(final Message message) throws Fault {
final Conduit conduit = message.getExchange().getConduit(message);
if (conduit instanceof HTTPConduit) {
final HTTPConduit httpConduit = (HTTPConduit) conduit;
final TLSClientParameters tlsClientParameters = ObjectUtils.firstNonNull(httpConduit.getTlsClientParameters(), new TLSClientParameters());
// configure the params
httpConduit.setTlsClientParameters(tlsClientParameters);
}
}
}