I have the following situation:
I have 2 web applications running on Tomcat. Initially, the user is registered in application 1 and then. There is a link to the application 2. By clicking the link, the User should be redirected to the second application.
Both applications use LDAP authentication.
Now the problem is that the second application has its own authentication system.
So, we plan to implicitly authenticate the user who is registered in the first system.
I wrote a servlet that starts when I click the link for App2 in App1.
I am trying to use below code which should call the "ldap-login" servlet on app2 with the given parameters. The names of the parammers are correct.
String targetURL = "http://localhost:8080/app2/ldap-login"; HttpClient client = new HttpClient(); PostMethod doPost = new PostMethod(targetURL); //doPost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true); doPost.addParameter("login_netid", "alice"); doPost.addParameter("login_password", "alice"); try { int status = client.executeMethod(doPost); if (status == HttpStatus.SC_OK) { // redirect response.sendRedirect("http://localhost:8080/app2/myPage"); } else { System.out.println("Service failed, Response Code= " + HttpStatus.getStatusText(status)); System.out.println("Response Body --> " + doPost.getResponseBodyAsString()); } } catch (Exception ex) { System.out.println("ERROR: " + ex.getClass().getName() + " "+ ex.getMessage()); ex.printStackTrace(); } finally { doPost.releaseConnection(); }
But I get the answer "Moved temporarily."
Can someone suggest me an alternative?
source share