[英]How to enable TLS/SSL in java, Spring / CXF for Web Service?
[英]How do you use TLS/SSL Http Authentication with a CXF client to a web service?
我正在嘗試訪問由證書保護的Web服務。 安全性在IIS上設置,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>
要以編程方式執行此操作,請創建一個攔截器並使用factory.getOutInterceptors().add(new TLSInterceptor())
將其添加到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);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.