当前位置:网站首页>每日一博 - 微服务权限一二事
每日一博 - 微服务权限一二事
2022-06-12 18:27:00 【小小工匠】
文章目录
概念普及
关于权限, 先了解几个核心的概念
- 认证
- 授权
- 鉴权
认证
举个例子: 输入用户名/密码,点击登录后,后台执行的业务逻辑就是认证 ---------->验证用户名/密码是否正确,能否登录系统 , 这就是认证
授权
举个例子: 不同的用户拥有不同的权限是通过系统授权来实现的,授权就是授予相关用户或角色资源操作的权限, 当然了也有很多第三方系统的授权.
鉴权
举个例子; 同样的系统,不同的人登录成功后,拥有的权限是不一样的,当用户进行操作时,后台会验证是否能够进行相应的操作,这就是鉴权,即校验用户是否有相应资源的操作权限。
单体应用下的 认证、授权、鉴权
我们知道了: 权限问题的核心就是解决认证、鉴权和授权问题。
我们先看看在单体应用中是如何处理上述问题的 。
认证的处理方式
单体应用中,对于用户登录,会先校验用户的用户名/密码,通常都涉及到密码的加密处理,一般的判断是加密后相应的密码是否与数据库中存储的密码相等,如果相等的话,则登录成功。
用户登录成功的话,一般会返回用户登录成功相关凭证。
- 如果是JWT的话,则会返回Token
- 如果采用的是会话的话,则会通过Set-Cookie返回SessionId给客户端
授权的处理方式
在单体应用中,授权即修改用户相关角色信息,或者修改角色相关权限信息。一般在用户重新登录后,最新的权限信息生效。
鉴权的处理方式
单体应用一般会通过拦截器(Spring Security、Apache Shrio本质上都是拦截器),拦截用户请求.
这里同样会根据鉴权方案是JWT还是HTTP会话分别处理
- 如果是JWT的话,则会通过解密来获得用户信息
- 如果是采用的会话的方式,则会根据会话ID,从存储中(这里一般是Redis)来获得用户信息.
不论是哪种方案,最终都是根据用户信息来对相应的请求进行权限校验。
鉴权一般有两种方式,但都是基于角色的。
- 一种是基于角色的隐式鉴权,即根据角色直接判断是否拥有相应资源的操作权限,比如角色是管理员,就可以删除用户,角色是普通用户,只能查看用户信息。 这种一般在简单的系统中比较适用,常用的方式是通过注解,表明哪个接口可以给哪个角色访问。但这种方式在复杂的系统中就会变得难以维护。
- 另一种是基于角色的精准鉴权,此种鉴权方案,一般会给角色分配明确的权限,相应的鉴权方式为根据用户角色查出具体的权限集合,然后进行进一步判断。此种方式在复杂系统中更加有效方便。
微服务架构下的 认证、授权、鉴权
在微服务中,权限处理的认证、授权功能实现,跟单体应用没什么区别。
边栏推荐
- TypeScript类型声明文件(三)
- MySQL advanced learning notes
- When openharmony meets openeuler
- GD32F4xx控制DGUS触控按键
- Window版本pytorch入门深度学习环境安装与配置
- Machine learning series (5): Naive Bayes
- Lenovo responded that there are too many and too messy notebooks: it is now the product adjustment period and will be divided into three series of digital /air/ pro in the future
- ES7 does not use parent-child and nested relationships to implement one to many functions
- Adjust CEPH cluster image source
- Leetcode topic [string] -151- flip words in string
猜你喜欢

Installation and configuration of window version pytorch entry depth learning environment

To understand Devops, you must read these ten books!

有源差分晶振原理圖以及LV-PECL、LVDS、HCSL區別

C语言练习(4)——大数乘除

Solution to the problem that the anaconda navigator card logo cannot be opened and the card will flash back - replace the alicloud image source

Review of MySQL (IX): index

Pytest automated testing framework (II)

Gospel of audio and video developers, rapid integration of AI dubbing capability

VirtualLab basic experiment tutorial -4 Single slit diffraction

Quickly copy the request in browser F12 to postman/ or generate the corresponding code of the relevant language
随机推荐
The difference between user status and system status in CRM
Leetcode 718 longest common substring
Partial scratch and corrosion detection of bolts and screws based on Halcon
js求斐波那契数列
Title 66: input 3 numbers a, B, C, and output them in order of size.
2022.6.12-----leetcode.890
TypeScript常用类型(一)
TypeScript高级类型(二)
在思科模擬器Cisco Packet Tracer實現自反ACL
TypeScript类型声明文件(三)
CEPH deploy offline deployment of CEPH cluster and error reporting FAQ
Gd32f4xx controls dgus touch keys
Review of MySQL (VI): usage of Union and limit
HTTP缓存<强缓存与协商缓存>
Gospel of audio and video developers, rapid integration of AI dubbing capability
Why my order by create_ Time ASC becomes order by ASC
JS中的数组(含leetcode例题)<持续更新~>
Gossip about the 88 of redis source code
JS中的字符串(含leetcode例题)<持续更新~>
Regression analysis based on elasticnetcv