Spring Cloud Cloud architecture-SSO Single Sign-on OAuth2.0 get user information based on token (4)

Source: Internet
Author: User

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
  1. /** 
  2. * Get user information based on token
  3. * @param accesstoken
  4. * @return
  5. * @throws Exception
  6. */
  7. @RequestMapping (value = "/user/token/{accesstoken}", method = Requestmethod.get)
  8. Public Responsevo Getuserbytoken (@PathVariable (value = "Accesstoken", required = true) String accesstoken,< c6> @RequestHeader (value = "userid", required = true) Long userId) throws Exception {
  9. if (Stringutils.isempty (Accesstoken)) {
  10. return Userresponsecode.buildenumresponsevo (userresponsecode.response_code_req_cannot_empty, null);
  11. }
  12. Oauthaccesstoken Oauthaccesstoken = Usermgrservice.getoauthaccesstoken (Accesstoken);
  13. if (null = = Oauthaccesstoken) {
  14. return Userresponsecode.buildenumresponsevo (userresponsecode.response_code_oauth_accesstoken_empty, null  );
  15. }
  16. String userName = Oauthaccesstoken.getusername ();
  17. if (Stringutils.isempty (UserName)) {
  18. return Userresponsecode.buildenumresponsevo (userresponsecode.response_code_oauth_accesstoken_empty, null  );
  19. }
  20. return This.getuser (userName);
  21. }
  22. @RequestMapping (Path = "/user/get/{username}", method = Requestmethod.get)
  23. Public Responsevo GetUser (@PathVariable (value = "UserName") String userName) {
  24. map<string, object> returndata = null;
  25. try {
  26. User user = Usermgrservice.getuserbyname (userName);
  27. if (null! = user) {
  28. Returndata = new hashmap<string, object> ();
  29. Returndata.put ("user", user);
  30. return Userresponsecode.buildenumresponsevo (userresponsecode.response_code_success, returndata);
  31. }
  32. return Userresponsecode.buildenumresponsevo (Userresponsecode.response_code_system_error, null);
  33. } catch (Exception e) {
  34. return Userresponsecode.buildenumresponsevo (Userresponsecode.response_code_system_error, null);
  35. }
  36. }

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.