如何更改j_security_check使用的原始请求页面?

发布于 2024-12-02 15:13:19 字数 448 浏览 0 评论 0原文

当未经身份验证的用户请求某些资源时,他将被重定向到登录页面,但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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝眼睛不忧郁 2024-12-09 15:13:19

如果页面是动态的并且“可能不存在”,但链接可能在某个时间点有效,并且您的应用程序在旧请求上失败,那么您的应用程序中出现了某些问题。如果“动态页面”实际上只是使用路径变量的模式匹配,那么您的代码应该能够响应这些情况,因为每个页面请求都应该得到适当的处理。

示例:我有一个页面来显示用户的公开个人资料。也许用户从我的网站取消注册。现在“页面”不应该“存在”。例如,在 Spring 中,我将使用 PathVariable 并使我的处理程序响应用户的存在或不存在:

@RequestMapping(value="/display/{userkey}")
public String displayUser (@PathVariable("userkey") String userkey) {
    User user = someDAO.getUser(userkey);
    if(user != null) {
        // do something
    } else {
        // do something else
    }
    return "theView";
}

在这种情况下,我将向浏览器返回一些有意义的消息,或者也许重定向到另一个位置。这似乎不是一个安全问题,而是一个应用程序设计问题。

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:

@RequestMapping(value="/display/{userkey}")
public String displayUser (@PathVariable("userkey") String userkey) {
    User user = someDAO.getUser(userkey);
    if(user != null) {
        // do something
    } else {
        // do something else
    }
    return "theView";
}

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.

木有鱼丸 2024-12-09 15:13:19

您需要执行以下操作:

  1. 在 web.xml 中为 j_security_check 创建过滤器
  2. 在您的过滤器中,在 chain.doFilter(...) 之前,更改内容名为 WASReqURL 的 cookie 重定向到成功登录后的 servlet。

Here is what you need to do:

  1. Create a filter for j_security_check in the web.xml
  2. In your Filter, before the chain.doFilter(...), change the content of the cookie named WASReqURL to redirect to a servlet which will be the post successful login.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文