Skip to content

Commit

Permalink
fixes networknt#1252 resolve a class cast exception in TokenHandler (n…
Browse files Browse the repository at this point in the history
…etworknt#1253)

* fixes networknt#1252 resolve a class cast exception in TokenHandler

* fixes networknt#1252 add trace logs for authorization
  • Loading branch information
stevehu committed Jun 6, 2022
1 parent fd01ba4 commit e78e3f1
Showing 1 changed file with 6 additions and 2 deletions.
Expand Up @@ -103,7 +103,7 @@ public void handleRequest(final HttpServerExchange exchange) throws Exception {

Jwt cachedJwt = cache.get(serviceId);
// get a new token if cachedJwt is null or the jwt is about expired.
if(cachedJwt == null || cachedJwt.getExpire() - (Long)tokenConfig.get(ClientConfig.TOKEN_RENEW_BEFORE_EXPIRED) < System.currentTimeMillis()) {
if(cachedJwt == null || cachedJwt.getExpire() - Long.valueOf((Integer)tokenConfig.get(ClientConfig.TOKEN_RENEW_BEFORE_EXPIRED)) < System.currentTimeMillis()) {
Jwt.Key key = new Jwt.Key(serviceId);
cachedJwt = new Jwt(key); // create a new instance if the cache is empty for the serviceId.

Expand Down Expand Up @@ -146,11 +146,15 @@ public void handleRequest(final HttpServerExchange exchange) throws Exception {
// assume that the subject token has the scope already?)
String token = exchange.getRequestHeaders().getFirst(Headers.AUTHORIZATION);
if(token == null) {
if(logger.isTraceEnabled()) logger.trace("Adding jwt token to Authorization header with Bearer " + cachedJwt.getJwt().substring(20));
exchange.getRequestHeaders().put(Headers.AUTHORIZATION, "Bearer " + cachedJwt.getJwt());
} else {
if(logger.isTraceEnabled()) {
logger.trace("Authorization header is used with " + token.substring(10));
logger.trace("Adding jwt token to X-Scope-Token header with Bearer " + cachedJwt.getJwt().substring(20));
}
exchange.getRequestHeaders().put(HttpStringConstants.SCOPE_TOKEN, "Bearer " + cachedJwt.getJwt());
}

Handler.next(exchange, next);
}

Expand Down

0 comments on commit e78e3f1

Please sign in to comment.