当前位置:编程学习 > 网站相关 >>

shiro不跳转successUrl的问题

遇到shiro校验框架成功后不进行自动跳转到指定页面;

相关配置如下:


 01 <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"> 

02     <property name="securityManager" ref="securityManager" /> 

03     <property name="loginUrl" value="/login" /> 

04     <property name="successUrl" value="/account/user/current" /> 

05     <property name="filterChainDefinitions"> 

06         <value> 

07             /login = authc 

08             /test = authc 

09             /logout = logout 

10             /static/** = anon 

11             /** = authc 

12         </value> 

13     </property> 

14 </bean>

 

我使用的是验证过滤器是authc;逻辑上只要登录成功即可跳转至“/account/user/current”实际上不行;

主要原因是successUrl配置只是做为一种附加配置,只有session中没有用户请求地址时才会使用successUrl;

系统默认登录成功后首次跳转的地址为,访问系统时初次使用地址,例:如果用户首次访问的是http://****/aa/aa.html;

 那么shiro校验成功后跳转的地址即可http://****/aa/aa.html; 否则shiro将跳转到默认虚拟路径:“/”;

对于应用中,如果没有注册/路径,则默认使用web.xml中配置的<welcom-list>配置;

shiro源码逻辑如下:


 01 String successUrl = null; 

02        boolean contextRelative = true; 

03        SavedRequest savedRequest = WebUtils.getAndClearSavedRequest(request); 

04        if (<B minmax_bound="true"><SPAN style="COLOR: #e53333" minmax_bound="true">savedRequest != null && savedRequest.getMethod().equalsIgnoreCase(AccessControlFilter.GET_METHOD)</SPAN></B>) { 

05            successUrl = savedRequest.getRequestUrl(); 

06            contextRelative = false; 

07        } 

08  

09        if (successUrl == null) { 

10            successUrl = fallbackUrl; 

11        } 

12  

13        if (successUrl == null) { 

14            throw new IllegalStateException("Success URL not available via saved request or via the " + 

15                    "successUrlFallback method parameter. One of these must be non-null for " + 

16                    "issueSuccessRedirect() to work."); 

17        } 

18  

19        WebUtils.issueRedirect(request, response, successUrl, null, contextRelative);

 

上述代码红色部分表明,对于成功后地址指向,会依据会话SESSION中保留的请求地址;

 


补充:Web开发 , 其他 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,