filter实例

Posted arctic_fox

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了filter实例相关的知识,希望对你有一定的参考价值。

 

 

最近在学习filter,看完理论知识之后,就特地在实际工作中的系统中去验证。

SSP系统实例如下:

1.在web.xml中寻找 filter的配置信息

  如下:

 <filter>
  <filter-name>passoFilter</filter-name>
  <filter-class>com.pingan.passo.wls.client.filter.SSOClientFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>passoFilter</filter-name>
  <url-pattern>/login</url-pattern>
 </filter-mapping>
 <filter>
  <filter-name>CookieFilter</filter-name>
  <filter-class>com.paic.phssp.common.filter.CookieFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>CookieFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <filter> 
     <filter-name>SecurityAclFilter</filter-name> 
     <filter-class>com.paic.phssp.common.filter.SecurityAclFilter</filter-class> 
 </filter>
 <filter-mapping>
  <filter-name>SecurityAclFilter</filter-name>
  <url-pattern>*.do</url-pattern>
 </filter-mapping>
 <filter-mapping>
  <filter-name>SecurityAclFilter</filter-name>
  <url-pattern>*.screen</url-pattern>
 </filter-mapping>
 <filter> 
     <filter-name>AppScanFilter</filter-name> 
     <filter-class>com.paic.phssp.common.filter.AppScanFilter</filter-class>
     <init-param>
            <param-name>excludedPages</param-name>
            <param-value>/phssp/document.create.check.prop.do,/phssp/document.create.content.do,/phssp/document.create.new.do,/phssp/document.create.update.do,/phssp/document.editPreView.do,/phssp/newDocument.detialPreView.do,/phssp/document.detialPreView.do,/phssp/document.downLoadPdf.do,/phssp/document.detialPreWordView.do,/appsvr/phssp/redis/test</param-value><!-- 匹配不做拦截的请求声明-->
        </init-param>
 </filter>
 <filter-mapping>
  <filter-name>AppScanFilter</filter-name>
  <url-pattern>*.do</url-pattern>
 </filter-mapping>
 <filter-mapping>
  <filter-name>AppScanFilter</filter-name>
  <url-pattern>*.screen</url-pattern>
 </filter-mapping>
 <filter>
     <filter-name>UMSecurityFilter</filter-name>
     <filter-class>
         com.pingan.security.client.filter.UMSecurityFilter
     </filter-class>
     <init-param>
         <param-name>SecurityPropertiesName</param-name>
         <param-value>um-security.properties</param-value>
     </init-param>
     <init-param>
         <description>不希望被拦截的页面, 默认不拦截js css 图片</description>
         <param-name>publicPages</param-name>
         <param-value>/login;/login.jsp;/ssologin.jsp;/logout.jsp;/ssp/privilege/ISendUserPrivilege.do;/appsvr/phssp/doc/generate.do;/appsvr/phssp/redis/test;/phssp/newDocument.detialPreView.do;/phssp/pdfsign.manage.getBasemessage.do;/phssp/pdfsign.manage.getBasemessage.do</param-value>
     </init-param>
     <init-param>
         <param-name>UserRoleService</param-name>
         <param-value>
             com.pingan.security.client.policy.acl.service.UM2UserRoleService
         </param-value>
     </init-param>
 </filter>
 <filter-mapping>
     <filter-name>UMSecurityFilter</filter-name>
     <url-pattern>*</url-pattern>
     <dispatcher>REQUEST</dispatcher>
     <dispatcher>FORWARD</dispatcher>
 </filter-mapping> 
 
 <filter>
  <filter-name>Set Character Encoding</filter-name>
  <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  <init-param>
   <param-name>encoding</param-name>
   <param-value>UTF-8</param-value>
  </init-param>
 </filter>
 <filter-mapping>
  <filter-name>Set Character Encoding</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 
     <filter>
  <filter-name>RefererFilter</filter-name>
  <filter-class>com.paic.phssp.common.filter.RefererFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>RefererFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

其中有四个是在代码中有实现的,其他 都是引用第三方jar包的。

 

 

下面我们就来看看这四个实现的filter

 

AppScanFilter.java

 

以上是关于filter实例的主要内容,如果未能解决你的问题,请参考以下文章

Filter的执行顺序与实例

filter的知识点 和 实例

iptables filter表实例

php实现验证邮箱格式的代码实例

HBase(0.96以上版本)过滤器Filter详解及实例代码

python map() filter() reduce()函数的用法以及实例