1

我想构建一个受用户名和密码保护的简单示例 Web 服务。

作为起点,我使用:https ://docs.jboss.org/author/display/JBWS/WS-Security

问题:每个客户端即使有错误或丢失的凭据也可以调用 Web 服务方法。所以@EndpointConfig 似乎没有效果。但我不知道如何深入挖掘,因为我无法通过调试和 jboss 管理控制台获得有关 Web 服务配置的更详细信息。

网络服务类:

@WebService(serviceName="MyWebService", portName="MyWebServicePort")
@EndpointConfig(configFile = "WEB-INF/jaxws-endpoint-config.xml", configName = "myconfig")
public class MyWebService{...}

jaxws-endpoint-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<jaxws-config xmlns="urn:jboss:jbossws-jaxws-config:4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:javaee="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="urn:jboss:jbossws-jaxws-config:4.0 schema/jbossws-jaxws-config_4_0.xsd">
  <endpoint-config>
    <config-name>myconfig</config-name>
    <property>
      <property-name>ws-security.username</property-name>
      <property-value>myusername</property-value>
    </property>
    <property>
      <property-name>ws-security.password</property-name>
      <property-value>mypassword</property-value>
    </property>
  </endpoint-config>
</jaxws-config>

有什么建议可以拒绝未经授权的客户吗?

4

1 回答 1

1

您基本上需要在您的 WSDL 中发布您的策略。

您必须在 WSDL 的绑定部分下添加。

<binding name="SecurityServicePortBinding" type="tns:ServiceIface">
<wsp:PolicyReference URI="#SecurityServiceSignThenEncryptPolicy"/>
...
</binding>

并将策略定义本身添加到您的 WSDL 中。

<wsp:Policy wsu:Id="SecurityServiceSignThenEncryptPolicy" xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
 <wsp:ExactlyOne>
   <wsp:All>
    <sp:AsymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
   ....
 </wsp:ExactlyOne>
</wsp:Policy>

当您点击您的服务 URL(例如http://localhost:8080/yourservice?wsdl)时,您应该能够在返回的 WSDL 中看到策略引用。否则,不会发生身份验证/加密。

于 2013-03-22T09:16:36.993 回答