使用 j_security_check 自动登录 [英] Auto login with j_security_check

查看:78
本文介绍了使用 j_security_check 自动登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 j_security_check tomcat 的新手.但是我使用登录过滤器实现了登录功能(基于表单的身份验证)web.xml 中的一些设置.当我们尝试访问安全页面时,tomcat 会重定向到登录页面.提供凭据后,它会将用户重定向到用户尝试访问的页面.到目前为止,它按预期工作.

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. 使用用户提供的详细信息创建用户(保存到数据库)
  2. 自动登录用户并重定向到安全主页.

第 1 点已经实施并且运行良好.插入新用户后,我重定向到安全主页.然后容器显示一个登录页面,用户可以在其中输入他的凭据,登录页面的提交操作将用户带到安全页面.

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.

有什么想法吗??

提前致谢.

推荐答案

如果您使用的是 Tomcat 7.0.x 和 Servlet 3.0 webapp,您可以使用 Servlet 中 HttpServletRequest 对象的 login(user, pass) 方法或过滤.

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)

这篇关于使用 j_security_check 自动登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆