CAS實戰のclient自定義過濾器


  我們在配置cas client肯定寫過如下代碼:

 <filter>  
        <filter-name>CASFilter</filter-name>  
        <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>
        <filter-class>com.founder.ec.sso.filter.CASFilter</filter-class>
        <init-param>  
            <param-name>casServerLoginUrl</param-name>  
            <param-value>http://localhost:8082/cas/login</param-value>
        </init-param>  
        <init-param>  
            <param-name>serverName</param-name>  
            <param-value>http://localhost:8008/</param-value>
        </init-param>  
    </filter>  
    <filter-mapping>  
        <filter-name>CASFilter</filter-name>  
        <url-pattern>/*</url-pattern>  
    </filter-mapping>

  在自定義過濾器的時候,只需要將默認的CASFilter對應的類路徑改為自定義的過濾器類。

  CASFilter必須繼承AbstractCasFilter,覆蓋里面除isRequestUrlExcluded外的所有方法,另重寫isRequestUrlExcluded方法。

 private boolean isRequestUrlExcluded(final HttpServletRequest request,final HttpServletResponse response) {
        boolean flag = false;
        String pathInfo = "";
        String servletPath = request.getServletPath();
        if (request.getPathInfo()!=null) pathInfo = request.getPathInfo();
        if (
                servletPath.equals("/testSend.jsp") ||
                pathInfo.equals("/ds/getDataXMLInStr") ||
                
           ){
            flag = true;
        }else if(servletPath.indexOf("login.jsp")>-1){
            flag = false;
      }
        return flag;
    }

  將需要放行的請求置為flag為true的條件中即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM