整合spring cloud雲架構 - token獲取用戶信息
阿新 • • 發佈:2018-07-04
exception path ash resp null require 數據 ade pri 上一篇我根據框架中OAuth2.0的使用總結,畫了SSO單點登錄之OAuth2.0 登出流程,今天我們看一下根據用戶token獲取yoghurt信息的流程:
/** * 根據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雲架構 - token獲取用戶信息