From 1467ba3ad7922995b9a9ffcf53cd54802f20ade1 Mon Sep 17 00:00:00 2001 From: Steve Hu Date: Wed, 11 May 2022 10:09:42 -0400 Subject: [PATCH] fixes #1227 add some debug statements to the JWT access in client and security modules --- .../com/networknt/client/oauth/KeyRequest.java | 15 +++++++++++++++ .../com/networknt/client/oauth/OauthHelper.java | 2 ++ .../java/com/networknt/security/JwtVerifier.java | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/client/src/main/java/com/networknt/client/oauth/KeyRequest.java b/client/src/main/java/com/networknt/client/oauth/KeyRequest.java index 3f78f1f5a3..f554462dfc 100644 --- a/client/src/main/java/com/networknt/client/oauth/KeyRequest.java +++ b/client/src/main/java/com/networknt/client/oauth/KeyRequest.java @@ -107,4 +107,19 @@ public int getProxyPort() { public void setProxyPort(int proxyPort) { this.proxyPort = proxyPort; } + + @Override + public String toString() { + return "KeyRequest{" + + "serverUrl='" + serverUrl + '\'' + + ", proxyHost='" + proxyHost + '\'' + + ", proxyPort=" + proxyPort + + ", serviceId='" + serviceId + '\'' + + ", uri='" + uri + '\'' + + ", clientId='" + clientId + '\'' + + ", clientSecret='" + clientSecret + '\'' + + ", enableHttp2=" + enableHttp2 + + ", kid='" + kid + '\'' + + '}'; + } } diff --git a/client/src/main/java/com/networknt/client/oauth/OauthHelper.java b/client/src/main/java/com/networknt/client/oauth/OauthHelper.java index 9d2cbc826a..00249f5e98 100644 --- a/client/src/main/java/com/networknt/client/oauth/OauthHelper.java +++ b/client/src/main/java/com/networknt/client/oauth/OauthHelper.java @@ -285,6 +285,7 @@ public static Result getTokenFromSamlResult(SAMLBearerRequest tok * @throws ClientException throw exception if communication with the service fails. */ public static String getKey(KeyRequest keyRequest) throws ClientException { + if(logger.isDebugEnabled()) logger.debug("keyRequest = " + keyRequest.toString()); return getKey(keyRequest, null); } @@ -333,6 +334,7 @@ public static String getKey(KeyRequest keyRequest, String envTag) throws ClientE keyClient.sendAsync(request, HttpResponse.BodyHandlers.ofString()); return response.thenApply(HttpResponse::body).get(ClientConfig.get().getTimeout(), TimeUnit.MILLISECONDS); } catch (Exception e) { + logger.error("Exception:", e); throw new ClientException(e); } } diff --git a/security/src/main/java/com/networknt/security/JwtVerifier.java b/security/src/main/java/com/networknt/security/JwtVerifier.java index 896b97285a..facde83fc2 100644 --- a/security/src/main/java/com/networknt/security/JwtVerifier.java +++ b/security/src/main/java/com/networknt/security/JwtVerifier.java @@ -370,7 +370,7 @@ private Map> getJsonWebKeyMap() { try { logger.debug("Getting Json Web Key list from {} for serviceId {}", keyRequest.getServerUrl(), entry.getKey()); String key = OauthHelper.getKey(keyRequest); - logger.debug("Got Json Web Key list from {} for serviceId {}", keyRequest.getServerUrl(), entry.getKey()); + logger.debug("Got Json Web Key = ", key); List jwkList = new JsonWebKeySet(key).getJsonWebKeys(); if (jwkList == null || jwkList.isEmpty()) { throw new RuntimeException("cannot get JWK from OAuth server");