Auto login with j_security_check

一曲冷凌霜 提交于 2019-12-11 11:44:49

问题


I am new to j_security_check tomcat. However i implemented login functionality(form based authentication) using login filter & some settings in web.xml. When we trying to access a secured page, tomcat redirects to login page. After providing credentials it redirects user to a page which user tried to access. So far it is working as expected.

But, the new requirement is: User access a non-secured page (public page), there he can enter his login username & login password. On submitting this page we have to do

  1. create a user with details provided by the user(save to DB)
  2. auto login the user and redirect to a secured home page.

the 1st point has already been implemented and working fine. After inserting new user i am redirecting to secured home page. Then container shows a login page where user can enter his credentials, the submit action of login page takes user to secured page.

But i want to redirect user to secured home page after saving his details to DB as we have his username & password i.e. non-secured page to secured page without login page interruption. I want to use container managed authentication only.

Any ideas??

Thanks in advance.


回答1:


If you are using Tomcat 7.0.x and a Servlet 3.0 webapp, you can use the login(user, pass) method of the HttpServletRequest object in your Servlet or Filter.

http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#login(java.lang.String,%20java.lang.String)



来源:https://stackoverflow.com/questions/14191751/auto-login-with-j-security-check

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!