我依据框架中 OAuth2.0 的应用总结,画了 SSO 单点登录之 OAuth2.0 登出流程,明天咱们看一下依据用户 token 获取 yoghurt 信息的流程(企业架构源码能够加求球:三五三六二四七二五九):
1. /**
2. * 依据 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,@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. }
13. OauthAccessToken oauthAccessToken = userMgrService.getOauthAccessToken(accessToken);
14. if(null == oauthAccessToken){15. return UserResponseCode.buildEnumResponseVO(UserResponseCode.RESPONSE_CODE_OAUTH_ACCESSTOKEN_EMPTY, null);
16. }
18. String userName = oauthAccessToken.getUserName();
19. if (StringUtils.isEmpty(userName)) {20. return UserResponseCode.buildEnumResponseVO(UserResponseCode.RESPONSE_CODE_OAUTH_ACCESSTOKEN_EMPTY, null);
21. }
23. return this.getUser(userName);
24. }
26. @RequestMapping(path = "/user/get/{userName}", method = RequestMethod.GET)
27. public ResponseVO getUser(@PathVariable(value = "userName") String userName) {
28. Map<String, Object> returnData = null;
29. try {30. User user = userMgrService.getUserByName(userName);
31. if (null != user) {32. returnData = new HashMap<String, Object>();
33. returnData.put("user", user);
34. return UserResponseCode.buildEnumResponseVO(UserResponseCode.RESPONSE_CODE_SUCCESS, returnData);
35. }
36. return UserResponseCode.buildEnumResponseVO(UserResponseCode.RESPONSE_CODE_SYSTEM_ERROR, null);
37. } catch (Exception e) {38. return UserResponseCode.buildEnumResponseVO(UserResponseCode.RESPONSE_CODE_SYSTEM_ERROR, null);
39. }
41. }
我这里只是简略写了一些登出的代码,咱们会在前面的文章中具体贴出所有代码供大家参考,而且会从创立数据库,到执行操作的每一个流程记录下来。
从当初开始,我这边会将近期研发的 spring cloud 微服务云架构的搭建过程和精华记录下来,帮忙更多有趣味研发 spring cloud 框架的敌人,大家来一起探讨 spring cloud 架构的搭建过程及如何使用于企业我的项目。