2019独角兽企业重金招聘Python工程师标准>>>

本文为转载学习

原文链接:http://blog.csdn.net/dsundsun/article/details/11750189

我们了解一下验证的过程:首先用户发起一个请求、 这时候,认证管理器进行拦截,验证用户发起请求时的一些凭证信息,未通过验证信息审核的那么返回给用户,通过审核的,那么继续进行请求访问,访问页面之前,会被访问决策管理拦截,访问决策管理器验证用户是否有访问页面的权限,如果有,那么继续到访问页面。

其实spring security这样的权限框架就是根据一系列的依赖代理(delegates)和servlet过滤器来实现的。看看如下这个图:

首先先通过过滤器拦截用户的请求,拦截后通过servlet来进行处理,如果处理成功那么进行正常访问,在返回给用户一个请求。

所以了解过滤器链的优先级是非常重要的。通过我查看spring security的帮助说明文档,我们可以看到过滤器链的顺序,如下:

1.ChannelProcessingFilter, because it might need to redirect to a different protocol

【ChannelProcessingFilter,使用它因为我们可能会指向不同的协议(如:Http,Https)】

2.SecurityContextPersistenceFilter,  so  a  SecurityContext  can  be  set  up  in  the SecurityContextHolder  at  the  beginning  of  a  web  request,  and  any  changes  to  the SecurityContext can be copied to the HttpSession when the web request ends (ready for use with the next web request)

【SecurityContextPersistenceFilter,负责从SecurityContextRepository 获取或存储 SecurityContext。SecurityContext 代表了用户安全和认证过的session】

3.ConcurrentSessionFilter, because it uses the SecurityContextHolder functionality and needs to update the SessionRegistry to reflect ongoing requests from the principal

【ConcurrentSessionFilter,使用SecurityContextHolder的功能,更新来自“安全对象”不间断的请求,进而更新SessionRegistry】

4.Authentication  processing  mechanisms  -  UsernamePasswordAuthenticationFilter, CasAuthenticationFilter,  BasicAuthenticationFilter  etc  -  so  that  the SecurityContextHolder can be modified to contain a valid Authentication request token

【认证进行机制,UsernamePasswordAuthenticationFilter,CasAuthenticationFilter,BasicAuthenticationFilter等等--SecurityContextHolder可能会修改含有Authentication这样认证信息的token值】

5.The SecurityContextHolderAwareRequestFilter,  if  you  are  using  it  to  install  a  Spring Security aware HttpServletRequestWrapper into your servlet container

【SecurityContextHolderAwareRequestFilter,如果你想用它的话,需要初始化spring security中的HttpServletRequestWrapper到你的servlet容器中】

6.The  JaasApiIntegrationFilter,  if  a  JaasAuthenticationToken  is  in  the SecurityContextHolder  this  will  process  the  FilterChain  as  the  Subject  in  the JaasAuthenticationToken

【JaasApiIntegrationFilter,如果JaasAuthenticationToken在SecurityContextHolder的上下文中,在过滤器链中JaasAuthenticationToken将作为一个对象。】

7.RememberMeAuthenticationFilter, so that if no earlier authentication processing mechanismupdated the SecurityContextHolder, and the request presents a cookie that enables remember-me services to take place, a suitable remembered Authentication object will be put there

【RememberMeAuthenticationFilter,如果还没有新的认证程序机制更新SecurityContextHolder,并且请求已经被一个“记住我”的服务替代,那么将会有一个Authentication对象将存放到这(就是 已经作为cookie请求的内容)。】

8.AnonymousAuthenticationFilter, so that if no earlier authentication processing mechanism updated the SecurityContextHolder, an anonymous Authentication object will be put there

【AnonymousAuthenticationFilter,如果没有任何认证程序机制更新SecurityContextHolder,一个匿名的对象将存放到这。】

9.ExceptionTranslationFilter, to catch any Spring Security exceptions so that either an HTTP error response can be returned or an appropriate AuthenticationEntryPoint can be launched

【ExceptionTranslationFilter,为了捕获spring security的错误,所以一个http响应将返回一个Exception或是触发AuthenticationEntryPoint。】
10.FilterSecurityInterceptor, to protect web URIs and raise exceptions when access is denied

【FilterSecurityInterceptor,当连接被拒绝时,保护web URLS并且抛出异常。】

还记得spring security的xml吗?里边的配置文件:

<http auto-config="true" ><intercept-url pattern= "/*" access="ROLE_USER" />
</http >

有一个属性叫做auto-config ,这个是一个自动配置过滤器(Filter)的属性 我们进入eclipse 然后光标指向它 点一下F2

我们可以看到这个属性的介绍,大概意思是:这是一个预留的属性,他可以自动配置login form,BSIC 认证和logout URL 和logout services,如果没有特殊表明,这个的默认值是false。我们推荐你避免使用这个属性,相反的,配置你需要的一些服务。。,,(spring security本来不希望我们使用这个属性,这个事我们都先记着)

那好,今天就到这里,我们了解了两个事情:
     第一个:整个spring security是有过滤器链和sevlet组成的,并且是按一定顺序执行的,而且查看相关spring security提供的说明,我们可以清楚的了解到这些过滤器大致都是做什么用的、
     第二个:上次我们跑起来的应用中,配置了auto-config="true"这个属性,它帮我们自动添加了一些过滤器,使项目跑起来很快,但是由于不太有针对性(这是我自己的猜测),spring security不建议我们使用它,spring security更希望我们能配置一些有针对性的服务。

转载于:https://my.oschina.net/heroShane/blog/196981

spring security3.x学习(3)_初探过滤器机制和auto-config用法相关推荐

  1. spring security3.x学习(15)_扩展JdbcDaoImpl。

    2019独角兽企业重金招聘Python工程师标准>>> 本文为转载学习 原文链接:http://blog.csdn.net/dsundsun/article/details/1184 ...

  2. spring security3.x学习(12)_remember me

    2019独角兽企业重金招聘Python工程师标准>>> 本文为转载学习 原文链接:http://blog.csdn.net/dsundsun/article/details/1182 ...

  3. Java学习笔记_身份验证机制

    身份验证机制(authentication):确定一个用户具有自己声称的那个身份 应用程序关心用户是否通过了验证而不关心是通过何种方式进行的验证??? 授权(访问控制:authorization):★ ...

  4. java中batch基础_详解Spring batch 入门学习教程(附源码)

    详解Spring batch 入门学习教程(附源码) 发布时间:2020-09-08 00:28:40 来源:脚本之家 阅读:99 作者:achuo Spring batch 是一个开源的批处理框架. ...

  5. spring security3(转)

    转:spring security3 初探  http://yzxqml.iteye.com/blog/1756106 现在很多企业和开发团队都使用了SSH2(Struts 2 +Spring 2.5 ...

  6. 关于对《Spring Security3》翻译 (第一章 - 第三章)

    原文:http://lengyun3566.iteye.com/category/153689?page=2 翻译说明 最近阅读了<Spring Security3>一书,颇有收获(封面见 ...

  7. 使用Spring Security3的四种方法概述

    使用Spring Security3的四种方法概述 那么在Spring Security3的使用中,有4种方法: 一种是全部利用配置文件,将用户.权限.资源(url)硬编码在xml文件中,已经实现过, ...

  8. Spring Boot 2 学习笔记(2 / 2)

    Spring Boot 2 学习笔记(1 / 2) - - - 45.web实验-抽取公共页面 46.web实验-遍历数据与页面bug修改 47.视图解析-[源码分析]-视图解析器与视图 48.拦截器 ...

  9. 春天的故事-Spring Security3十五日研究

    sparta-紫杉   2011-4-2 22:00 前言 南朝<述异记>中记载,晋王质上山砍柴,见二童子下棋,未看完,斧柄已烂,下山回村,闻同代人都去世了,自已还未变老.     因此发 ...

  10. Unity学习日志_车轮碰撞器简介

    Unity学习日志_车轮碰撞器简介 1. 简介: 车轮碰撞器是一种针对地面车辆的特殊碰撞体.他有内置的碰撞检测.车轮物理系统和有滑胎摩擦的参考体.除了车轮,该碰撞体也可以用于其他游戏对象. 属性: M ...

最新文章

  1. 在Java中定义常量
  2. 雅思听力的词语练习打字!!!
  3. Xilinx Vivado的使用详细介绍(1):创建工程、编写代码、行为仿真、Testbench
  4. 安装成功后python报错_python安装Graphviz后报错及解决方法
  5. python3.4和3.6的区别_详解Python3.6正式版新特性
  6. 【英语学习】【Daily English】U08 Dating L01 She is the one for me.
  7. 蓝桥杯 ADV-68算法提高 企业奖金发放
  8. db9针232接口波特率标准_DB9 公头母头引脚定义及连接
  9. 固态硬盘故障检测_diskgenius检测固态硬盘(ssd固态硬盘坏道修复)
  10. 大数据开发之CDH篇----cloudera-scm-agent启动不了后的一堆事
  11. python写梦幻西游脚本精灵_奔三新人学习按键精灵脚本做冷门项目
  12. 【技术博客】当蒸馏遇上GAN
  13. mysql大于等于between比较_MySQL范围查询优化,Between与大于等于对比及优化
  14. 服务器 sn 作用,命令查看服务器SN号
  15. iOS开发之3DTouch集成
  16. window.open打开子窗口回调父窗口函数
  17. 【设计教程】在PS里面制作简单的下雨效果!
  18. Zabbix Server trapper 命令注入漏洞 (CVE-2017-2824)
  19. 2021年前的最后一篇文章,分享一下前端这几年的感受和心得,总结过去展望未来
  20. 微信 8.0 「裂开」「炸弹」的特效代码来了

热门文章

  1. 为vs2008添加Mobile Web Forms模板
  2. Sugar Bytes WOW2 for Mac - 多功能滤波效果器
  3. 泰拉瑞亚Terraria for Mac(动作冒险游戏)
  4. 【Flutter】微信项目实战【02】我的界面搭建(上)
  5. Fl Studio真的不如Cubase或者Logic Pro等电音软件专业吗?
  6. linux网络测试(必会)
  7. Material Design使用集合
  8. ****** 三十 ******、软设笔记【计算机体系结构】-循环冗余校验码(CRC)
  9. Android开发技巧:给Button的点击上色
  10. CKEditor4.7怎样实现上传图片,浏览服务器(无需ckfinder),nodejs图片管理,字体居中,图片居中(超详细)...