自定义 shiro过滤器(平安pafa5框架)

本文介绍了如何自定义一个名为PafaDelegatingFilter的过滤器,该过滤器继承自AbstractWebFilter并实现了EnvironmentAware、ServletContextAware和ApplicationContextAware接口。这个过滤器适用于PingAn的Pafa5框架,它模拟了Spring的DelegatingFilterProxy功能,允许将过滤器链的处理交给目标过滤器。配置包括在pafa_sar_spring.xml中引入过滤器,设置targetBeanName属性指向目标过滤器,并设置targetFilterLifecycle为true,以便Spring管理目标过滤器的生命周期。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



import java.io.IOException;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.commons.logging.Log;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyAccessorFactory;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.PropertyValues;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceEditor;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.context.ServletContextAware;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.ServletContextResourceLoader;
import org.springframework.web.context.support.StandardServletEnvironment;
import org.springframework.web.util.NestedServletException;

import com.pingan.pafa.papp.web.filter.AbstractWebFilter;
import com.pingan.pafa.papp.web.filter.DefFilterConfig;

/**
 * 自定义Spring DelegatingFilterProxy, 适应pafa框架, 实现DelegatingFilterProxy功能
 *
 * 配置步骤:  1.在pafa_sar_spring.xml引入当前自定义过滤器
 *    2.注入targetBeanName属性, 指向目标过滤器, 将当前过滤器链跳转交给目标过滤器进行处理
 *    3.注入targetFilterLifecycle属性为true, 将目标过滤器生命周期交给spring管理
 */
public class PafaDelegatingFilter extends AbstractWebFilter implements
 EnvironmentAware, ServletContextAware, ApplicationContextAware {
 
 protected final Log logger = org.apache.commons.logging.LogFactory.getLog(getClass());

 private final Set<String> requiredProperties = new HashSet<String>();

 private FilterConfig filterConfig = new DefFilterConfig(this.getBeanName(),null,this.getServletContext());

 private String beanName;

 private Environment environment = new StandardServletEnvironment();

 private ServletContext servletContext;
 
 private String contextAttribute;

 private ApplicationContext applicationContext;

 private String targetBeanName;

 private boolean targetFilterLifecycle = false;

 private volatile Filter delegate;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值