【问题标题】:Decrypting Message with a Spring Web Service Client使用 Spring Web 服务客户端解密消息
【发布时间】:2010-12-25 15:55:45
【问题描述】:

350 赏金和华夫饼给可以帮助我的人!

我已经为Spring Web 服务加密苦苦挣扎了好几天,我不知道如何让 Spring 对消息正文的加密起作用。每当我让服务器对生成的消息进行加密时,客户端似乎并没有在尝试根据 Schema (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>

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

【问题讨论】:

  • 你还没有给出完整的信息;)给出完整的堆栈跟踪(或者至少在一个有意义的地方,而不是开始处)
  • 这就是我得到的所有错误。我没有得到完整的堆栈跟踪。我得到的堆栈跟踪是它试图针对 XSD 验证消息,这对加密数据不起作用。
  • 听起来 DecryptionProcessor 想知道它正在解密的内容的架构,但没有。在您客户的 spring xml 中,我没有看到在某处使用“模式”引用...
  • 我尝试关闭加密/解密,接收消息没有任何问题。我会看看我是否可以访问解密器以提供架构。
  • 您几乎得到的错误似乎表明 ns0 未在消息中的消息包内定义(例如缺少 xmlns:ns0="...")。

标签: java security spring web-services spring-ws


【解决方案1】:

你确定吗

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

是否正确解决?

您收到的错误表明它无法找到处理该元素的方法。如果响应没有被解密,您将看不到元素名称和前缀。

您是否能够在不加密的情况下验证和运行 Web 服务?

【讨论】:

  • 是的,我可以在不加密的情况下成功运行它。它知道 ns0:HolidayListResponse 因为架构要求它是响应中的顶级元素,但是消息是加密的,所以它看不到那个顶级元素。至于 xsd 属性,是的,它正在正确解析,从类路径开始启动路径。我尝试更改路径,如果找不到 XSD 文件,则会在启动时出错。
【解决方案2】:

查看CastorMarshaller 属性,并尝试将一些“忽略”属性设置为真(在您的&lt;bean id="castorMarshaller" 中)。例如设置:

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

其中一个可能会这样做。

【讨论】:

  • 当我有机会我会尝试并告诉你。谢谢。
  • 很抱歉没有回复,我们现在的重点已经从这个转移到其他优先事项上,我一直很忙。我会投票赞成这个答案,因为它看起来确实是正确的。一旦我有机会尝试它,我会告诉你它是否有效。再次感谢您的回复。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-16
  • 2014-09-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-24
  • 2015-10-29
相关资源
最近更新 更多