473,379 Members | 1,260 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

How to resolve Invalid Security Tocken Provided Error?

rahuljaiswal1987
Hi all,

I am very new to web services. I am workin on WS consumption part in my project. I am trying to get data from a web service hosted with in my network. I am using Ksoap2 API for making client. I am getting "Invalid Security Tocken was provided error". When i checked my server side log i found that "nonce" value which is passed is null. But when i am printing its value it is not null. Following is the code:


Expand|Select|Wrap|Line Numbers
  1. public class Main 
  2. {
  3.      private static final String SOAP_ACTION = "ProductDetails";
  4.      private static final String METHOD_NAME = "ProductDetails";
  5.      private static final String NAMESPACE = "http://www.mycomp.com/interfaces/ProductDetailsRequest.xsd";
  6.      private static final String URL = "http://localhost:8080/MyManagerReports/services/ProductDetailsWebService";
  7.      private Object resultsRequestSOAP = null;
  8.      public static void main(String[] args) 
  9.      {
  10.         SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
  11.         EpcDetails epcdetails=new EpcDetails();
  12.         epcdetails.setEpcId("urn:epc:tag:gid-96:9780321.42477.7");
  13.          request.addProperty("EpcDetails", epcdetails);
  14.         SoapSerializationEnvelope sse=new SoapSerializationEnvelope(SoapEnvelope.VER11);
  15.         String OASIS_SECURITY_XSD_URL="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
  16.         Element userNameTokenElt, userNameElt, passwordElt, nonceElt, createdElt;
  17.         String username="someuser";
  18.         String password="somepassword";
  19.         String nonce, created, digest;
  20.         userNameElt = new Element().createElement(OASIS_SECURITY_XSD_URL, "Username");
  21.         userNameElt.addChild(Node.TEXT, username);
  22.               passwordElt = new Element().createElement(OASIS_SECURITY_XSD_URL, "Password");
  23.               userNameTokenElt = new Element().createElement(OASIS_SECURITY_XSD_URL, "UsernameToken");
  24.               userNameTokenElt.addChild(Node.ELEMENT, userNameElt);
  25.               nonce=generateNonce();
  26.               created=DateUtils.currentISO8601ZuluTimestamp();
  27.               digest=UsernameToken.doPasswordDigest(nonce, created,password);
  28.               passwordElt.addChild(Node.TEXT, digest);
  29.               nonceElt=new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "Nonce");
  30.               System.out.println(nonce);
  31.               nonceElt.addChild(Node.TEXT,nonce);
  32.               createdElt=new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "Created");
  33.               createdElt.addChild(Node.TEXT,created);
  34.               userNameTokenElt.addChild(Node.ELEMENT, passwordElt);
  35.               userNameTokenElt.addChild(Node.ELEMENT, nonceElt);
  36.               userNameTokenElt.addChild(Node.ELEMENT, createdElt);
  37.            Element securityElement = new Element().createElement(OASIS_SECURITY_XSD_URL, "Security");
  38.            securityElement.setPrefix("wsse", OASIS_SECURITY_XSD_URL);
  39.            securityElement.addChild(Node.ELEMENT, userNameTokenElt);
  40.         Element []seurity ={securityElement}; 
  41.         sse.headerOut=seurity;
  42.         sse.setOutputSoapObject(request);
  43.         sse.addMapping(NAMESPACE, 
  44.         ProductDetailsRequest.ProductDetailsRequest.getSimpleName(),
  45.         ProductDetailsRequest.ProductDetailsRequest);
  46.         AndroidHttpTransport aht=new AndroidHttpTransport(URL);
  47.         try 
  48.         {
  49.          aht.call(SOAP_ACTION, sse);
  50.          SoapObject response= (SoapObject) sse.getResponse();
  51.         } catch (IOException e) 
  52.         {
  53.          e.printStackTrace();
  54.         } catch (XmlPullParserException e) {
  55.          e.printStackTrace();
  56.        }
  57.  
  58.         }
  59.      public static String generateNonce()
  60.      {
  61.        try    
  62.        {
  63.             byte[] nonce = WSSecurityUtil.generateNonce(18);
  64.          return new String(Base64.encode(nonce));
  65.           }catch (WSSecurityException e)
  66.           {
  67.         throw new RuntimeException(e);
  68.        }
  69.   }
  70.  
  71. }
\


Please reply ASAP.

Thanks & Regards,
Rahul Jaiswal
Nov 24 '10 #1
0 1182

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: newbie | last post by:
Hi all , I'm using CDO from my vb component to fire email. The problem is whenever one of the email addresses in to, or cc is wrong then none of the mails are fired even to the correct...
1
by: Rob Barnes | last post by:
When I try to create a machine-level security policy based on an assembly's strong name, I get the following error: "ERROR: Invalid label or name" The caspol command is: "caspol -machine...
1
by: verb13 | last post by:
In an asp page in localhost I have this: Set x = Server.CreateObject("Scripting.Dictionary") And I get this error: Invalid class string If I omit Server like this: Set x =...
9
by: John Stemper | last post by:
I've recently moved an ASP.Net app to our deployment server after it was verified on our integration test server. On the deployment server I am now getting the following error:...
2
by: GD | last post by:
Hi, An intranet application, with a SMTP mail function that lets users to attach files with emails by selecting files in their local computers (through a file browser component), works perfect on...
0
by: Sam Fields | last post by:
I have found very little regarding the error "Unable to find an entry point named EnumerateSecurityPackagesW in DLL security.dll. ". I have an ASP.NET Web Service being accessed via SSL. I found...
3
by: Ajay Choudhary | last post by:
Hi, If the client tries to access a web service with invalid namespace, it gets a SOAP exception as invalid SOAPAction. The invalid namespace will happen because the proxies on the client side...
3
by: adiel_g | last post by:
I cannot seem to get a wmv file to stream from asp.net. I have tried the following code. I need to be able to use either response.outpustream or response.binarywrite since I will be getting the...
3
by: Asle | last post by:
Hi, I am using Ms Access 2000. i wrote a simple VBA Code to perform addition operation based on the user input. I used AfterUpdate event for each fields to update the value to Sub_Total ...
1
by: mandanarchi | last post by:
Set myHTTP = CreateObject("msxml2.xmlhttp") Set myDom = CreateObject("MSXML2.DOMDocument") myDom.async = False myDom.Load (myxml) myHTTP.Open "POST", "https://link-removed.aspx",...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.