In a distributed environment, how to support the PC, APP (iOS, Android) and other multi-terminal session sharing, which is the solution that all companies need, with the traditional session way to solve, I think it is out, we can find a common solution, For example, using traditional CAs to achieve SSO single sign-on between multiple systems or using OAuth for third-party login scenarios? Let's talk about it today. Using Spring Interceptor Interceptor mechanism, JWT authentication method, Redis distributed cache implementation SSO Single Sign-on, gossip less, directly to the steps recorded to share to everyone: distributed architecture
1. Introduction of the relevant jar package for JWT, introduced in Project Pom.xml:
650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-f0234f4d36258d9b.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>
2. Interceptor Configuration:
650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-bf6a3b13b4532349.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>
I've simply configured the URL to intercept and the URL to filter (this depends on your project)
3. Write a JWT encryption or decryption tool class:
650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-d87bf17a9e1cb63d.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>
This encryption tool class is I find from the Internet, if you want to modify, you can follow your own business changes.
4. Create a Login.java object that is used to encrypt or decrypt JWT:
650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-9afde7c6681e4b6d.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>
650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-7819e4c34a2ee2f1.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>
5. Define the Redislogin object that is used to store the user object through the UID to Redis:
650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-a1ab77ecc0d61caa.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>
650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-0eda71eba8ddb107.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>
6. Writing Logininterceptor.java Interceptors
650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-8373c2d2a2ce74eb.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>
650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-d8476325ad18274c.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>
7. Define the Loginresponsecode of the exception
650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-734bcb227979fd3a.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>
8. Write the Unified SSO single Sign-on interface:
650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-8fac33f6fbb34fc6.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>
9. Test SSO Single Sign-on:
650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-b09d0f196964ade4.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>
return result set:
650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-dc5525098b87e708.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>
Willing to understand the framework of technology or source of friends directly to seek exchange and sharing technology: 04 II 849 II three QI
Some of the distributed solutions, the friends who are willing to know can find our team to discuss
More detailed source code references
Spring+springmvc+interceptor+jwt+redis implementing SSO Single Sign-on