`
kobe学java
  • 浏览: 250569 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

spring security 3.0 logout filter 代码中的一个小bug

 
阅读更多

先附上 
   
Java代码   收藏代码
  1.   public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)  
  2.         throws IOException, ServletException {  
  3.     HttpServletRequest request = (HttpServletRequest) req;  
  4.     HttpServletResponse response = (HttpServletResponse) res;  
  5.   
  6.     if (requiresLogout(request, response)) {  
  7.         Authentication auth = SecurityContextHolder.getContext().getAuthentication();  
  8.   
  9.         if (logger.isDebugEnabled()) {  
  10.             logger.debug("Logging out user '" + auth + "' and transferring to logout destination");  
  11.         }  
  12.   
  13.         for (LogoutHandler handler : handlers) {  
  14.             handler.logout(request, response, auth);  
  15.         }  
  16.   
  17.         logoutSuccessHandler.onLogoutSuccess(request, response, auth);  
  18.   
  19.         return;  
  20.     }  
  21.   
  22.     chain.doFilter(request, response);  
  23. }  
  24.   
  25. /** 
  26.  * Allow subclasses to modify when a logout should take place. 
  27.  * 
  28.  * @param request the request 
  29.  * @param response the response 
  30.  * 
  31.  * @return <code>true</code> if logout should occur, <code>false</code> otherwise 
  32.  */  
  33. protected boolean requiresLogout(HttpServletRequest request, HttpServletResponse response) {  
  34.     String uri = request.getRequestURI();  
  35.     int pathParamIndex = uri.indexOf(';');  
  36.   
  37.     if (pathParamIndex > 0) {  
  38.         // strip everything from the first semi-colon  
  39.         uri = uri.substring(0, pathParamIndex);  
  40.     }  
  41.   
  42.     int queryParamIndex = uri.indexOf('?');  
  43.   
  44.     if (queryParamIndex > 0) {  
  45.         // strip everything from the first question mark  
  46.         uri = uri.substring(0, queryParamIndex);  
  47.     }  
  48.   
  49.     [color=red]if ("".equals(request.getContextPath())) {  
  50.         return uri.endsWith(filterProcessesUrl);  
  51.     }[/color]  
  52.   
  53.     return [color=red]uri.endsWith(request.getContextPath() + filterProcessesUrl)[/color];  
  54. }  

    requiresLogout方法是判断url是否为 logout_url 的,居然用了 endsWith,我进行了测试,只要地址后缀为 j_spring_security_logout 的 都能退出系统。 
    而且 if ("".equals(request.getContextPath())) { 
            return uri.endsWith(filterProcessesUrl); 
        }
这段代码貌似没用, 直接用下面那个就能比较出来。 
    大家有什么看法? 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics