Not able to Login from a Servlet using j_security_check | Community
Skip to main content
Tuhin_Ghosh
Level 8
October 10, 2016

Not able to Login from a Servlet using j_security_check

  • October 10, 2016
  • 1 reply
  • 7259 views

Hi Everyone,

I am trying to login with the j_security_check through a Servlet. The below is the code I have in my Servlet.

HttpClient httpClient = new HttpClient();
PostMethod postMethod = new PostMethod(“http://localhost:4502/content/tuhin/home/j_security_check”);

postMethod.addParameter(“j_username”, “tuhin”);
postMethod.addParameter(“j_password”, “tuhin”);
postMethod.addParameter(“_charset_”, “UTF-8”);

httpClient.executeMethod(postMethod);

Now this code is returning 302 status code. That means its not failing, otherwise it should have returned 403.

But at the same time I can see its not logging in with the intended user.

Am I doing something wrong? Or there is any more steps that I am missing ?

Thanks and Regards
Tuhin

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

Tuhin_Ghosh
Level 8
October 11, 2016
        Hi Scott, I have seen this code. In there the code present is inside a jsp doing a post call from a HTML form and that works just fine. But I am trying to achieve the same inside from a servlet. I have imitated the same code in the servlet, see above. But its not working.
Pawan-Gupta
Level 8
October 11, 2016

Hi Tuhin,

Can you please explain how you are validating the user is not logged in once execute is done? because httpclient call is to make request and get response as object (you can use it for further request as you want - its like connection) but it will not create/update existing user session which was created using AEM authentication process (for that you have extend that servlet)

Thanks,

Pawan

Tuhin_Ghosh
Level 8
October 13, 2016

Hi Pawan,

 

Thanks for the reply. I am printing the logged in user id in the page to see which/what user is logged in.

My initial Idea was calling j_security_check servlet with proper parameters would log in the user. But apparently that is not the case. And as you mentioned it is not updating the existing session. Could you please let me know how I could programmatically  log the user in? Any code snipped would be very helpful.

 

Thanks and Regards,

Tuhin