Android ksoap2 UsernameToken身份验证安全性处理失败

时间:2014-10-06 23:25:46

标签: android web-services android-ksoap2

我试图调用测试程序" String witaj(String name)"使用UsernameToken身份验证的WS(波兰描述和文档:http://www.poczta-polska.pl/webservices/)。

    private final String NAMESPACE = "http://sledzenie.pocztapolska.pl/";
    private final String URL = "https://tt.poczta-polska.pl/Sledzenie/services/Sledzenie?wsdl";
    private final String SOAP_ACTION = "http://sledzenie.pocztapolska.pl/witaj";
    private final String METHOD_NAME = "witaj";

    @Override
    protected Void doInBackground(Void... params) {
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        PropertyInfo name = new PropertyInfo();
        name.setNamespace(NAMESPACE);
        name.setName("imie");
        name.setValue("ciumciurumcia");
        name.setType(String.class);
        request.addProperty(name);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
//--------------------------------------------------------------------------------------------
        Element headers[] = new Element[1];
        headers[0]= new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security");
        headers[0].setAttribute(envelope.env, "mustUnderstand", "1");
        Element security=headers[0];

        Element to = new Element().createElement(security.getNamespace(), "UsernameToken");
        to.setAttribute("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "Id", "UsernameToken-2");

        Element action1 = new Element().createElement(security.getNamespace(), "Username");
        action1.addChild(Node.TEXT, "sledzeniepp");
        to.addChild(Node.ELEMENT,action1);

        Element action2 = new Element().createElement(security.getNamespace(), "Password");
        action2.setAttribute(null, "Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-tokenprofile-1.0#PasswordText");
        action2.addChild(Node.TEXT, "PPSA");
        to.addChild(Node.ELEMENT,action2);

        headers[0].addChild(Node.ELEMENT, to);
        envelope.headerOut = headers;
//--------------------------------------------------------------------------------------------
        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

        try {
            androidHttpTransport.debug = true;
            androidHttpTransport.call(SOAP_ACTION, envelope);
...

doc:

中描述的肥皂信封示例
<soapenv:Envelope xmlns:sled="http://sledzenie.pocztapolska.pl" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
    <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <wsse:Username>sledzeniepp</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-tokenprofile-1.0#PasswordText">PPSA</wsse:Password>
        </wsse:UsernameToken>
    </wsse:Security>
</soapenv:Header>
<soapenv:Body>
    <sled:witaj>
        <sled:imie>Jan</sled:imie>
    </sled:witaj>
</soapenv:Body>

我的代码生成的信封:

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header>
    <n0:Security v:mustUnderstand="1" xmlns:n0="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <n0:UsernameToken n1:Id="UsernameToken-2" xmlns:n1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <n0:Username>sledzeniepp</n0:Username>
            <n0:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-tokenprofile-1.0#PasswordText">PPSA</n0:Password>
        </n0:UsernameToken>
    </n0:Security>
</v:Header>
<v:Body>
    <n2:witaj id="o0" c:root="1" xmlns:n2="http://sledzenie.pocztapolska.pl/">
        <n2:imie i:type="d:string">ciumciurumcia</n2:imie>
    </n2:witaj>
</v:Body>

我已尝试使用Nonce + Created等版本,并且答案是最终的:

... <faultcode>soapenv:Server</faultcode>
    <faultstring>WSDoAllReceiver: security processing failed</faultstring>
    <detail />

我认为怀疑是信封标签中缺少名称空间http://sledzenie.pocztapolska.pl/。但我不能把它放在那里。 欢迎任何吸烟。

1 个答案:

答案 0 :(得分:1)

这是密码字段的错误类型命名空间。其余的代码现在正在运作。

正确的uri是&#34; http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText&#34;

最终我将工作代码放在https://github.com/mmprog/wspocztapolska上 标题构造和Web服务数据模型。