2012-04-27 1 views
0

私は、opentravel.org OTA XMLリクエストを受け入れてそれに応じて応答するTomcat Webサービスを持っています。 JibX OTAクラスを使用します。JibX WSからSOAPヘッダーにアクセス

これまでのところ、サービスのユーザーはPOXを使用していましたが、実際にはうまくいきましたが、新しいユーザーはSOAPヘッダーにSOAPヘッダーにセキュリティ資格情報を追加する必要がありました。 ..

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Header> 
    <wsse:Security soap:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org  /wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
     <wsse:UsernameToken> 
     <wsse:Username>USERNAME</wsse:Username> 
     <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401- wss-username-token-profile-1.0#PasswordText">SECRET</wsse:Password> 
     </wsse:UsernameToken> 
    </wsse:Security> 
    </soap:Header> 

だから私は、私はサービス実装クラス内からヘッダにアクセスする必要があると思うの要求を認証します。

私はSOAPヘッダーの例をチェックしました。私は、ヘッダーにはinContextも含めてアクセスできることを伝えています。

public RoomListRS list(RoomListRQ roomListRQ, InContext inCtx){ 
.... 
} 

ので、このメソッド内で、私はこれを行うことができます...

Security security = (Security) inCtx.getAttribute("security"); 

ので、私は、トークン内の

に、ユーザー名にアクセスすることができます...サービスでこれを指定しました...

<service name="OTAService"> 
    <service-class>com.xx.webservice.ota.HotelServiceImpl</service-class> 
    <operation method="list"/> 
    <handler-class class="org.jibx.ws.io.handler.ContextAttributeUnmarshallingInHandler"> 
    <constructor-arg value="com.xx.shared.soap.security.Security"/> 
    <constructor-arg value="security"/> 
    </handler-class> 
</service> 

これは正しいですか?

私はSecurityクラスを作成しましたが、ヘッダー内の何かにアクセスできることを証明するために、すべての名前空間の項目を残しました。 ...このようなフラグメントを有することに基づいて

<Security> 
     <UsernameToken> 
     <Username>USERNAME</Username> 
     <Password>SECRET</Password> 
     </UsernameToken> 
    </Security> 

は、だから私はbindgenとの結合を作成し、コンパイルされ、その後、あるsoapUI

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.opentravel.org/OTA/2003/05"> 
    <soapenv:Header> 
    <Security> 
     <UsernameToken> 
     <Username>USERNAME</Username> 
     <Password>SECRET</Password> 
     </UsernameToken> 
    </Security> 
    </soapenv:Header> 
    <soapenv:Body> 
<OTA_HotelRoomListRQ xmlns="http://www.opentravel.org/OTA/2003/05" Version="2.0"> 
.... 
</OTA_HotelRoomListRQ> 
</soapenv:Body> 
</soapenv:Envelope> 

でそれを呼び出したが、私はからのセキュリティオブジェクトを取得しようとすると、コンテキストはnullです。

スティックの端が間違っていませんか?

SOAPYを使用して別のエンドポイントで別のサービスを作成してください。

JibX WSとinHandlerではできないことがありますか?

コメントは大歓迎です。


私の質問にお答えすることが大変ありがとうございます。

あなたが追加したものを通過しようとしています。あなたのカスタマイズとxsdを使ってjavaソースとbinding.xmlを作成しました。

私はクラスをコンパイルしていると私は今、それらをバインドしようとしていますが、私はこのエラーを取得しています:

C:\Java\wsse>java org.jibx.binding.generator.BindGen org.oasisopen.docs.wss.oasis200401wsswssecuritysecext1.SecurityHeaderType 
Exception in thread "main" java.lang.IllegalStateException: No way to handle type java.lang.Object, referenced from org.oasisopen.docs.wss.oasis200401wsswssecuritysecext1.SecurityHeaderType 
    at org.jibx.binding.generator.BindGen.expandReferences(BindGen.java:227) 
    at org.jibx.binding.generator.BindGen.findReferences(BindGen.java:1010) 
    at org.jibx.binding.generator.BindGen.generate(BindGen.java:1124) 
    at org.jibx.binding.generator.BindGen.main(BindGen.java:1302) 

私はそれがどんな光を投げかけているかどうかを確認するためにbindgenのカスタマイゼーションを見てみるつもりです、これがこの問題に対応した唯一の手がかりです。あなたはこの周りにどのようにしているのか教えていただけますか?

もう一度おねがいします。

+0

他に誰もこれをしなければなりませんでしたか?私だけですか? – iainmac999

答えて

0

WS-Securityのユーザー名とパスワードのヘッダー用に用意されている一部の製品コードを共有できます。なぜコードが機能していないのかわかりませんが、おそらくこれが役に立ちます。

<!-- Contains customization elements for code generation from WS Security schema --> 
<schema-set show-schema="false" generate-all="false" xmlns:xs="http://www.w3.org/2001/XMLSchema" line-width="120"> 
    <schema name="oasis-200401-wss-wssecurity-secext-1.0.xsd" generate-all="true" prefer-inline="true" any-handling="mapped"> 
    <class-decorator class="org.jibx.schema.codegen.extend.CollectionMethodsDecorator" /> 
    </schema> 
</schema-set> 

、その後で構築されています:

は、我々は以下のカスタマイズで、オアシス-200401-WSS-wssecurity-secext-1.0.xsdスキーマからWS-Securityのコードとバインディングを生成

<target name="codegen-wss" description="Regenerate JiBX bindings and generated code for WS-Security schema"> 
    <echo message="Running code generation from schema" /> 
    <mkdir dir="${gen.src.dir}" /> 
    <java classname="org.jibx.schema.codegen.CodeGen" fork="yes" classpathref="build.classpath" failonerror="true"> 
    <arg value="-c" /> 
    <arg value="custom_jibx_gen_wssec.xml" /> 
    <arg value="-t" /> 
    <arg value="${gen.src.dir}" /> 
    <arg value="wsdl/wssec/oasis-200401-wss-wssecurity-secext-1.0.xsd" /> 
    </java> 
    <move file="${gen.src.dir}/binding.xml" tofile="${wssec.binding.file}" failonerror="true" /> 
</target> 

とを結合させた:

<target name="compile" depends="init" description="Compile the source code and run JiBX binding compiler"> 
    <mkdir dir="${dest.dir}" /> 
    <javac srcdir="${src.dir}:${gen.src.dir}" destdir="${dest.dir}" deprecation="on"> 
    <classpath refid="build.classpath" /> 
    </javac> 
    <bind binding="${gen.src.dir}/xxx-binding.xml"> 
    <classpath path="${dest.dir}" /> 
    </bind> 
    <bind binding="${wssec.binding.file}"> 
    <classpath path="${dest.dir}" /> 
    </bind> 
</target> 

サーブレットのスプリングの設定は、Tを定義します

<property name="handlerDefinitions"> 
    <list> 
    <bean class="org.jibx.ws.server.HandlerDefinition" > 
     <description>Handler for inbound WS/Security header</description> 
     <property name="className" value="org.jibx.ws.io.handler.ContextAttributeUnmarshallingInHandler" /> 
     <property name="args"> 
     <list> 
      <value>org.oasisopen.docs.wss.oasis200401wsswssecuritysecext1.SecurityHeaderType</value> 
      <value>wssecurity.header</value> 
     </list> 
     </property> 
    </bean> 

をし、エンドポイントが使用してヘッダーを取得します:彼はInHandler securityHeaderを使用する

public ServiceRequestReceipt processRequest(ServiceRequest request, InContext inCtx, OutContext outCtx) 
    throws WsException { 
    SecurityHeaderType securityHeader = (SecurityHeaderType) inCtx.getAttribute("wssecurity.header"); 

私たちのコードは次のようになります。

 if (securityHeader == null) { 
      throw new AuthenticationException("No WS-Security header found"); 
     } 

     List<Object> securityHeaderTypes = securityHeader.getSecurityHeaderTypes(); 
     if (securityHeaderTypes == null || securityHeaderTypes.size() == 0) { 
      throw new AuthenticationException("WS-Security header appears to be empty"); 
     } 

     UsernameTokenType usernameToken = null; 
     try { 
      usernameToken = (UsernameTokenType) securityHeaderTypes.get(0); 
     } catch (ClassCastException e) { 
      throw new AuthenticationException("Expected UsernameToken in WS-Security header"); 
     } 

     AttributedString usernameAttStr = usernameToken.getUsername(); 
     if (usernameAttStr == null) { 
      throw new AuthenticationException("Expected Username in WS-Security header"); 
     } 

     String username = usernameAttStr.getString(); 
     if (!username.equals(retailer.getRetailerUsername())) { 
      throw new AuthenticationException("Invalid username in WS-SecurityHeader"); 
     } 
     List<Object> any = usernameToken.getAny(); 
     if (any == null) { 
      throw new AuthenticationException("Expected Password element in WS-Security header"); 
     } 
     PasswordString passwordString = null; 
     for (Iterator iterator = any.iterator(); iterator.hasNext();) { 
      try { 
       passwordString = (PasswordString) iterator.next(); 
      } catch (ClassCastException ignore) { 
       logger.debug("Found non password string object"); 
      } 
     } 
     if (passwordString == null) { 
      throw new AuthenticationException("Expected Password in WS-Security header"); 
     } 
     if (passwordString.getAttributedString() == null) { 
      throw new AuthenticationException("Expected Password AttributedString in WS-Security header"); 
     } 

     String password = passwordString.getAttributedString().getString(); 
     if (!password.equals(retailer.getRetailerPassword())) { 
      throw new AuthenticationException("Invalid password in WS-SecurityHeader"); 
     } 

私はそれが役に立てば幸い!

関連する問題