Using Spring Cloud Zuul and Spring Security as the Dependency, the authentication system implemented by JWT, which supports role based authentication .
the er pic is simple :
-
start eureka , api-company , api-personal , gateway , token-manager
-
open eureka , you can find our server is registed , like this :
-
while the server under runing , we can start using , and first of all , we need get our token for users.
We assume that personal user is logged in with a mobile phone number, and an company user is using an email to log in.
-
now , let's see how to use the token for different roles .
First of all , we need to set "Authorization" in Headers , which value should be like Bearer + " " + ${token} , for example :
next , we can use the token to do something meaningful .
-
A personal user wants to say hello :
-
A personal user wants to view boss's api :
-
A employee user wants to say hello :
-
A employee user wants to view manager's api :
-
A manager user wants to say hello :
-
A manager user wants to view employee's api :
-
A manager user wants to view boss's api :
-
A boss user wants to say hello :
-