Skip to content

Commit

Permalink
Merge pull request #100 from wangyu096/github_perf/esb_api_normalization
Browse files Browse the repository at this point in the history
perf: esb api normalization #79
  • Loading branch information
jsonwan authored Jul 15, 2021
2 parents ead0c06 + 7c8a097 commit cf0b350
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package com.tencent.bk.job.common.web.interceptor;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
import com.tencent.bk.job.common.constant.JobCommonHeaders;
Expand Down Expand Up @@ -62,19 +63,23 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
}
// reset username and appCode
if (StringUtils.isNotBlank(username)) {
String usernameInBody = jsonBody.get("bk_username").asText();
if (StringUtils.isNotEmpty(usernameInBody) && !usernameInBody.equals(username)) {
log.error("Invalid username, usernameInBody: {}, username: {}", usernameInBody, username);
JsonNode bkUserNameNode = jsonBody.get("bk_username");
if (bkUserNameNode != null && StringUtils.isNotBlank(bkUserNameNode.asText())
&& !bkUserNameNode.asText().equals(username)) {
log.error("Invalid username, usernameInBody: {}, username: {}", bkUserNameNode.asText(),
username);
}
jsonBody.set("bk_username", new TextNode(username));
} else {
log.error("Header {} is missing", JobCommonHeaders.USERNAME);
}

if (StringUtils.isNotBlank(appCode)) {
String appCodeInBody = jsonBody.get("bk_app_code").asText();
if (StringUtils.isNotEmpty(appCodeInBody) && !appCodeInBody.equals(appCode)) {
log.error("Invalid appCode, appCodeInBody: {}, appCode: {}", appCodeInBody, appCode);
JsonNode bkAppCodeNode = jsonBody.get("bk_app_code");
if (bkAppCodeNode != null && StringUtils.isNotBlank(bkAppCodeNode.asText())
&& !bkAppCodeNode.asText().equals(appCode)) {
log.error("Invalid appCode, appCodeInBody: {}, appCode: {}", bkAppCodeNode.asText(),
appCode);
}
jsonBody.set("bk_app_code", new TextNode(appCode));
} else {
Expand Down

0 comments on commit cf0b350

Please sign in to comment.