(13) Integrate spring cloud cloud architecture - OAuth2.0 for SSO single sign-on to obtain user information based on token (4)

In the last article, I drew the OAuth2.0 logout process of SSO single sign-on based on the summary of the use of OAuth2.0 in the framework. Today, let's take a look at the process of obtaining yoghurt information according to the user token:



 

       /**
	 * Get user information based on 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 just simply wrote some logout codes here. We will post all the codes in detail in the following articles for your reference, and will record every process from creating the database to performing operations.

 

From now on, I will record the construction process and essence of the recently developed spring cloud microservice cloud architecture to help more friends who are interested in developing the spring cloud framework. Let's discuss the construction process and how of the spring cloud architecture together. Used in enterprise projects.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326197505&siteId=291194637