如何更改j_security_check使用的原始请求页面?
当未经身份验证的用户请求某些资源时,他将被重定向到登录页面,但j_security_check
将保留原始请求的资源。如果用户登录成功,将被重定向到该资源。
问题是有时请求的资源是动态的,因此它可能不存在。我的应用程序中有很多地方都有这种行为,因此我们不是在每个“资源处理程序”(控制器)中验证这一点,而是尝试将所有这些逻辑集中在拦截 j_security_check
的过滤器中转到登录页面。
现在,我们如何获取基于表单的身份验证机制保存的原始请求资源呢?它依赖于供应商吗?
另一种选择:
如果我可以在j_security_check
之前运行过滤器,我将无法修改URL,但可以使用“有效URL”向用户发送重定向。但是我怎样才能在j_security_check
之前执行过滤器呢?
When an unauthenticated user request some resources, he will be redirected to a login page but j_security_check
will keep the original requested resource. If the user login successfully, it will be redirected to that resource.
The problem is that sometimes the requested resource is dynamic, so it might not exists. I have a lot of places in my application with this behavior, so instead of validate this in each "resource handler" (controller), we are trying to centralize all this logic in a filter that intercept the j_security_check
forward to the login page.
Now, how can we get the original requested resource kept by the Form-Based Authentication mechanism? It's vendor dependent?
Another alternative:
If I can run a filter BEFORE the j_security_check
I can't modify the URL but I can send a redirect to the user with a "valid URL". But how can I execute a filter before the j_security_check
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果页面是动态的并且“可能不存在”,但链接可能在某个时间点有效,并且您的应用程序在旧请求上失败,那么您的应用程序中出现了某些问题。如果“动态页面”实际上只是使用路径变量的模式匹配,那么您的代码应该能够响应这些情况,因为每个页面请求都应该得到适当的处理。
示例:我有一个页面来显示用户的公开个人资料。也许用户从我的网站取消注册。现在“页面”不应该“存在”。例如,在 Spring 中,我将使用 PathVariable 并使我的处理程序响应用户的存在或不存在:
在这种情况下,我将向浏览器返回一些有意义的消息,或者也许重定向到另一个位置。这似乎不是一个安全问题,而是一个应用程序设计问题。
If pages are dynamic and "may not exist", but yet a link could have been valid at some point in time, and your application barfs on that old request, then something is broken in your application. If "dynamic pages" are really just pattern matches using path variables, then your code should be responsive to those situations, as each page request should be handled appropriately.
Example: I have a page to display a user's public profile. Maybe the user unregisters from my site. Now the "page" shouldn't "exist". In Spring, for example, I would use a
PathVariable
and make my handler responsive to the existence or non-existence of the user:In this case, I would return some meaningful message to the browser, or maybe redirect to another location. This seems to be less a security issue and more one of application design.
您需要执行以下操作:
j_security_check
创建过滤器chain.doFilter(...)
之前,更改内容名为 WASReqURL 的 cookie 重定向到成功登录后的 servlet。Here is what you need to do:
j_security_check
in the web.xmlchain.doFilter(...)
, change the content of the cookie named WASReqURL to redirect to a servlet which will be the post successful login.