Shiro controls the previous page after successful login, And shiro jumps back

Source: Internet
Author: User

Shiro controls the previous page after successful login, And shiro jumps back

After login, jump back to the previous page is a requirement encountered during login and registration module, and it is also necessary. If you directly access the login page, you can control it to go directly to the home page, but you need to directly access your own shopping cart and other pages that require identity authentication, or because the session times out, if you need to log on again, it is a matter of improving the user experience to jump back to the previous page. To implement this function, we have two methods for the moment. One is to log on using ajax, so that the user can log on directly through the pop-up window on the current page, the second is to store the url before the user logs on to the session. After the login operation is successful, check whether such a url exists in the session.

Shiro is integrated into the project, which has such a function in the WebUtils tool class.

 

So much nonsense. In fact, some people have written such a blog article on the Internet about the implementation of this function. The shiro tutorial written by this great god is worth reading, but I am using it.

SavedRequest savedRequest = WebUtils. when getSavedRequest (request); is used, the savedRequest object is always blank. After waiting for a while, the savedRequest object will be pointed out by someone in the group later. It is found that the configuration file is not written, that is, filterChainDefinitions in shiroFilter, the url to be intercepted is not completely written, as shown in the following section.

<! -- Shiro's Web Filter --> <bean id = "shiroFilter" class = "org. apache. shiro. spring. web. shiroFilterFactoryBean "> <property name =" securityManager "ref =" securityManager "/> <property name =" loginUrl "value ="/user-web/login "/> <property name = "unauthorizedUrl" value = "/unauthorized"/> <property name = "filters"> <util: map> <entry key = "authc"> <bean class = "org. apache. shiro. web. filter. authc. passThruAuthenticationFilter "/> </entry> </util: map> </property> <property name = "filterChainDefinitions"> <value> # Put the files that can be accessed without authentication in front of/js/* = anon/css/* = anon/ img/* = anon/images/* = anon/user-web/login = anon/logout = logout/user-web/* = authc/backend-web/* = authc </value> </property> </bean>

Only/user-web/* (except for login, url matching uses a short circuit mechanism, that is, the first matching principle) and the url after/backend-web, in this way, when the user does not log on to the session and access the prefix containing the above two links, the user will jump to the previous interface after the login is successful.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.