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:
Java code
- /**
- * Get user information based on token
- * @param accesstoken
- * @return
- * @throws Exception
- */
- @RequestMapping (value = "/user/token/{accesstoken}", method = Requestmethod.get)
- Public Responsevo Getuserbytoken (@PathVariable (value = "Accesstoken", required = true) String accesstoken,< c6> @RequestHeader (value = "userid", required = true) Long userId) throws Exception {
- if (Stringutils.isempty (Accesstoken)) {
- return Userresponsecode.buildenumresponsevo (userresponsecode.response_code_req_cannot_empty, null);
- }
- Oauthaccesstoken Oauthaccesstoken = Usermgrservice.getoauthaccesstoken (Accesstoken);
- if (null = = Oauthaccesstoken) {
- return Userresponsecode.buildenumresponsevo (userresponsecode.response_code_oauth_accesstoken_empty, null );
- }
- String userName = Oauthaccesstoken.getusername ();
- if (Stringutils.isempty (UserName)) {
- return Userresponsecode.buildenumresponsevo (userresponsecode.response_code_oauth_accesstoken_empty, null );
- }
- return This.getuser (userName);
- }
- @RequestMapping (Path = "/user/get/{username}", method = Requestmethod.get)
- Public Responsevo GetUser (@PathVariable (value = "UserName") String userName) {
- map<string, object> returndata = null;
- try {
- User user = Usermgrservice.getuserbyname (userName);
- if (null! = user) {
- Returndata = new hashmap<string, object> ();
- Returndata.put ("user", user);
- return Userresponsecode.buildenumresponsevo (userresponsecode.response_code_success, returndata);
- }
- return Userresponsecode.buildenumresponsevo (Userresponsecode.response_code_system_error, null);
- } catch (Exception e) {
- return Userresponsecode.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
Spring Cloud Cloud architecture-SSO Single Sign-on OAuth2.0 get user information based on token (4)