简体   繁体   English

在 Wicket 9 中,当用户的会话在某些页面中过期时,他们被重定向到登录页面而不是会话过期页面

[英]In Wicket 9, when the user's session expires in certain pages, they are redirected to the login page not the Session Expired page

While upgrading some legacy code from Wicket 1.5 to Wicket 9, I found that redirection to a "Session expired" notification page seems to be partially broken.在将一些遗留代码从 Wicket 1.5 升级到 Wicket 9 时,我发现重定向到“会话已过期”通知页面似乎部分中断。

I have the following statement, which always used to work before, in the main application file:我在主应用程序文件中有以下语句,以前总是使用它:

getApplicationSettings().setPageExpiredErrorPage(MyErrorPage.class);

Here is the scenario which should trigger redirection to "MyErrorPage":这是应该触发重定向到“MyErrorPage”的场景:

  1. The user successfully logs in and goes into any menu option.用户成功登录并进入任何菜单选项。
  2. They sit around for a while, doing nothing, and their session times out.他们坐了一会儿,什么都不做,然后他们的会话超时了。
  3. After this period of inactivity, they click on a link or attempt to submit a form.在这段不活动期之后,他们会单击链接或尝试提交表单。
  4. At this point, they ought to be redirected to "MyErrorPage".此时,它们应该被重定向到“MyErrorPage”。

The menu option invoked in point (1) - lets call it MyMenuPage - could have been invoked with two possible types of syntax: Either:在点 (1) 中调用的菜单选项 - 让我们称之为 MyMenuPage - 可以用两种可能的语法类型调用:

setResponsePage(MyMenuPage.class);

Or:或者:

setResponsePage(new MyMenuPage(params));

It seems that the user will only be redirected to my custom error page if the original menu page was invoked with the SECOND syntax.如果使用 SECOND 语法调用原始菜单页面,则似乎用户只会被重定向到我的自定义错误页面。

If the original page was invoked with the FIRST syntax, the user is sent straight to the login page, without any explanation about the fact that their page has expired.如果原始页面是使用 FIRST 语法调用的,则用户会直接进入登录页面,而不会对其页面已过期这一事实进行任何解释。

Please can someone advise me how to get the same result in both types of page - which are not stateless, because the user has logged in.请有人告诉我如何在两种类型的页面中获得相同的结果 - 这不是无状态的,因为用户已登录。

There is a difference between page being expired and http session expiration.页面过期和 http 会话过期之间存在差异。

As PageExpiredException's javadoc [I] explains there are three possible reasons for it:正如 PageExpiredException 的 javadoc [I] 解释的那样,可能有以下三种原因:

  • the page have never been stored there, eg an error occurred during the storing process该页面从未存储在那里,例如在存储过程中发生错误
  • the http session has expired and thus all pages related to this session are erased too http 会话已过期,因此与此会话相关的所有页面也被删除
  • the page instance has been erased because the store size is exceeded由于超出存储大小,页面实例已被擦除

Wicket stores all stateful pages on the disk. Wicket 将所有有状态的页面存储在磁盘上。 Later when you use such page, eg by clicking a link, Wicket loads the page instance, executes the click, and render the response.稍后当您使用此类页面时,例如通过单击链接,Wicket 加载页面实例、执行单击并呈现响应。

If the http session is expired then most probably your authentication strategy kicks in and redirects to the login page without even trying to load the old page.如果 http 会话过期,那么您的身份验证策略很可能会启动并重定向到登录页面,甚至无需尝试加载旧页面。 If you use Component#continueToOriginalDestination() after successful login then the user will be navigated to a new instance of the old page.如果您在成功登录后使用Component#continueToOriginalDestination() ,那么用户将被导航到旧页面的新实例。

To summarize:总结一下:

  • if the http session expires then your application redirect to the LoginPage如果 http 会话过期,则您的应用程序重定向到 LoginPage
  • if a page instance is expired then by default Wicket will create a new instance of it (see PageSettings#setRecreateBookmarkablePagesAfterExpiry(boolean) ) or show the configured getApplicationSettings().setPageExpiredErrorPage(MyPage.class);如果页面实例已过期,则默认情况下 Wicket 将创建它的新实例(请参阅PageSettings#setRecreateBookmarkablePagesAfterExpiry(boolean) )或显示配置的getApplicationSettings().setPageExpiredErrorPage(MyPage.class); will be rendered将被渲染

To debug what happens in your case put some breakpoints at the following places:要调试在您的情况下发生的情况,请在以下位置放置一些断点:

  1. https://github.com/apache/wicket/blob/6a7e4c3d770324f125fbf43615c7708b67c8d8c5/wicket-core/src/main/java/org/apache/wicket/Component.java#L1061 https://github.com/apache/wicket/blob/6a7e4c3d770324f125fbf43615c7708b67c8d8c5/wicket-core/src/main/java/org/apache/wicket/Component.java#L1061
  2. https://github.com/apache/wicket/blob/6a7e4c3d770324f125fbf43615c7708b67c8d8c5/wicket-auth-roles/src/main/java/org/apache/wicket/authroles/authentication/AuthenticatedWebApplication.java#L134 https://github.com/apache/wicket/blob/6a7e4c3d770324f125fbf43615c7708b67c8d8c5/wicket-auth-roles/src/main/java/org/apache/wicket/authroles/authentication/Authenticated1WebApplication.java#L

I. https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/protocol/http/PageExpiredException.java#L31一、 https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/protocol/http/PageExpiredException.java#L31

Seems like I just have to work round this by always using the following syntax:似乎我只需要始终使用以下语法来解决这个问题:

setResponsePage(new MyPage());

This is not the end of the world, because at least I don't have to pass any parameters in, in order to trigger the required "Go to session expired page" behaviour.这不是世界末日,因为至少我不必传入任何参数来触发所需的“转到会话过期页面”行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM