Shiro cannot jump to index page after successful login with AUTHC configuration

Source: Internet
Author: User

These two days found a problem, title, tried a lot of methods, can not solve, really depressed. Finally see the source code to know, my configuration is as follows. The original intention is from/api/user/login login success, jump to/index, but how can not jump to/index. The original AUTHC interceptor (ie, formauthenticationfilter), verification success will only jump to the beginning of the page you enter, because I am from the/api/user/login page into the login, so will only jump to/api/user/login. To jump to the/index page, only the first entry from the/index page, the background will be redirected to the/api/user/login page, the verification is successful, only return to the/index page.

The configuration is as follows:

    <!--Shiro Web filter, ID to be consistent---<bean id= "Shirofilter" class= "Org.apache.shiro.spring.web.ShiroFilte" Rfactorybean "> <property name=" SecurityManager "ref=" SecurityManager "/> <property name=" Login Url "value="/api/user/login "/> <property name=" Successurl "value="/index "/> <property name="
                Unauthorizedurl "value="/unauthorized "/> <property name=" Filters "> <map>
        <entry key= "authc" value-ref= "Formauthenticationfilter"/> </map> </property>
                <property name= "Filterchaindefinitions" > <value>/static/** = anon
                /api/user/login = Authc/api/user/logout = logout/api/user/register* = Anon /unauthorized = Anon/** = user </value> </property> </bea N>

Formauthenticationfilter Part Source:

    Protected Boolean onloginsuccess (Authenticationtoken token, Subject Subject,
                                     servletrequest request, Servletresponse response) throws Exception {
        issuesuccessredirect (request, response);
        We handled the success redirect directly, prevent the chain from continuing:
        return false;
    }

From the source code we can see that after the successful login, will be executed

     protected void Issuesuccessredirect (ServletRequest request, servletresponse response) throws Exception {
        Webutils.redirecttosavedrequest (Request, Response, Getsuccessurl ());
    }

This method is

   public static void Redirecttosavedrequest (ServletRequest request, servletresponse response, String Fallbackurl)
        Throws IOException {String successurl = null;
        Boolean contextrelative = true;
        Savedrequest savedrequest = webutils.getandclearsavedrequest (request);
            if (savedrequest! = null && Savedrequest.getmethod (). Equalsignorecase (Accesscontrolfilter.get_method)) {
            Successurl = Savedrequest.getrequesturl ();
        Contextrelative = false;
        } if (Successurl = = null) {Successurl = Fallbackurl; } if (Successurl = = null) {throw new IllegalStateException ("Success URL not available via saved requ EST or via the "+" Successurlfallback method parameter.

        One of these must is non-null for "+" issuesuccessredirect () to work. ");
    Webutils.issueredirect (Request, response, Successurl, NULL, contextrelative); } 

The

key is Successurl = Savedrequest.getrequesturl (), which will reassign the Successurl and the configured/index to fail.

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.