咱們在配置cas client確定寫過以下代碼:app
<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對應的類路徑改成自定義的過濾器類。jsp
CASFilter必須繼承AbstractCasFilter,覆蓋裏面除isRequestUrlExcluded外的全部方法,另重寫isRequestUrlExcluded方法。url
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的條件中便可。spa