Spring security 源码分析系列(一)

扫码关注公众号:Java 技术驿站

发送:vip
将链接复制到本浏览器,永久解锁本站全部文章

【公众号:Java 技术驿站】 【加作者微信交流技术,拉技术群】
免费领取 2000+ 道 Java 面试题
  1. org.springframework.web.filter.DelegatingFilterProxy(在web.xml中属于占位作用)初始化 org.springframework.security.util.FilterChainProxy并获取DI容器 里的实例调用他的dofilter方法 FilterChainProxy包含 private ApplicationContext applicationContext; /** Map of the original pattern Strings to filter chains */ private Map uncompiledFilterChainMap; /** Compiled pattern version of the filter chain map */ private Map filterChainMap; private UrlMatcher matcher = new AntUrlPathMatcher(); private boolean stripQueryStringFromUrls = true; private DefaultFilterInvocationDefinitionSource fids; public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { //FilterInvocation 是 对应配置文件中url 和对应是否经过过滤器的对象 FilterInvocation fi = new FilterInvocation(request, response, chain); List filters = getFilters(fi.getRequestUrl()); //如果查出该url不需要经过过滤器就直接进入web.xml里的真实过滤器 从而next if (filters == null || filters.size() == 0) { if (logger.isDebugEnabled()) { logger.debug(fi.getRequestUrl() + filters == null ? ” has no matching filters” : ” has an empty filter list”); } chain.doFilter(request, response); return; } //创建一个虚拟的filter内部链 //否则根据fi得到该网页url需要经过那些过滤器来通过虚拟过滤连 VirtualFilterChain virtualFilterChain = new VirtualFilterChain(fi, filters); virtualFilterChain.doFilter(fi.getRequest(), fi.getResponse()); } VirtualFilterChain的dofilter方法 public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { if (currentPosition == additionalFilters.size()) { if (logger.isDebugEnabled()) { logger.debug(fi.getRequestUrl() + ” reached end of additional filter chain; proceeding with original chain”); } fi.getChain().doFilter(request, response); } else { currentPosition++; Filter nextFilter = (Filter) additionalFilters.get(currentPosition – 1); if (logger.isDebugEnabled()) { logger.debug(fi.getRequestUrl() + ” at position ” + currentPosition + ” of ” + additionalFilters.size() + ” in additional filter chain; firing Filter: ‘” + nextFilter + “‘”); } nextFilter.doFilter(request, response, this); } } 其中通过查看我自己的虚拟过滤链中的元素如下: [org.springframework.security.concurrent.ConcurrentSessionFilter[ order=100; ], org.springframework.security.context.HttpSessionContextIntegrationFilter[ order=200; ], org.springframework.security.ui.logout.LogoutFilter[ order=300; ], com.avi.springsecurityExtends.MyAuthenticationProcessingFilter[ order=700; ], org.springframework.security.ui.webapp.AuthenticationProcessingFilter[ order=700; ], org.springframework.security.ui.basicauth.BasicProcessingFilter[ order=1000; ], org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter[ order=1100; ], org.springframework.security.ui.rememberme.RememberMeProcessingFilter[ order=1200; ], org.springframework.security.providers.anonymous.AnonymousProcessingFilter[ order=1300; ], org.springframework.security.ui.ExceptionTranslationFilter[ order=1400; ], org.springframework.security.intercept.web.FilterSecurityInterceptor@1a29452]

来源:http://ddrv.cn/a/88268

赞(0) 打赏
版权归原创作者所有,任何形式的转载请联系博主:daming_90:Java 技术驿站 » Spring security 源码分析系列(一)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏