Search code examples
javaweb-servicessingle-sign-onurl-parametersondemand

Retreiveing Encoded Value from URL


I have passes a encoded SSO token in URL...so the URL looks like

 http://127.0.0.1:7101/CRMOD_UCM-Sankalp-context-root/BrowseFile.jsp?token=%246%24zhxjx%2fpz6dVucl9cgG43ii2Tr4qVnNbeqJg8jCy6Jj7vRvXN4%3d%3b%246%24GlRGp%2fxfEM308NZGmY%2fhjHav2yjHSvbww1l0%2fCcCtcVjzl%2bCQFlQPdBRKO0t1XUmF0I6xLmfQ%2fnb7VgJeSYnvrAb9YUQQ3tvr%2fBZ%2bIRZiBAGU2%2fZg%3d

but when i retreive the value of variable and print it using out.println("SSO Token:"+request.getParameter("token")); it prints

$6$zhxjx/pz6dVucl9cgG43ii2Tr4qVnNbeqJg8jCy6Jj7vRvXN4=;$6$GlRGp/xfEM308NZGmY/hjHav2yjHSvbww1l0/CcCtcVjzl+CQFlQPdBRKO0t1XUmF0I6xLmfQ/nb7VgJeSYnvrAb9YUQQ3tvr/BZ+IRZiBAGU2/Zg=

The correct token is which is present in the URL, WHY i am getting such a different value in my print...

Kindly help......


Solution

  • You are getting encoded value if you want decode then use following code. By default system decode for us but in your case it is not decoded and you must explicitly decode value of request.getParameter("token").

    String token = request.getParameter("token").toString();
    // To decode url
    String decodedtoken = URLDecoder.decode(token , "UTF-8");
    System.out.println("Decoded token value "+ decodedtoken);
    
    // To encode url 
    String encodedtoken = URLEncoder.encode(token , "UTF-8"); 
    System.out.println("Encoded token value "+ encodedtoken);