1

因此,我正在 Eclipse 中使用 armart 和 axis2 开发 Web 服务。我正在尝试实现一个简单的用户名/密码身份验证方案,但我有一些问题。

我的代码现在基本上可以工作了,但是在我的 SOAP 请求中添加了 3(!)次:

        <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1">
           <wsse:Username>test</wsse:Username>
           <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pass</wsse:Password>
        </wsse:UsernameToken>
        <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-2">
           <wsse:Username>test</wsse:Username>
           <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pass</wsse:Password>
        </wsse:UsernameToken>
        <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-3">
           <wsse:Username>test</wsse:Username>
           <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pass</wsse:Password>
        </wsse:UsernameToken>

我得到的响应是正确的,所以我真的不明白为什么相同的标题元素被添加了 3 次。有人可以帮忙吗?

我的 services.xml 看起来像这样:

请在此处输入您的服务描述

<wsp:Policy wsu:Id="UTOverTransport"
    xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
    xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
    <wsp:ExactlyOne>
        <wsp:All>
            <sp:SignedSupportingTokens
                xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                <wsp:Policy>
                    <sp:UsernameToken
                        sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient" />
                </wsp:Policy>
            </sp:SignedSupportingTokens>
            <ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy">
                <ramp:passwordCallbackClass>sec.PWCBHandler</ramp:passwordCallbackClass>
            </ramp:RampartConfig>

        </wsp:All>
    </wsp:ExactlyOne>
</wsp:Policy>


<messageReceivers>
    <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
    <messageReceiver  mep="http://www.w3.org/2004/08/wsdl/in-out"  class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</messageReceivers>
<parameter name="ServiceClass" locked="false">sec.add</parameter>

在客户端,我的axis2.xml 如下所示:

<wsp:Policy wsu:Id="UTOverTransport" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
    <wsp:ExactlyOne>
      <wsp:All>
        <sp:SignedSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
            <wsp:Policy>
                <sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient" />
          </wsp:Policy>
        </sp:SignedSupportingTokens>
        <ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy"> 
            <ramp:user>test</ramp:user>
            <ramp:passwordCallbackClass>sec.PWCBHandler</ramp:passwordCallbackClass>
        </ramp:RampartConfig>
      </wsp:All>
    </wsp:ExactlyOne>
</wsp:Policy>

我的 Client.java 是这样实现的:

public void invokeService(){

    ConfigurationContext ctx;
    try {
        ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(this.path, null);
        AddStub stub = new AddStub(ctx,this.EPR);

        ServiceClient client = stub._getServiceClient();
        Options o = client.getOptions();
                    o.setUsername("test");
                    o.setPassword("pass");
        client.engageModule("rampart");

        AddStub.AddNumbers add = new AddStub.AddNumbers();
        add.setA(this.a);
        add.setB(this.b);

        System.out.println("Requesting");
        AddStub.AddNumbersResponse response = stub.addNumbers(add);
        System.out.println(response.get_return());

    } catch (AxisFault e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 
    catch (RemoteException e) {
        e.printStackTrace();
    }
}
4

0 回答 0