Web サービスへの CXF クライアントで TLS/SSL Http 認証を使用するにはどうすればよいですか?

StackOverflow https://stackoverflow.com/questions/543896

質問

証明書によって保護された Web サービスにアクセスしようとしています。セキュリティは IIS 上にセットアップされ、Web サービスはその背後にあります。

WS-SECURITY がこの種の認証を行うとは思えません。Web サービスを呼び出すときにクライアント証明書を渡す方法はありますか?

「ページにはクライアント証明書が必要です」というIISエラーページを取得しています。

CXF2.1.4を使用しています

役に立ちましたか?

解決

はい、これはCXFを使用して可能です。あなたは、クライアント導管を設定する必要があります。あなたは、IISでWebサービスにアクセスすることができます証明書を格納するキーストアを指定することができます。限り、あなたはここで使用している証明書がIISで知られている許可クライアントであるとして、あなたは[OK]をする必要があります。

<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 のnoreferrer">

他のヒント

答え上記は正しいが、それに追加する....

あなたのクライアントBeanが(このSSL作業罰金のために)、以下の通りである必要があります:

<jaxws:client id="helloClient" serviceClass="demo.spring.HelloWorld" address="http://localhost:9002/HelloWorld" />

あなたはSSLが動作しません、次のように、クライアントBeanを定義する場合:

<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> 

@geg が述べたように、JaxWsProxyFactoryBean にインターセプターを追加し、HttpConduit を使用する必要があります。

ここ 参照できるサンプルコードです。
これ コードは TLSClientParameters の設定方法をガイドします

、プログラム的にそれを行うインターセプターを作成し、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帰属
所属していません StackOverflow
scroll top