【问题标题】:How do I deal with WS-Security when all I have is a wsdl?当我只有一个 wsdl 时,我该如何处理 WS-Security?
【发布时间】:2011-05-09 21:41:58
【问题描述】:

我正在尝试开发一个在 Glassfish 容器 (Metro) 中使用 Web 服务的独立客户端应用程序。我所要做的就是为我正在尝试使用的服务提供一个 wsdl。 wsdl 充斥着各种“wsp:Policy”标签。看起来 IssuedToken、Trust13、ecryption 都被使用了。 所以我从 netbeans 和 JAX-WS 生成了一些代码。一切都很顺利,但是在尝试运行客户端时,我得到: 'WST0029:无法从 IssuedToken 或客户端配置获取 STS 位置以访问服务http://localhost:8080/ ....'

那时我突然意识到我对 WSS 一无所知。看起来没有生成任何代码来处理安全问题。所以,我将不得不从头开始。 那么从哪里开始呢?图书?教程?

TIA

【问题讨论】:

    标签: wsdl jax-ws ws-security webservice-client java-metro-framework


    【解决方案1】:

    Metro 在运行时从 WSDL 或 wsit-client.xml 配置文件应用策略。这就是为什么没有生成与策略相关的代码的原因。根据this post,目前无法以编程方式进行。

    This tutorial 很好地解释了您可以使用 WSS 做的一些事情,尽管在这种情况下所有内容可能并不适用,但它仍然是一本好书。

    我发现生成支持 WSS 的客户端的最简单方法是使用 Metro 的 wsimport 脚本:

    cd metro/bin/
    mkdir src target
    ./wsimport.sh -s src -d target -extension -Xendorsed -verbose YourService.wsdl
    

    然后将 Metro 安装到您的应用程序服务器中(将库复制到正确的位置或运行 ant 脚本):

    ant -f metro-on-glassfish.xml
    

    然后将您的本地 WSDL 文件放在您的类路径中(例如您的资源文件夹),以便 Metro 可以在运行时获取它以应用您生成的 YourService 类中的策略:

    private final static URL YOURSERVICE_WSDL_LOCATION;
    
    // This is enough, you don't need the wsdlLocation attribute 
    // on the @WebServiceClient annotation if you have this.
    static {
        YOURSERVICE_WSDL_LOCATION =
            CustomerService.class.getClassLoader().getResource("YourService.wsdl");
    }
    
    public YourService() {
        super(YOURSERVICE_WSDL_LOCATION, 
                new QName("http://tempuri.org/", "YourService"));
    }
    

    如果您想要WS-Addressing,您可能需要手动将该功能添加到您的绑定方法中(Metro 从来没有为我生成它,所以我总是必须自己添加它)。

    @WebEndpoint(name = "WSHttpBinding_IYourService")
    public IYourService getWSHttpBindingIYourService() {
        WebServiceFeature wsAddressing = new AddressingFeature(true);
    
        IYourService service =
            super.getPort(new QName("http://xmlns.example.com/services/Your",
                    "WSHttpBinding_IYourService"), IYourService.class, 
                    wsAddressing);
    
        return service;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-10
      • 1970-01-01
      • 1970-01-01
      • 2021-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多