In the last article, I drew the process of SSO single sign-on OAuth 2.0 logout based on the summary of the use of OAuth 2.0 in the framework. Today we will look at the process of obtaining yoghurt information according to user token:
/** * Getting user information from 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); } }
I've just written a few logged-out codes here. We'll post all the codes in detail in the following articles for your reference, and record every process from creating database to executing operation.
From now on, I will record the construction process and essence of spring cloud micro-service Cloud Architecture recently developed, and help more friends who are interested in developing spring cloud framework. Let's discuss the construction process of spring cloud architecture and how to apply it to enterprise projects.
Friends who are willing to understand the framework technology or source code ask directly: Bian 147,775,633