当前位置:网站首页>Design and practice of unified security authentication for microservice architecture
Design and practice of unified security authentication for microservice architecture
2022-07-28 03:03:00 【Java misty rain】
When the enterprise application system gradually increases , Each system manages its own user data separately, which is easy to form an information island , Decentralized user management mode hinders the evolution of enterprise application to platform . When the enterprise's Internet business develops to a certain scale , It is necessary to build a unified and standardized account management system , Because it is an important infrastructure of enterprise Internet cloud platform , It can bring unified account management to the platform 、 Identity Authentication 、 Basic capabilities such as user authorization , To bring enterprises such as cross system single sign on 、 Third party authorized login and other basic capabilities , It provides necessary conditions for the construction of open platform and business ecology .
— 1 —
Definition of noun
Third-party application: Third party applications , Also known as “ client ”(client).
HTTP service:HTTP Service provider , Abbreviation in this paper “ Service provider ”.
Resource Owner: Resource owner , Also known as “ user ”(user), The login user .
User Agent: The user agent , Browser in this article .
Authorization server: Authentication server , That is, the server used by the service provider to handle authentication .
Resource server: Resource server , The server where the service provider stores the user generated resources . It and authentication server , Can be the same server , It can also be a different server .
— 2 —
R & D background
Under the monomer application system , The application is a whole , Generally, all requests will be checked for their permissions . Requests are generally checked by a permission interceptor , Cache user information to session in , Subsequent access gets user information from the cache .
With Restful API、 The rise of micro Services , be based on Token Authentication for is now becoming more and more common .Token and Session ID Different , It's not just a key.Token It usually contains information about the user , Pass the verification Token You can check your identity .
be based on Token The advantages of certification are as follows :
Server stateless :Token The mechanism does not need storage on the server session Information , because Token It contains the relevant information of all users .
Good performance , Because it's verifying Token You don't need to access the database or remote services to verify the permissions , Nature can improve a lot of performance .
Support for mobile devices , Support cross program calls ,Cookie Is not allowed to cross domain access , and Token There is no such problem .
— 3 —
R & D objectives
Through the standard security certification process , Heterogeneous systems or cross services can flexibly integrate specified features or services 、 Unified security authentication .
be based on Token A typical process of authentication is as follows :
The user enters the login information ( Or call Token Interface , Pass in user information ), Send to the authentication service for authentication ( The identity authentication service can be together with the server , You can also separate , Let's look at the splitting of micro services ).
The authentication service verifies that the login information is correct , Return Interface ( General interface will contain user basic information 、 Scope of authority 、 Effective time and other information ), Client storage interface , Can be stored in Session Or in the database .
The client will Token Put it in HTTP Request header , Launch related API call .
Called microservices , verification Token jurisdiction .
The server returns relevant resources and data .
Security authentication function point :

Get credentials , Third party application clients use client code / Safety code 、 Resource owner user name / The password and other certificate information are obtained from the authorization server Access Token Resource access credentials .
Login authorization , The client carries Access Token Credentials access server resources , Resource server validation Token、 Third party application credential information 、 Resource owner User Legitimacy , adopt Token Read resource owner identity information (user) Load the permission entry of the resource owner to perform login .
Access authentication , Third party application client access server resources , The system validates visitors Access Token Legitimacy 、 Permission information , Verification certificate (Access Token) correct , At this point, the resource server will return the resource information .
Certificate renewal ,Access token Access certificate expiration requires certificate renewal , Refresh Token Validity of voucher .
— 4 —
Technology selection analysis
The system is authorized to use OAuth2 Open authorization standard password mode .
Token use JWT standard .
OAuth Open licensing
OAuth(Open Authorization, Open licensing ) It defines a security for the authorization of user resources 、 Open and simple standards , The third party does not need to know the user's account number and password , The user's authorization information can be obtained .
There are four main authorization methods :
Authorization code mode (authorization code) Authorization code used between client and server application .
Simplified mode (implicit) For mobile app perhaps web app( these app It's on the user's device , For example, call up wechat on the mobile phone for authentication and authorization ). Servers that do not pass through third-party applications , Request token directly from authentication server in browser , Skip the “ Authorization code ” This step , Hence the name . All steps in browser , The token is visible to the visitor , And the client does not need authentication .
Password mode (resource owner password credentials) Applications are directly trusted ( It's all developed by one company ) In password mode , Users provide their own user name and password to the client . Clients use this information , towards “ Service provider ” Asking for authorization . In this mode , The user must give his password to the client , But the client must not store the password .
Client mode (client credentials) Used in applications API Access client mode (Client Credentials Grant) Client in its own name , Not in the name of the user , towards “ Service provider ” authentication . Strictly speaking , Client mode does not belong to OAuth Problems to be solved by the framework . In this mode , Users register directly with clients , Client requests in its own name “ Service provider ” Provide services , In fact, there is no authorization problem .
Json Web Token(JWT)
Json Web Token(JWT), Is a kind of implementation based on the JSON Open standards for (RFC 7519). The Token Designed to be compact and safe , Especially for single sign in of distributed sites (SSO) scene .JWT The declaration of is generally used to pass the authenticated user identity information between the identity provider and the service provider , To get resources from the resource server , You can also add some additional declaration information that other business logic requires , The Token It can also be used directly for authentication , It can also be encrypted .
— 5 —
Authentication process logic
System authorization
Third party application clients use client code / Safety code 、 Resource owner user name / The password and other certificate information are obtained from the authorization server Access Token Resource access credentials .

System authorization is issued to customer applications Access Token.

System authentication
The client carries Access Token Credentials access server resources , Resource server validation Token、 Third-party applications 、 Resource owner User Legitimacy , adopt Token Read resource owner identity information (user) Load the permissions of the resource owner, perform login .
![]()
The system validates visitors Access Token Legitimacy 、 Permission information , Verification certificate (Access Token) correct , At this point, the resource server will return the resource information .
Certificate renewal
Access Token Access certificate expiration requires certificate renewal , Refresh Token Validity of voucher .

— 6 —
Interface design
Authorization certificate
Get authorization certificate , Verify client identity information 、 Verify the identity of the resource owner , Send out Token voucher .

Client code / The security code needs to be applied to the system by a third party and generated after it is registered and approved .


Renewal of authorization certificate
Obtain renewal authorization certificate , Verify client identity information 、 check RefreshToken voucher , Send out Token voucher .



边栏推荐
- 每日刷题巩固知识
- Newline required at end of file but not found.
- Job 7.27 IO process
- clientY vs pageY
- Using pytorch's tensorboard visual deep learning indicators | pytorch series (25)
- trivy【1】工具扫描运用
- Deep residual learning for image recognition shallow reading and Implementation
- Vscode debug displays multiple columns of data
- CSDN Top1 "how does a Virgo procedural ape" become a blogger with millions of fans through writing?
- Oracle basicfile lob field space recycling shrink space doubts
猜你喜欢

Redis aof日志持久化
![[stream] parallel stream and sequential stream](/img/e1/b8728962c14df56241aa6973c0c706.png)
[stream] parallel stream and sequential stream

CNN中的混淆矩阵 | PyTorch系列(二十三)

每日刷题巩固知识

GAMES101复习:光线追踪(Ray Tracing)

Flutter神操作学习之(满级攻略)

TFX airflow experience
![[image defogging] image defogging based on dark channel and non-mean filtering with matlab code](/img/39/6266eb14deac9f38b7e95f7291067e.png)
[image defogging] image defogging based on dark channel and non-mean filtering with matlab code

“29岁,普通功能测试,我是如何在一周内拿到5份Offer的?”

Record of a cross domain problem
随机推荐
入职华为od一个月的感受
超参数调整和实验-训练深度神经网络 | PyTorch系列(二十六)
CSDN Top1 "how does a Virgo procedural ape" become a blogger with millions of fans through writing?
从硬件编程到软件平台的ci/cd
Digital twin agriculture - Smart agriculture rice processing plant has changed from "watching the sky to eat" to "knowing the sky to work"
Pychart shortcut key for quickly modifying all the same names on the whole page
[brother hero's July training] day 26: check the collection
Explanation of CNN circular training | pytorch series (XXII)
[email protected]注解使用
Eigenvalues and eigenvectors
clientY vs pageY
[brother hero's July training] day 27: picture
每日刷题巩固知识
JS event object 2 e.charcode character code e.keycode key code box moves up, down, left and right
Consolidate the data foundation in the data center
数据中台夯实数据基础
JS 事件对象2 e.charcode字符码 e.keyCode键码 盒子上下左右移动
Data center construction (III): introduction to data center architecture
Center-based 3D Object Detection and Tracking(基于中心的3D目标检测和跟踪 / CenterPoint)论文笔记
JVM 内存布局详解,图文并茂,写得太好了!