Skip to content

Commit

Permalink
Merge pull request #3642 from rajithacharith/choreo-new
Browse files Browse the repository at this point in the history
Add traceId header to oauth-agent requests.
  • Loading branch information
renuka-fernando authored Feb 11, 2025
2 parents 266e153 + 49c4689 commit 42aaea6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class APIConstants {
public static final String PATH_HEADER = ":path";

public static final String LOG_TRACE_ID = "traceId";
public static final String OAUTH_AGENT_TRACE_ID_HEADER = "x-correlation-id";

/**
* Holds the common set of constants related to the output status codes of the security validations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;
import org.wso2.choreo.connect.enforcer.config.ConfigHolder;
import org.wso2.choreo.connect.enforcer.constants.APIConstants;
import org.wso2.choreo.connect.enforcer.constants.APISecurityConstants;
Expand Down Expand Up @@ -124,6 +125,8 @@ public static Optional<String> exchangePATToJWT(String patHash) {
// Create a request to exchange API key to JWT.
HttpPost exchangeRequest = new HttpPost(url.toURI());
exchangeRequest.addHeader("Content-Type", ContentType.APPLICATION_JSON.toString());
exchangeRequest.addHeader(APIConstants.OAUTH_AGENT_TRACE_ID_HEADER,
ThreadContext.get(APIConstants.LOG_TRACE_ID));
exchangeRequest.setEntity(new StringEntity(createKeyHashExchangeRequest(patHash)));
try (CloseableHttpResponse response = httpClient.execute(exchangeRequest)) {
if (response.getStatusLine().getStatusCode() == 200) {
Expand Down Expand Up @@ -162,6 +165,8 @@ public static Optional<String> exchangeAPIKeyToJWT(String apiKeyId) {
// Create a request to exchange API key to JWT.
HttpPost exchangeRequest = new HttpPost(url.toURI());
exchangeRequest.addHeader("Content-Type", ContentType.APPLICATION_JSON.toString());
exchangeRequest.addHeader(APIConstants.OAUTH_AGENT_TRACE_ID_HEADER,
ThreadContext.get(APIConstants.LOG_TRACE_ID));
exchangeRequest.setEntity(new StringEntity(createKeyHashExchangeRequest(apiKeyId)));
try (CloseableHttpResponse response = httpClient.execute(exchangeRequest)) {
if (response.getStatusLine().getStatusCode() == 200) {
Expand Down

0 comments on commit 42aaea6

Please sign in to comment.