-1

where i will populate a table which has links and each link is pointing to different case id, when click on that link, i need to validate that 3rd party url in my java method and need to allow the browser to open secured page.

any pointers on how to achieve this is very helpful.

Thanks.

rangoon
  • 1
  • 5
  • With Servlet filter you can achieve what you required to do. Visit – Rajesh Oct 25 '13 at 23:26
  • Rajesh, but my use case is fairly simple, do i need to use servlet filter and all those things, i just need to authenticate lets say www.abc.com in java, and i will construct the url dynamically in java method which is a secured page, and once i pass this url to href, then it should open without challenging again. can you let me know a fairly simple solution. – rangoon Oct 26 '13 at 04:00

1 Answers1

1

Yes, this can be achieved with a simple serlvet. Suppose to say that you have list of href links in a table 1. Upon clicking on each href link direct it to your servlet.

Ex: < a href="/yourServlet.do?thirdPartyURL=actual3rdPartyURL">actual3rdPartyURL < / a>

  1. Validate this third party URL in your servlet code. If everything is okay
  2. Then redirect it with the SendRedirect method.

Note: it is not a good practice to show the URL in the browser address bar. as you mentioned that, you are the one who populating this URLs, Use a hashmap to store these URL's and map it with Case ID and redirect it. hope you got the complete info.

Please check the below example and let me know if you need more info

/**
 *  
 */
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{

    PrintWriter out = response.getWriter();

    /**
     * Assume that this is the map you are getting from third party
     * This map holds two value pairs
     * Map<CaseID, URL>
     */
    Map<String, String> lstURLS = new HashMap<String,String>();
    lstURLS.put("CASEID1", "https://www.abc.com/abc1");
    lstURLS.put("CASEID2", "https://www.def.com/def");
    lstURLS.put("CASEID3", "https://www.egh.com/egh");

    /**
     * Assume that the request parameter caseID, 
     * will provide you the case id which was selected by the user
     * from the provided table of URLS
     */
    String userProvidedCaseID = request.getParameter("caseID");
    System.out.println("MySerlvet | caseID | "+ userProvidedCaseID);

    /**
     * Retrieve the URL from the list of third party URL's
     */
    if(null != userProvidedCaseID){
        String thirdPartyURL = lstURLS.get("userProvidedCaseID");
        if(null != thirdPartyURL){
            response.sendRedirect(thirdPartyURL);
        }else{
            out.print("No Case ID found / Error message");
        }
    }else{
        out.print("No Case ID found / Error message");
    }
}
Rajesh
  • 11
  • 3
  • Rajesh, Can you give me the servlet code where i can authenticate the url and redirect it to the secured page. TIA. – rangoon Oct 29 '13 at 20:11
  • I have edited the code, please check and let me know. hope this will help you. – Rajesh Oct 29 '13 at 21:16
  • Rajesh, I need to authenticate the url like abc.com which is login page and it will have username and password, once i authenticate that page in the java method, and i need to redirect the page to secured page in that abc.com lets say abc.com/page1, where it should not challenge the user again. But i didn't see the authentication code in the code you pasted above. Thanks for helping me out. – rangoon Oct 29 '13 at 21:27
  • I got it totally wrong. 1. If You wanted to authenticate the third party website and read the data using [link](http://hc.apache.org/httpclient-3.x/authentication.html) 2. If you wanted the third party website not to authenticate again, you may need to look into this [link](http://stackoverflow.com/questions/7561631/oauth-2-0-benefits-and-use-cases-why). I have not tried this oAuth2, hence I dont have any example handy :( – Rajesh Oct 29 '13 at 21:36
  • Rajesh, can you let me know how to authenticate the url and get the secured page HTML, i tried HttpClient but unable to pass through it. – rangoon Nov 05 '13 at 22:40