Spring 3.1: Redirect after login not working

落花浮王杯 提交于 2019-12-05 05:58:00
Satyam Koyani

In the Spring, there is requestCache (which stores the SavedRequest in the HttpSession) which determines the strategy used to save a request during the authentication process in order that it may be retrieved and reused once the user has authenticated.

So when user request to open a page but that page expects the user to be logged in In that you have to store that request in requestCache and once Authentication will be successful then you have to get that previous request which is already stored in the requestCatch and redirect user to that request Below information help you to achieve this.

See this example which explains the same concept you are looking for

Good Article which also explains same concept in detail with a little bit different way

SavedRequestAwareAuthenticationSuccessHandler :

In your case you have to use authentication success strategy which can make use of the DefaultSavedRequest which may have been stored in the session by the ExceptionTranslationFilter. When such a request is intercepted and requires authentication, the request data is stored to record the original destination before the authentication process commenced, and to allow the request to be reconstructed when a redirect to the same URL occurs. This class is responsible for performing the redirect to the original URL if appropriate.

  • If the alwaysUseDefaultTargetUrl property is set to true, the defaultTargetUrl will be used for the destination. Any DefaultSavedRequest stored in the session will be removed.

  • If the targetUrlParameter has been set on the request, the value will be used as the destination. Any DefaultSavedRequest will again be removed.

  • If a DefaultSavedRequest is found in the RequestCache (as set by the ExceptionTranslationFilter to record the original destination before the authentication process commenced), a redirect will be performed to the Url of that original destination. The DefaultSavedRequest object will remain cached and be picked up when the redirected request is received (See SavedRequestAwareWrapper).

  • If no DefaultSavedRequest is found, it will delegate to the base class.

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