In distributed environment, how to support multi-terminal session sharing such as PC and APP (ios and Android) is also a solution that all companies need. I think it is out of date to solve the problem by using the traditional session method. Can we find a general solution? For example, using traditional CAS for SSO sso between multiple systems or using oAUth’s third-party login scheme? Today, we will briefly explain the use of Spring Interceptor mechanism, JWT authentication mode, Redis distributed cache sso sso, without further talk, directly record the steps to share with you: distributed architecture

1. Introduce related JAR packages of JWT into project POM.xml:




2. Interceptor configuration:




I have simply configured the URLS to be blocked and the urls to be filtered (this depends on your own project).

3. Write JWT encryption or decryption tool classes:




This encryption tool class is I found from the Internet, if you want to modify, you can modify according to their own business.

Create login. Java object for JWT encryption or decryption:







5. Define the RedisLogin object, which is used to store the user object to Redis by uid:







6. Write the LoginInterceptor. Java interceptor







7. Define the exception LoginResponseCode




8. Write unified SSO single sign-on interface:




9. Test SSO sso:




Return result set:




Willing to understand the framework technology or source code of friends directly ask to exchange technology: 2042849237

Some distributed solutions, friends who are willing to understand can find our team to discuss