0

WSS4Jの部分を追加し始めるまで、CXFを使用して最初のWebサービスの契約を設定することはかなりうまくいっていました。

パスワードの送信をデバッグして、soapヘッダーにログインしようとしています。WSPasswordCallbackクラスでgetPassword()を呼び出すと、nullになります。石鹸の封筒から、パスワードが送信されたことがわかります。

この投稿、http://old.nabble.com/PasswordDigest-and-PasswordText-difference-td24475866.html、2009年から、UsernameTokenHandlerが欠落している(作成する必要がある)かどうか疑問に思いました。

それが本当なら、誰かが私に、spring / cxf bean xmlファイルでそれを構成する方法を教えてもらえますか?

アドバイスや提案をいただければ幸いです。

問題のJavaファイルは次のとおりです。

package com.netcentric.security.handlers;

import java.io.IOException;
import javax.annotation.Resource;
import javax.com.urity.auth.callback.Callback;
import javax.com.urity.auth.callback.CallbackHandler;
import javax.com.urity.auth.callback.UnsupportedCallbackException;
import org.apache.ws.com.urity.WSPasswordCallback;

public class ServicePWCallback implements CallbackHandler
{
   @Override
   public void handle(Callback[] callbacks) throws IOException, 
                UnsupportedCallbackException {
        try {
            for (int i = 0; i < callbacks.length; i++) {
                if (callbacks[i] instanceof WSPasswordCallback) {

                    WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];

                    sString login = pc.getIdentifier();

                    String password = pc.getPassword();
                    // password is null, not the expected myPASSWORD**1234

                    int n = pc.getUsage(); 
                    // this is 2 == WSPasswordCallback.USERNAME_TOKEN

              //...

CXF / Spring構成ファイル:

    <beans xmlns = "http://www.springframework.org/schema/beans"
           xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context = "http://www.springframework.org/schema/context"
           xmlns:jee = "http://www.springframework.org/schema/jee"
           xmlns:jaxws = "http://cxf.apache.org/jaxws"
           xsi:schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
    http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd "
        default-dependency-check = "none" default-lazy-init = "false">

        <import resource = "classpath:META-INF / cxf / cxf.xml" />
        <import resource = "classpath:META-INF / cxf / cxf-servlet.xml" />

        <bean id = "serverPasswordCallback" class = "com.netcentric.security.handlers.ServicePWCallback" />
        <bean id = "wss4jInInterceptor" class = "org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
            <コンストラクター引数>
                <地図>
                    <entry key = "action" value = "UsernameToken" />
                    <entry key = "passwordType" value = "PasswordText" />
                                    <entry key = "passwordCallbackRef">
                        <ref bean = "serverPasswordCallback" />
                    </ entry>
                </ map>
            </コンストラクタ-arg>
        </ bean>

        <jaxws:endpoint id = "FederationImpl"
            implementor = "com.netcentric.services.federation.FederationImpl"
            endpointName = "e:federation"
            serviceName = "e:federation"
            address = "federation"
            xmlns:e = "urn:federation.services.netcentric.sec">

                    <jaxws:inInterceptors>
                            <bean class = "org.apache.cxf.binding.soap.saaj.SAAJInInterceptor" />
                            <ref bean = "wss4jInInterceptor" />
                    </ jaxws:inInterceptors>
        </ jaxws:endpoint>
    </ Beans

せっけんメッセージ:

    <?xml version = "1.0" encoding = "UTF-8"?>
    <soapenv:Envelope xmlns:soapenv = "http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd = "http://www.w3.org/2001/XMLSchema" xmlns:xsi = "http: //www.w3.org/2001/XMLSchema-instance">
        <soapenv:Header>
            <wsse:comurity xmlns:wsse = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wscomurity-comext-1.0.xsd" soapenv:mustUnderstand = "1">
                <wsu:Timestamp xmlns:wsu = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wscomurity-utility-1.0.xsd" wsu:Id = "Timestamp-16757598" >>
                    <wsu:Created> 2011-09-22T18:21:23.345Z </ wsu:Created>
                    <wsu:Expires> 2011-09-22T18:26:23.345Z </ wsu:Expires>
                </ wsu:Timestamp>
                <wsse:UsernameToken xmlns:wsu = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wscomurity-utility-1.0.xsd" wsu:Id = "UsernameToken-16649441" >>
                    <wsse:Username> pam </ wsse:Username>
                    <wsse:Password Type = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"> myPASSWORD ** 1234 </ wsse:パスワード>
                </ wsse:UsernameToken>
            </ wsse:comurity>
        </ soapenv:Header>
        <soapenv:Body>
            <getVersion xmlns = "urn:federation.services.netcentric.com">
                <getVersionRequest />
            </ getVersion>
        </ soapenv:Body>
    </ soapenv:Envelope>

4

3 に答える 3

5

CXF 2.4.x を使用している場合は、以下を読むことをお勧めします。

http://coheigea.blogspot.com/2011/02/usernametoken-processing-changes-in.html

そして、それが追加情報を提供するのに役立つかどうかを確認します。Colm のブログは、最近の WSS4J リリースに関する有用な情報の宝庫です。

于 2011-09-22T20:18:21.327 に答える
3

ご助力いただきありがとうございます。私はこれで進歩を遂げました。CXF 2.4.2 と WSS4J 1.6.2 を使用しています。フレームワークがパスワードをチェックするようになりました。したがって、正しい内部セクションは

            if (callbacks[i] instanceof WSPasswordCallback) {
                WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
                sString login = pc.getIdentifier();
                String password = getPassword(login);
                pc.getPassword(login); 
                //...
            }

SOAP ヘッダーからパスワードを取得して期待値と比較する代わりに、期待値を検索し、それをフレームワークに渡して比較を行います。

于 2011-09-23T15:13:22.850 に答える
0

これを追加します:

// set the password on the callback. 
This will be compared to the            
// password which was sent from the client.            
pc.setPassword("password");

==> "" の間のパスワードは、クライアントから送信されたパスワードと比較されます。

クライアント側: write login = bob ; パスワード = bobPassword (消化されます)

サーバー側: user = bob をキャッチしuser.setPassword(bobPassword)、受け取ったパスワードが正しいかどうかを関数が検証します。

于 2015-02-16T12:01:26.967 に答える