2009-12-11 116 views
10

350赏金和华夫饼可以帮助我的人!使用Spring Web服务客户端解密消息

我一直在努力与Spring Web服务加密几天,我不知道如何让Spring的加密邮件正文工作。每当我让服务器对产生的消息进行加密时,客户端在尝试根据模式(XSD)对其进行验证之前似乎没有对其进行解密。

Here is the server side configuration

The server's xwss security configuration

The client's Spring configuration

Client's xwss configuration

什么我能做的就是加密用户令牌,并成功地将其解密。在从客户端向服务器发送数据时我这样做。服务器然后解密用户令牌并且认证用户证书,这很好地工作。

如果我尝试加密回来的消息正文,则会出现此问题。这个问题发生在客户端。似乎客户端在解密消息之前试图验证消息,因此在对模式进行验证时发生错误。

[Fatal Error] :1:192: The prefix "ns0" for element "ns0:HolidayListResponse" is not bound. 
11-Dec-2009 7:45:32 AM com.sun.xml.wss.impl.apachecrypto.DecryptionProcessor decryptElementWithCipher 
SEVERE: WSS1203: Exception [ The prefix "ns0" for element "ns0:HolidayListResponse" is not bound. ] while trying to decrypt message 

And here is the SOAP response itself

这里是编组映射文件

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN" 
         "http://castor.org/mapping.dtd"> 
<mapping> 
    <field-handler name="dateHandler" class="com.mycompany.hr.handlers.DateFieldHandler" /> 
    <field-handler name="dateHandler2" class="com.mycompany.hr.handlers.DateFieldHandler" /> 
    <class name="com.mycompany.hr.data.Holiday"> 
     <map-to ns-uri="http://mycompany.com/hr/schemas" ns-prefix="ns0" xml="Holiday" /> 
     <field name="from" type="string" handler="dateHandler"> 
      <bind-xml name="StartDate" node="element" /> 
     </field> 
     <field name="to" type="string" handler="dateHandler2"> 
      <bind-xml name="EndDate" node="element" /> 
     </field> 
    </class> 
    <class name="com.mycompany.hr.data.Employee"> 
     <map-to ns-uri="http://mycompany.com/hr/schemas" ns-prefix="ns0" xml="Employee" /> 
     <field name="number" type="java.lang.Integer"> 
      <bind-xml name="Number" node="element" /> 
     </field> 
     <field name="firstName" type="java.lang.String"> 
      <bind-xml name="FirstName" node="element" /> 
     </field> 
     <field name="lastName" type="java.lang.String"> 
      <bind-xml name="LastName" node="element" /> 
     </field> 
    </class> 
    <class name="com.mycompany.hr.data.HolidayRequest"> 
     <map-to ns-uri="http://mycompany.com/hr/schemas" ns-prefix="ns0" xml="HolidayRequest" /> 
     <field name="holiday" type="com.mycompany.hr.data.Holiday"> 
      <bind-xml name="Holiday" node="element" /> 
     </field> 
     <field name="employee" type="com.mycompany.hr.data.Employee"> 
      <bind-xml name="Employee" node="element" /> 
     </field> 
    </class> 

    <class name="com.mycompany.hr.data.HolidayConfirmation"> 
     <map-to ns-uri="http://mycompany.com/hr/schemas" ns-prefix="ns0" xml="HolidayConfirmation" /> 
     <field name="confirmationCode" type="java.lang.Integer"> 
      <bind-xml name="ConfirmationCode" node="element" /> 
     </field> 
     <field name="confirmationMessage" type="java.lang.String"> 
      <bind-xml name="ConfirmationMessage" node="element" /> 
     </field> 
    </class> 

    <class name="com.mycompany.hr.data.HolidayResponse"> 
     <map-to ns-uri="http://mycompany.com/hr/schemas" ns-prefix="ns0" xml="HolidayResponse" /> 
     <field name="confirmation" type="com.mycompany.hr.data.HolidayConfirmation"> 
      <bind-xml name="HolidayConfirmation" node="element" /> 
     </field> 
    </class> 
    <class name="com.mycompany.hr.data.HolidayListRequest"> 
     <map-to ns-uri="http://mycompany.com/hr/schemas" ns-prefix="ns0" xml="HolidayListRequest" /> 
     <field name="id" type="java.lang.Integer"> 
      <bind-xml name="userId" node="element" /> 
     </field> 
    </class> 
    <class name="com.mycompany.hr.data.HolidayListResponse"> 
     <map-to ns-uri="http://mycompany.com/hr/schemas" ns-prefix="ns0" xml="HolidayListResponse" /> 
     <field name="holidays" type="com.mycompany.hr.data.Holiday" collection="vector"> 
      <bind-xml name="Holiday" node="element" /> 
     </field> 
    </class> 
</mapping> 

我知道这是一个大量的信息,但我想我会提供一切。我的加密设置是否正确?是不是可以加密邮件正文并在客户端解密?在这一点上,我几乎可以接受任何建议。

+0

你还没有给出整个信息;)给出完整的堆栈跟踪(或至少把它切在有意义的地方,而不是开始) – Bozho 2009-12-14 12:28:20

+0

这就是我得到的一个错误。我没有得到整个堆栈跟踪。我得到的堆栈跟踪是试图根据XSD验证消息,这对加密数据不起作用。 – Zoidberg 2009-12-14 13:19:50

+0

这听起来像DecryptionProcessor想知道它解密的模式,但不知道。 在客户端的spring xml中,我没有看到正在使用的“模式”引用... – 2009-12-14 15:27:12

回答

0

你一定

<property name="xsd" value="classpath:src/java/hr.xsd"/> 

正在妥善解决?

您收到的错误表明无法找到如何处理该元素。如果响应未得到解密,您将不会看到元素名称和前缀。

您能否验证并运行Web服务而无需加密?

+0

是的,我可以在没有加密的情况下成功运行它。它知道ns0:HolidayListResponse,因为模式要求它是响应中的顶级元素,但是消息是加密的,所以它不会看到顶级元素。至于xsd属性,是的,它正确地解决了,从类路径的弹簧开始路径。我试图改变路径,如果它找不到XSD文件,我会在启动时遇到错误。 – Zoidberg 2009-12-15 11:28:35

2

看看CastorMarshaller属性,并尝试将某些“忽略”属性设置为true(在您的<bean id="castorMarshaller"中)。例如设置:

<property name="validating" value="false" /> 
<property name="suppressNamespaces" value="true" /> 
<property name="ignoreExtraElements" value="true" /> 

其中一个可能会这样做。

+0

当我有机会时,我会尝试并让你知道。谢谢。 – Zoidberg 2010-01-04 12:16:18

+0

@Zoidberg还没有更新? :) – Bozho 2010-02-23 20:44:13

+0

对不起,由于缺乏反应,我们的工作重心已经从此转移到其他优先事项上,而且我一直非常忙碌。我会对这个答案进行投票,因为它确实看起来是正确的。一旦我有机会尝试它,我会让你知道它是否有效。再次感谢您的回应。 – Zoidberg 2010-02-24 12:10:46