Security 安全框架1
security
过滤器链
检查请求是否有请求信息-主要校验规则
UsernamePasswordAuthenticationFilter: 处理表单登录, 请求是否带用户名密码BasicAuthenticationFilter: 是否有Basic码信息, 有会进行解码认证
FilterSecurityInterceptor: 最后一部, 决定当前请求能不能继续, 根据不过的原因会抛出异常.ExceptionTranslationFilter: 在前FilterSecurityInterceptor有一个ExceptionTranslationFilter会处理FilterSecurityInterceptor抛出的异常, 引到用户根据前面过滤器的信息处理异常.- security通过过滤器链判断用户是否授权, 读取HttpSecurity配置, 判断请求中是否携带信息, 选择需要执行的过滤器, 最后由
ExceptionTranslationFilter统一进行权限认证, 如果未通过, 则会抛出异常, 由ExceptionTranslationFilter统一进行异常处理, 最后将异常信息返回给前台.
如果自定义Security过滤器 就是添加绿色的部分。
2. 认证流程
认证流程处理说明
UsernamePasswordAuthenticationFilter: 登陆请求未认证状态进入, 设置账户密码, 还未获取权限, 设置一些用户信息IP SESSIONAuthenticationManager: 负责收集所有AuthenticationProvider, 循环所有AuthenticationProvider获取是否支持, 挑出一个provider来获取用户认证AuthenticationProvider: 真正校验的逻辑UserDetailsService: 获取UserDetails获取权限信息返回给UsernamePasswordAuthenticationFilter, 成功SuccessHandler, 失败FailureHandlerUserDetails:Authentication已认证
认证结果如何在多个请求间共享
SecurityContext: 在认证成功之前方式上下文SecurityContextHolder: ThreadLocal(线程级环境变量)封装, 获取认证信息SecurityContextPersisitenceFilter: 在整个过滤器链的最前面, request进来检查Session中是否有SecurityContext如果有放到SecurityContextHolder没有空过, response回来检查SecurityContextHolder是否有SecurityContext, 如果有放置到Session中, 没有空过;
获取认证用户信息
- SecurityContextHolder.getContext().getAuthentication(): 静态方法获取
- Controller接口方法参数: Authentication authentication Spring mvc会自动注入
- @AuthenticationPrincipal UserDetails userDetails: 使用朱姐@AuthenticationPrincipal UserDetails 只注入用户信息
源码地址:https://github.com/Artister/tutorials-java/tree/master/security
Security 安全框架1的更多相关文章
- Spring Security安全框架
今天来简单介绍一下Spring Security安全框架 简介 Spring Security 提供了基于javaEE的企业应有个你软件全面的安全服务.这里特别强调支持使用SPring框架构件的项目, ...
- Spring Security安全框架入门篇
一.Spring Security相关概念 1.1..Spring Security介绍: Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安 ...
- Spring Security 安全框架
一 简介:Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架.它提供了一组可以在Spring应用上下文中配置的Bean,充分利用了Spr ...
- security安全框架,用户登录安全认证与退出
一.创建用户表及实体类 二.编写security配置文件 <?xml version="1.0" encoding="UTF-8"?><bea ...
- springboot集成spring security安全框架入门篇
一. :spring security的简介 Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架.它提供了一组可以在Spring应用上下 ...
- 001 Hello Security 的框架搭建
一:STS 1.下载STS 官网:http://spring.io/tools 使用一个干净的STS进行操作学习. 2.jdk检查 3.添加自己的maven 4.使用tomcat 二:新建项目 1.新 ...
- Spring boot 整合spring Data JPA+Spring Security+Thymeleaf框架(上)
近期上班太忙所以耽搁了给大家分享实战springboot 框架的使用. 以下是spring boot 整合多个框架的使用. 首先是准备工作要做好. 第一 导入框架所需的包,我们用的事maven 进行 ...
- security安全框架 配置
<?xml version="1.0" encoding="UTF-8"?><beans:beans xmlns="http://w ...
- SpringBoot+thymeleaf+security+vue搭建后台框架 基础篇(一)
刚刚接触SpringBoot,说说踩过的坑,主要的还是要记录下来,供以后反省反省! 今天主要讲讲 thymeleaf+security 的搭建,SpringBoot的项目搭建应该比较简单,这里就不多说 ...
随机推荐
- PG数据库空间大小及数据库对象占用空间大小
select pg_size_pretty(pg_database_size('lrisk')); --查询数据库剩余空间 select pg_database.datname,pg_size_pre ...
- String str = "1,2,3,4,5,6" 如何将这个字符串转换成int数组
String str = "1,2,3,4,5,6"; string[] strS = str.Split(','); int[] num = new int[strS.Lengt ...
- 设计模式(17) 访问者模式(VISITOR) C++实现
意图: 表示一个作用于某对象结构的各元素的操作.它使你可以再不改变各元素的类的前提下定义作用于这些元素的新操作. 动机: 之前在学校的最后一个小项目就是做一个编译器,当时使用的就是访问者模式. 在静态 ...
- Python初学者第十七天 函数(1)
17day 函数 1.函数定义: 函数 是指将一组语句的集合通过一个名字(函数名)封装起来,想要执行这个函数,只需调用其函数名即可 2.函数的特性: a 减少重复代码 b 使程序变得可扩展 c 使程序 ...
- Python学习---django重点之视图函数
django重点之视图函数 http请求中产生两个核心对象: http请求:HttpRequest对象,由Django自己创建 http响应:HttpResponse对象,由开发自己创建,必须返回一个 ...
- SpringMvc学习---基础知识考核
SpringMVC 1.SpringMVC的工作流程 流程 : 1.用户发送请求至前端控制器DispatcherServlet2.DispatcherServlet收到请求调用HandlerMappi ...
- 企业级Nginx基于虚拟主机别名的设置
生活中访问www.baidu.com和baidu.com是一个效果,同理也可以用rewrite 301跳转的思路(多发了一次请求过去)配置nginx.conf文件或者include里面的引用的文件,道 ...
- LVS跨网段DR模式并使用ldirectord实现RS高可用性
DR模型的工作过程: Client向VIP发起请求,请求被路由器接收到,转发给不同网段的Director的VIP,Director再通过私有网络转给RS服务器,RS服务器处理请求并通过自身配置的VIP ...
- lambdas vs. method groups
Update: Due to a glitch in my code I miscalculated the difference. It has been updated. See full his ...
- Using shared access signatures (SAS) From Microsoft
A shared access signature (SAS) provides you with a way to grant limited access to objects in your s ...