当前位置:网站首页>每日一博 - 微服务权限一二事
每日一博 - 微服务权限一二事
2022-06-11 15:33:00 【小小工匠】

概念普及
关于权限, 先了解几个核心的概念
- 认证
- 授权
- 鉴权
认证
举个例子: 输入用户名/密码,点击登录后,后台执行的业务逻辑就是认证 ---------->验证用户名/密码是否正确,能否登录系统 , 这就是认证
授权
举个例子: 不同的用户拥有不同的权限是通过系统授权来实现的,授权就是授予相关用户或角色资源操作的权限, 当然了也有很多第三方系统的授权.
鉴权
举个例子; 同样的系统,不同的人登录成功后,拥有的权限是不一样的,当用户进行操作时,后台会验证是否能够进行相应的操作,这就是鉴权,即校验用户是否有相应资源的操作权限。

单体应用下的 认证、授权、鉴权
我们知道了: 权限问题的核心就是解决认证、鉴权和授权问题。
我们先看看在单体应用中是如何处理上述问题的 。
认证的处理方式
单体应用中,对于用户登录,会先校验用户的用户名/密码,通常都涉及到密码的加密处理,一般的判断是加密后相应的密码是否与数据库中存储的密码相等,如果相等的话,则登录成功。
用户登录成功的话,一般会返回用户登录成功相关凭证。
- 如果是JWT的话,则会返回Token
- 如果采用的是会话的话,则会通过Set-Cookie返回SessionId给客户端
授权的处理方式
在单体应用中,授权即修改用户相关角色信息,或者修改角色相关权限信息。一般在用户重新登录后,最新的权限信息生效。
鉴权的处理方式
单体应用一般会通过拦截器(Spring Security、Apache Shrio本质上都是拦截器),拦截用户请求.
这里同样会根据鉴权方案是JWT还是HTTP会话分别处理
- 如果是JWT的话,则会通过解密来获得用户信息
- 如果是采用的会话的方式,则会根据会话ID,从存储中(这里一般是Redis)来获得用户信息.
不论是哪种方案,最终都是根据用户信息来对相应的请求进行权限校验。
鉴权一般有两种方式,但都是基于角色的。
一种是基于角色的隐式鉴权,即根据角色直接判断是否拥有相应资源的操作权限,比如角色是管理员,就可以删除用户,角色是普通用户,只能查看用户信息。
这种一般在简单的系统中比较适用,常用的方式是通过注解,表明哪个接口可以给哪个角色访问。但这种方式在复杂的系统中就会变得难以维护。另一种是基于角色的精准鉴权,此种鉴权方案,一般会给角色分配明确的权限,相应的鉴权方式为根据用户角色查出具体的权限集合,然后进行进一步判断。此种方式在复杂系统中更加有效方便。

微服务架构下的 认证、授权、鉴权
在微服务中,权限处理的认证、授权功能实现,跟单体应用没什么区别。
边栏推荐
- C语言简易版webserver
- [mysql_11] addition, deletion and modification of data processing
- A former employee of Baidu was awarded 1.07 million yuan for job hopping; Apple, Google and Microsoft plan to "kill" the password; It is said that Geely has acquired Meizu | Q information
- The reason why it is easy to let the single chip computer program fly
- 数据库优化
- Hot seek tiger, a list of eco economic models
- 【创建型模式】单例模式
- Tencent interviewers share their interview experience, how to evaluate the interviewers' technical and personal comprehensive quality, and give you some suggestions on the interview
- uniapp开发微信小程序,从构建到上线
- leetcode 120. 三角形最小路径和
猜你喜欢
随机推荐
[azure application service] nodejs express + msal realizes the authentication experiment of API Application token authentication (AAD oauth2 idtoken) -- passport authenticate()
Lick the dog till the last one has nothing (linear DP)
19. 二叉搜索樹的插入删除修剪
Shuttle -- hero component
B站高管解读财报:疫情对公司长期发展无影响 视频化趋势不可阻挡
C语言简易版webserver
03 _ 事务隔离:为什么你改了我还看不见?
我的代码变量名称统一 记录
Implementation of the function of recording login status
[creation mode] builder mode
MySQL用户权限总结【用户授权必会】
Backtracking / solution space tree permutation tree
回溯法/活动安排 最大兼容活动
Installation and use of sonarqube
Why can redis be so fast?
Safepoint explanation and analysis of its placement ideas
Flower shop window (linear DP)
老虎国际季报图解:营收5263万美元 持续国际化布局
Tencent interviewers share their interview experience, how to evaluate the interviewers' technical and personal comprehensive quality, and give you some suggestions on the interview
In the "ten billion blue ocean" database, each player can find a boat | c-position face-to-face


![[multi thread performance tuning] what operations cause context switching?](/img/a6/5d82c81dba546092447debebf7fc3e.jpg)






