上一篇我根據框架中OAuth2.0的使用總結,畫了SSO單點登陸之OAuth2.0 登出流程,今天咱們看一下根據用戶token獲取yoghurt信息的流程:spring
/** * 根據token獲取用戶信息 * @param accessToken * @return * @throws Exception */ @RequestMapping(value = "/user/token/{accesstoken}", method = RequestMethod.GET) public ResponseVO getUserByToken(@PathVariable(value = "accessToken", required = true) String accessToken,@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); } } 複製代碼
我這裏只是簡單寫了一些登出的代碼,咱們會在後面的文章中詳細貼出全部代碼供你們參考,並且會從建立數據庫,到執行操做的每個流程記錄下來。數據庫
從如今開始,我這邊會將近期研發的spring cloud微服務雲架構的搭建過程和精髓記錄下來,幫助更多有興趣研發spring cloud框架的朋友,你們來一塊兒探討spring cloud架構的搭建過程及如何運用於企業項目。bash
須要JAVASpring Cloud大型企業分佈式微服務雲構建的B2B2C電子商務平臺源碼請加企鵝求求:一零三八七七四六二六
架構