mmprog
mmprog

Reputation: 781

Android ksoap2 UsernameToken Authentication security processing failed

ive tried to call test procedure "String witaj(String name)" of WS using UsernameToken Authentication (polish description and documentation: 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);
...

Example soap envelope described in 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>

evelope generated by my code:

<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>

Ive tried version with Nonce+Created etc. and answer is allways:

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

I think suspect is lack of namespace http://sledzenie.pocztapolska.pl/ in envelope tag. But i cant put it there. Any sugestions will be welcome.

Upvotes: 1

Views: 1044

Answers (1)

mmprog
mmprog

Reputation: 781

That was wrong type namespace of Password field. Rest of the code is working now.

Correct uri is "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"

Eventually i've put working code on https://github.com/mmprog/wspocztapolska with header construction and webservice data model.

Upvotes: 1

Related Questions