java - How to pass password in soap header which requires password digest -
bellow header file using.
<soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:xsi=http://www.w3.org/2001/xmlschema-instance xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> <soap:header> <wsse:security soap:mustunderstand="1"> <wsse:usernametoken wsu:id="usernametoken-14867177"> <wsse:username>wsadvins</wsse:username> <wsse:password type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#passworddigest"> gqeg0mep2fappuljkkla3b8k73g= </wsse:password> <wsse:nonce>o7wgbbqpzrdwolsibihm7q==</wsse:nonce> <wsu:created>2007-02-20t19:45:56.456z</wsu:created> </wsse:usernametoken> </wsse:security> </soap:header> <soap:body> <!-- message body payload goes here --> </soap:body>
i creating passworddigest using below code.
string username="wsadvins" ; string password1 ='qeg0mep2fappuljkkla3b8k73g=="; string nonce1="o7wgbbqpzrdwolsibihm7q=="; string datetime = "2007-02-20t19:45:56.456z"; messagedigest sha1; string passworddigest=null; try { java.security.securerandom random = java.security.securerandom.getinstance("sha1prng"); random.setseed(system.currenttimemillis()); byte[] noncebytes = new byte[16]; random.nextbytes(noncebytes); string nonce = new string(org.apache.commons.codec.binary.base64.encodebase64(noncebytes), "utf-8"); sha1= messagedigest.getinstance("sha-1"); byte[] hash = messagedigest.getinstance("sha-1").digest(nonce.getbytes("utf-8")); sha1.update(datetime.getbytes("utf-8")); sha1.update(password1.getbytes("utf-8")); passworddigest = new string(base64.encode(sha1.digest(hash))); sha1.reset(); } catch (exception e) { // todo auto-generated catch block e.printstacktrace(); } system.out.println("generated password digest: " +passworddigest ); soapelement password = usernametoken.addchildelement("password", "wsse"); password.setattribute("type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#passworddigest"); password.addtextnode(passworddigest);
not sure whats going wrong. getting invalid username , password error time. soap ui works fine. 1 can me please.
Comments
Post a Comment