On the basis of a summary of the use of OAuth2.0 in the framework, the OAuth2.0 logout process of SSO single sign-on was drawn, today we take a look at the process of obtaining yoghurt information based on user token:
/*** Get user information based on token *@paramAccesstoken *@return * @throwsException*/@RequestMapping (Value= "/user/token/{accesstoken}", method =requestmethod.get) PublicResponsevo Getuserbytoken (@PathVariable (value = "Accesstoken", required =true) String Accesstoken, @RequestHeader (value = "UserId", required =true) Long userId)throwsException {if(Stringutils.isempty (Accesstoken)) {returnUserresponsecode.buildenumresponsevo (Userresponsecode.response_code_req_cannot_empty,NULL); } Oauthaccesstoken Oauthaccesstoken=Usermgrservice.getoauthaccesstoken (Accesstoken); if(NULL==Oauthaccesstoken) { returnUserresponsecode.buildenumresponsevo (Userresponsecode.response_code_oauth_accesstoken_empty,NULL); } String userName=Oauthaccesstoken.getusername (); if(Stringutils.isempty (userName)) {returnUserresponsecode.buildenumresponsevo (Userresponsecode.response_code_oauth_accesstoken_empty,NULL); } return This. GetUser (UserName); } @RequestMapping (Path= "/user/get/{username}", method =requestmethod.get) PublicResponsevo GetUser (@PathVariable (value = "UserName") (String userName) {Map<string, object> returndata =NULL; Try{User User=Usermgrservice.getuserbyname (userName); if(NULL!=user) {Returndata=NewHashmap<string, object>(); Returndata.put ("User", user); returnUserresponsecode.buildenumresponsevo (userresponsecode.response_code_success, returndata); } returnUserresponsecode.buildenumresponsevo (Userresponsecode.response_code_system_error,NULL); } Catch(Exception e) {returnUserresponsecode.buildenumresponsevo (Userresponsecode.response_code_system_error,NULL); } }
I'm just writing some of the code out here, and we'll post all the code in detail for your reference, from creating a database to every process that executes it.
From now on, I will be documenting the process and essence of the recent development of the spring cloud micro-service cloud architecture to help more friends who are interested in developing the Spring cloud framework to explore the process of building the spring cloud architecture and how to use it in enterprise projects.
Source source technical support for complete projects 1791743380
Integrated Spring Cloud Cloud Architecture-sso Single Sign-on OAuth2.0 get user information based on token (4)