Skip to content

Commit 1ecfe9e

Browse files
committed
improve error messages
1 parent d28b7f4 commit 1ecfe9e

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

component/grant-type/src/main/java/org/wso2/carbon/identity/oauth2/grant/jwt/JWTBearerGrantHandler.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,13 @@ public boolean validateGrant(OAuthTokenReqMessageContext tokReqMsgCtx) throws Id
334334
//check whether this jwt was issued by the resident identity provider
335335
identityProvider = getResidentIDPForIssuer(tenantDomain, jwtIssuer);
336336
if (identityProvider == null) {
337-
handleClientException("No Registered IDP found for the JWT with issuer name : " + jwtIssuer);
337+
handleClientException("No registered identity provider found for the JWT with issuer name : " + jwtIssuer);
338338
}
339339
}
340340

341341
tokenEndPointAlias = getTokenEndpointAlias(identityProvider);
342342
} else {
343-
handleClientException("No Registered IDP found for the JWT with issuer name : " + jwtIssuer);
343+
handleClientException("No registered identity provider found for the JWT with issuer name : " + jwtIssuer);
344344
}
345345
if (signedJWT != null) {
346346
signatureValid = validateSignature(signedJWT, identityProvider);
@@ -689,10 +689,13 @@ private boolean checkExpirationTime(Date expirationTime, long currentTimeInMilli
689689

690690
long expirationTimeInMillis = expirationTime.getTime();
691691
if ((currentTimeInMillis + timeStampSkewMillis) > expirationTimeInMillis) {
692-
handleClientException("JSON Web Token is expired." +
693-
", Expiration Time(ms) : " + expirationTimeInMillis +
694-
", TimeStamp Skew : " + timeStampSkewMillis +
695-
", Current Time : " + currentTimeInMillis + ". JWT Rejected and validation terminated");
692+
if (log.isDebugEnabled()) {
693+
log.debug("JSON Web Token is expired." +
694+
", Expiration Time(ms) : " + expirationTimeInMillis +
695+
", TimeStamp Skew : " + timeStampSkewMillis +
696+
", Current Time : " + currentTimeInMillis + ". JWT Rejected and validation terminated");
697+
}
698+
handleClientException("JSON Web Token is expired.");
696699
}
697700
return true;
698701
}
@@ -710,10 +713,13 @@ private boolean checkNotBeforeTime(Date notBeforeTime, long currentTimeInMillis,
710713

711714
long notBeforeTimeMillis = notBeforeTime.getTime();
712715
if (currentTimeInMillis + timeStampSkewMillis < notBeforeTimeMillis) {
713-
handleClientException("JSON Web Token is used before Not_Before_Time." +
714-
", Not Before Time(ms) : " + notBeforeTimeMillis +
715-
", TimeStamp Skew : " + timeStampSkewMillis +
716-
", Current Time : " + currentTimeInMillis + ". JWT Rejected and validation terminated");
716+
if (log.isDebugEnabled()) {
717+
log.debug("JSON Web Token is used before Not_Before_Time." +
718+
", Not Before Time(ms) : " + notBeforeTimeMillis +
719+
", TimeStamp Skew : " + timeStampSkewMillis +
720+
", Current Time : " + currentTimeInMillis + ". JWT Rejected and validation terminated");
721+
}
722+
handleClientException("JSON Web Token is used before Not_Before_Time.");
717723
}
718724
return true;
719725
}
@@ -734,11 +740,14 @@ private boolean checkValidityOfTheToken(Date issuedAtTime, long currentTimeInMil
734740
long rejectBeforeMillis = 1000L * 60 * validityPeriod;
735741
if (currentTimeInMillis + timeStampSkewMillis - issuedAtTimeMillis >
736742
rejectBeforeMillis) {
737-
handleClientException("JSON Web Token is issued before the allowed time." +
738-
", Issued At Time(ms) : " + issuedAtTimeMillis +
739-
", Reject before limit(ms) : " + rejectBeforeMillis +
740-
", TimeStamp Skew : " + timeStampSkewMillis +
741-
", Current Time : " + currentTimeInMillis + ". JWT Rejected and validation terminated");
743+
if (log.isDebugEnabled()) {
744+
log.debug("JSON Web Token is issued before the allowed time." +
745+
", Issued At Time(ms) : " + issuedAtTimeMillis +
746+
", Reject before limit(ms) : " + rejectBeforeMillis +
747+
", TimeStamp Skew : " + timeStampSkewMillis +
748+
", Current Time : " + currentTimeInMillis + ". JWT Rejected and validation terminated");
749+
}
750+
handleClientException("JSON Web Token is issued before the allowed time.");
742751
}
743752
return true;
744753
}

0 commit comments

Comments
 (0)