WS-Security:无法声明HttpsToken

时间:2015-04-23 20:19:41

标签: java web-services soap ws-security

我在WSDL中遵循了ws策略:

    <wsp:Policy wssutil:Id="Wssp1.2-2007-Https-UsernameToken-Plain.xml">
    <ns1:TransportBinding xmlns:ns1="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702">
        <wsp:Policy>
            <ns1:TransportToken>
                <wsp:Policy>
                    <ns1:HttpsToken/>
                </wsp:Policy>
            </ns1:TransportToken>
            <ns1:AlgorithmSuite>
                <wsp:Policy>
                    <ns1:Basic256/>
                </wsp:Policy>
            </ns1:AlgorithmSuite>
            <ns1:Layout>
                <wsp:Policy>
                    <ns1:Lax/>
                </wsp:Policy>
            </ns1:Layout>
            <ns1:IncludeTimestamp/>
        </wsp:Policy>
    </ns1:TransportBinding>
    <ns2:SupportingTokens xmlns:ns2="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702">
        <wsp:Policy>
            <ns2:UsernameToken
                ns2:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient">
                <wsp:Policy>
                    <ns2:WssUsernameToken10/>
                    <ns2:HashPassword/>
                </wsp:Policy>
            </ns2:UsernameToken>
        </wsp:Policy>
    </ns2:SupportingTokens>
</wsp:Policy>

为了支持我的客户端内部的WS安全性,我实现了:

        ((BindingProvider) port ).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, this.URL);

        AddressingProperties maps = new AddressingPropertiesImpl();
        ((BindingProvider) port).getRequestContext().put("javax.xml.ws.addressing.context", maps);

        Map<String, Object> ctx = ((BindingProvider) port).getRequestContext();

        ctx.put("ws-security.callback-handler", UsernamePasswordCallback.class.getName());

        UsernamePasswordCallback.user = this.USER;
        UsernamePasswordCallback.pass = this.PASS;

        ctx.put("ws-security.username", UsernamePasswordCallback.user);
        ctx.put("ws-security.callback-handler", UsernamePasswordCallback.class.getName());

        Client client = ClientProxy.getClient(port);
        client.getOutInterceptors().add(new LoggingOutInterceptor());
        client.getInInterceptors().add(new LoggingInInterceptor());

据我了解,当你有WssUsernameToken10HashPassword时,通常会这样做。问题似乎与TransportBinding有关:

HttpsToken could not be asserted: HttpURLConnection is not a HttpsURLConnection

有些人过去曾遇到过这个问题,不幸的是,似乎没有解决方案,也没有单一的回复。

我很感激任何想法。

2 个答案:

答案 0 :(得分:1)

如果有人遇到类似问题我建议查看cxf库版本:服务器端的不同版本和客户端可能会导致此问题。

答案 1 :(得分:0)

如果您将<ns1:HttpsToken/>与http:// url一起使用(例如,您处于开发环境中而不使用https),则很可能会出现错误消息,抱怨Http连接的HttpsToken问题 如果您使用HTTP连接,请将HttpsToken替换为HttpToken。