安全的Web服务异常:此服务需要<wsse:security>,缺少</wsse:security>

时间:2011-06-07 09:27:33

标签: java web-services security encryption jboss

我遇到了网络服务消息的问题。

1)Jboss 4.2.3GA

2)作为无状态EJB的Web Service类。它使用加密并注释如下:

@Local
@Stateless
@EndpointConfig(configName = "Standard WSSecurity Endpoint")
@SOAPBinding(style = SOAPBinding.Style.RPC)
@WebService

3)Web服务位于 Module_1

4)客户端是MBean。它有以下注释:

@Service(name = "MyWebServiceClient")
@Local(MyWebServiceClient.class)
@Management(MyWebServiceClient.class)

5) MyWebServiceClient 位于 Module_2

6) Module_1 包含以下WS相关内容的META-INF目录:

  • 的JBoss-的wsse-server.xml中
  • server.keystore
  • server.truststore

jboss-wsse-server.xml 包含以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-ws-security xmlns="http://www.jboss.com/ws-security/config" 
                   xsi="http://www.w3.org/2001/XMLSchema-instance" 
                   schemaLocation="http://www.jboss.com/ws-security/config 
                   www.jboss.com/ws-security/schema/jboss-ws-security_1_0.xsd">

<key-store-file>META-INF/server.keystore</key-store-file>
<key-store-password>qwerty</key-store-password>
<key-store-type>jks</key-store-type>

<trust-store-file>META-INF/server.truststore</trust-store-file>
<trust-store-password>qwerty</trust-store-password>
<trust-store-type>jks</trust-store-type>

<key-passwords>
    <key-password alias="server" password="qwerty"/>
    <key-password alias="client" password="qwerty"/>
</key-passwords>

<config>
    <sign type="x509v3" alias="server"/>
    <encrypt type="x509v3" alias="client"/>
    <requires>
        <signature/>
        <encryption/>
    </requires>
</config>
</jboss-ws-security>

7) Module_2 的'META-INF文件夹包含以下文件:

  • 的JBoss-的wsse-client.xml的
  • 标准JAXWS客户端-config.xml中
  • client.keystore
  • client.truststore

jboss-wsse-client.xml 包含以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-ws-security xmlns="http://www.jboss.com/ws-security/config"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://www.jboss.com/ws-security/config  
               http://www.jboss.com/ws-security/schema/jboss-ws-security_1_0.xsd">

<key-store-file>META-INF/client.keystore</key-store-file>
<key-store-password>qwerty</key-store-password>
<key-store-type>jks</key-store-type>

<trust-store-file>META-INF/client.truststore</trust-store-file>
<trust-store-password>qwerty</trust-store-password>
<trust-store-type>jks</trust-store-type>

<key-passwords>
    <key-password alias="server" password="qwerty"/>
    <key-password alias="client" password="qwerty"/>
</key-passwords>

<config>
    <sign type="x509v3" alias="client"/>
    <encrypt type="x509v3" alias="server"/>
    <requires>
        <signature/>
        <encryption/>
    </requires>
</config>
</jboss-ws-security>

standard-jaxws-client-config.xml 包含以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<jaxws-config xmlns="urn:jboss:jaxws-config:2.0" 
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:javaee="http://java.sun.com/xml/ns/javaee"
              xsi:schemaLocation="urn:jboss:jaxws-config:2.0 jaxws-config_2_0.xsd">

<client-config>
    <config-name>Standard WSSecurity Client</config-name>
    <post-handler-chains>
        <javaee:handler-chain>
            <javaee:protocol-bindings>##SOAP11_HTTP</javaee:protocol-bindings>

            <javaee:handler>
                <javaee:handler-name>WSSecurityHandlerOutbound</javaee:handler-name>
                <javaee:handler-class>org.jboss.ws.extensions.security.jaxws.WSSecurityHandlerClient
                </javaee:handler-class>
            </javaee:handler>
        </javaee:handler-chain>
    </post-handler-chains>
</client-config>

</jaxws-config>

两个模块在构建过程之后合并到同一个jar。所以META-INF包含所有这些xml和encription文件。

问题在于,当我尝试从Client MBean发送消息时,Web服务会生成异常:

  

org.jboss.ws.core.CommonSOAPFaultException:此服务需要&lt; wsse:安全&gt;,缺少。

据我所知,这意味着传入的soap-message不包含来自客户端的sing header。 在log4j中激活跟踪soap消息后,我在客户端看到以下消息正文:

<S:Envelope xmlns:S='http://schemas.xmlsoap.org/soap/envelope/'>
<S:Body>
    <ns2:addPoint xmlns:ns2='http://x.y.z.com/'>
        <deviceId>Device 1</deviceId>
        <color>GREEN</color>
    </ns2:addPoint>
</S:Body>
</S:Envelope>

但是在服务器和客户端xmls中指定了sign属性(参见tat)。 所以我无法理解为什么没有签署结果消息。

可能问题是所有配置文件都驻留在同一个META-INF中? 这有关系吗?

需要帮助。

1 个答案:

答案 0 :(得分:1)

我发现加密不起作用的原因。 该项目的结构如下:

EAR:
...META-INF
...client.jar
......META-INF
.........standard-jaxws-client-config.xml
.........jboss-wsse-client.xml
.........client.keystore
.........client.truststore
......org
........myproject
.................
...server.jar
......META-INF
.........jboss-wsse-server.xml
.........server.keystore
.........server.truststore
......org
........myproject
.................

问题是客户端找不到standard-jaxws-client-config.xml。邮件未加密。

当我将此文件复制到EAR / META-INF时,加密成功完成,消息已成功传输到服务器端并在服务器端解密。

我认为这是因为JBoss在ear文件的类路径中搜索standard-jaxws-client-config.xml。

我使用的新文件结构:

EAR:
...META-INF
......standard-jaxws-client-config.xml            <------- file placed here
...client.jar
......META-INF
.........jboss-wsse-client.xml
.........client.keystore
.........client.truststore
......org
........myproject
.................
...server.jar
......META-INF
.........jboss-wsse-server.xml
.........server.keystore
.........server.truststore
......org
........myproject
.................

如果服务器和客户端部署为单个文件(没有耳包装),那么将此文件放在client / META-INF下工作正常。

我意识到这个问题取决于路径解析。

相关问题