Skip to content

Commit

Permalink
fixes #254 update the starts and ends to debug level (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehu authored Nov 27, 2022
1 parent 759832e commit fdcd3fb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ public AccessControlHandler() {
@Override
@SuppressWarnings("unchecked")
public void handleRequest(final HttpServerExchange exchange) throws Exception {
if (logger.isDebugEnabled()) logger.trace("AccessControlHandler.handleRequest starts.");
if (logger.isDebugEnabled()) logger.debug("AccessControlHandler.handleRequest starts.");
String reqPath = exchange.getRequestPath();
// if request path is in the skipPathPrefixes in the config, call the next handler directly to skip the security check.
if (config.getSkipPathPrefixes() != null && config.getSkipPathPrefixes().stream().anyMatch(s -> reqPath.startsWith(s))) {
if(logger.isTraceEnabled()) logger.trace("Skip request path base on skipPathPrefixes for " + reqPath);
if (logger.isDebugEnabled()) logger.trace("AccessControlHandler.handleRequest ends with path skipped.");
if (logger.isDebugEnabled()) logger.debug("AccessControlHandler.handleRequest ends with path skipped.");
Handler.next(exchange, next);
return;
}
Expand All @@ -93,7 +93,7 @@ public void handleRequest(final HttpServerExchange exchange) throws Exception {
if (RuleLoaderStartupHook.endpointRules == null) {
logger.error("RuleLoaderStartupHook endpointRules is null");
setExchangeStatus(exchange, STARTUP_HOOK_NOT_LOADED, "RuleLoaderStartupHook");
if (logger.isDebugEnabled()) logger.trace("AccessControlHandler.handleRequest ends with an error.");
if (logger.isDebugEnabled()) logger.debug("AccessControlHandler.handleRequest ends with an error.");
return;
}

Expand All @@ -104,10 +104,10 @@ public void handleRequest(final HttpServerExchange exchange) throws Exception {
if (requestRules == null) {
if (config.defaultDeny) {
logger.error("Access control rule is missing and default deny is true for endpoint " + endpoint);
if (logger.isDebugEnabled()) logger.trace("AccessControlHandler.handleRequest ends with an error.");
if (logger.isDebugEnabled()) logger.debug("AccessControlHandler.handleRequest ends with an error.");
setExchangeStatus(exchange, ACCESS_CONTROL_MISSING, endpoint);
} else {
if (logger.isDebugEnabled()) logger.trace("AccessControlHandler.handleRequest ends.");
if (logger.isDebugEnabled()) logger.debug("AccessControlHandler.handleRequest ends.");
next(exchange);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public OpenApiHandler() {
}
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
if (logger.isDebugEnabled()) logger.trace("OpenApiHandler.handleRequest starts.");
if (logger.isDebugEnabled()) logger.debug("OpenApiHandler.handleRequest starts.");
if(config.isMultipleSpec()) {
String p = exchange.getRequestPath();
boolean found = false;
Expand All @@ -149,7 +149,7 @@ public void handleRequest(final HttpServerExchange exchange) throws Exception {
final Optional<NormalisedPath> maybeApiPath = h.findMatchingApiPath(requestPath);
if (!maybeApiPath.isPresent()) {
setExchangeStatus(exchange, STATUS_INVALID_REQUEST_PATH, requestPath.normalised());
if (logger.isDebugEnabled()) logger.trace("OpenApiHandler.handleRequest ends with an error.");
if (logger.isDebugEnabled()) logger.debug("OpenApiHandler.handleRequest ends with an error.");
return;
}

Expand All @@ -161,7 +161,7 @@ public void handleRequest(final HttpServerExchange exchange) throws Exception {

if (operation == null) {
setExchangeStatus(exchange, STATUS_METHOD_NOT_ALLOWED, httpMethod, openApiPathString.normalised());
if (logger.isDebugEnabled()) logger.trace("OpenApiHandler.handleRequest ends with an error.");
if (logger.isDebugEnabled()) logger.debug("OpenApiHandler.handleRequest ends with an error.");
return;
}

Expand All @@ -186,15 +186,15 @@ public void handleRequest(final HttpServerExchange exchange) throws Exception {
}
if(!found) {
setExchangeStatus(exchange, STATUS_INVALID_REQUEST_PATH, p);
if (logger.isDebugEnabled()) logger.trace("OpenApiHandler.handleRequest ends with an error.");
if (logger.isDebugEnabled()) logger.debug("OpenApiHandler.handleRequest ends with an error.");
return;
}
} else {
final NormalisedPath requestPath = new ApiNormalisedPath(exchange.getRequestURI(), helper.basePath);
final Optional<NormalisedPath> maybeApiPath = helper.findMatchingApiPath(requestPath);
if (!maybeApiPath.isPresent()) {
setExchangeStatus(exchange, STATUS_INVALID_REQUEST_PATH, requestPath.normalised());
if (logger.isDebugEnabled()) logger.trace("OpenApiHandler.handleRequest ends with an error.");
if (logger.isDebugEnabled()) logger.debug("OpenApiHandler.handleRequest ends with an error.");
return;
}

Expand All @@ -206,7 +206,7 @@ public void handleRequest(final HttpServerExchange exchange) throws Exception {

if (operation == null) {
setExchangeStatus(exchange, STATUS_METHOD_NOT_ALLOWED, httpMethod, openApiPathString.normalised());
if (logger.isDebugEnabled()) logger.trace("OpenApiHandler.handleRequest ends with an error.");
if (logger.isDebugEnabled()) logger.debug("OpenApiHandler.handleRequest ends with an error.");
return;
}

Expand All @@ -227,7 +227,7 @@ public void handleRequest(final HttpServerExchange exchange) throws Exception {
auditInfo.put(Constants.OPENAPI_OPERATION_STRING, openApiOperation);
exchange.putAttachment(AttachmentConstants.AUDIT_INFO, auditInfo);
}
if (logger.isDebugEnabled()) logger.trace("OpenApiHandler.handleRequest ends.");
if (logger.isDebugEnabled()) logger.debug("OpenApiHandler.handleRequest ends.");
Handler.next(exchange, next);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ public JwtVerifyHandler() {
@Override
@SuppressWarnings("unchecked")
public void handleRequest(final HttpServerExchange exchange) throws Exception {
if (logger.isDebugEnabled()) logger.trace("JwtVerifyHandler.handleRequest starts.");
if (logger.isDebugEnabled()) logger.debug("JwtVerifyHandler.handleRequest starts.");
String reqPath = exchange.getRequestPath();
// if request path is in the skipPathPrefixes in the config, call the next handler directly to skip the security check.
if (config.getSkipPathPrefixes() != null && config.getSkipPathPrefixes().stream().anyMatch(s -> reqPath.startsWith(s))) {
if(logger.isTraceEnabled()) logger.trace("Skip request path base on skipPathPrefixes for " + reqPath);
Handler.next(exchange, next);
if (logger.isDebugEnabled()) logger.trace("JwtVerifyHandler.handleRequest ends.");
if (logger.isDebugEnabled()) logger.debug("JwtVerifyHandler.handleRequest ends.");
return;
}
Map<String, Object> auditInfo = null;
Expand Down Expand Up @@ -144,7 +144,7 @@ public void handleRequest(final HttpServerExchange exchange) throws Exception {

if (!config.isEnableH2c() && this.checkForH2CRequest(headerMap)) {
setExchangeStatus(exchange, STATUS_METHOD_NOT_ALLOWED);
if (logger.isDebugEnabled()) logger.trace("JwtVerifyHandler.handleRequest ends with an error.");
if (logger.isDebugEnabled()) logger.debug("JwtVerifyHandler.handleRequest ends with an error.");
return;
}

Expand Down Expand Up @@ -178,20 +178,20 @@ public void handleRequest(final HttpServerExchange exchange) throws Exception {
}
if (logger.isTraceEnabled())
logger.trace("complete JWT verification for request path = " + exchange.getRequestURI());
if (logger.isDebugEnabled()) logger.trace("JwtVerifyHandler.handleRequest ends.");
if (logger.isDebugEnabled()) logger.debug("JwtVerifyHandler.handleRequest ends.");
Handler.next(exchange, next);
} catch (InvalidJwtException e) {
// only log it and unauthorized is returned.
logger.error("InvalidJwtException: ", e);
if (logger.isDebugEnabled()) logger.trace("JwtVerifyHandler.handleRequest ends with an error.");
if (logger.isDebugEnabled()) logger.debug("JwtVerifyHandler.handleRequest ends with an error.");
setExchangeStatus(exchange, STATUS_INVALID_AUTH_TOKEN);
} catch (ExpiredTokenException e) {
logger.error("ExpiredTokenException", e);
if (logger.isDebugEnabled()) logger.trace("JwtVerifyHandler.handleRequest ends with an error.");
if (logger.isDebugEnabled()) logger.debug("JwtVerifyHandler.handleRequest ends with an error.");
setExchangeStatus(exchange, STATUS_AUTH_TOKEN_EXPIRED);
}
} else {
if (logger.isDebugEnabled()) logger.trace("JwtVerifyHandler.handleRequest ends with an error.");
if (logger.isDebugEnabled()) logger.debug("JwtVerifyHandler.handleRequest ends with an error.");
setExchangeStatus(exchange, STATUS_MISSING_AUTH_TOKEN);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ public ValidatorHandler() {

@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
if (logger.isDebugEnabled()) logger.trace("ValidatorHandler.handleRequest starts.");
if (logger.isDebugEnabled()) logger.debug("ValidatorHandler.handleRequest starts.");
String reqPath = exchange.getRequestPath();
// if request path is in the skipPathPrefixes in the config, call the next handler directly to skip the validation.
if (config.getSkipPathPrefixes() != null && config.getSkipPathPrefixes().stream().anyMatch(s -> reqPath.startsWith(s))) {
if (logger.isDebugEnabled()) logger.trace("ValidatorHandler.handleRequest ends with skipped path " + reqPath);
if (logger.isDebugEnabled()) logger.debug("ValidatorHandler.handleRequest ends with skipped path " + reqPath);
Handler.next(exchange, next);
return;
}
Expand All @@ -102,14 +102,14 @@ public void handleRequest(final HttpServerExchange exchange) throws Exception {
openApiOperation = (OpenApiOperation)auditInfo.get(Constants.OPENAPI_OPERATION_STRING);
}
if(openApiOperation == null) {
if (logger.isDebugEnabled()) logger.trace("ValidatorHandler.handleRequest ends with an error.");
if (logger.isDebugEnabled()) logger.debug("ValidatorHandler.handleRequest ends with an error.");
setExchangeStatus(exchange, STATUS_MISSING_OPENAPI_OPERATION);
return;
}
RequestValidator reqV = getRequestValidator(exchange.getRequestPath());
Status status = reqV.validateRequest(requestPath, exchange, openApiOperation);
if(status != null) {
if (logger.isDebugEnabled()) logger.trace("ValidatorHandler.handleRequest ends with an error.");
if (logger.isDebugEnabled()) logger.debug("ValidatorHandler.handleRequest ends with an error.");
setExchangeStatus(exchange, status);
if(config.logError) {
logger.error("There is an Validation Error:");
Expand All @@ -120,7 +120,7 @@ public void handleRequest(final HttpServerExchange exchange) throws Exception {
if(config.validateResponse) {
validateResponse(exchange, openApiOperation);
}
if (logger.isDebugEnabled()) logger.trace("ValidatorHandler.handleRequest ends.");
if (logger.isDebugEnabled()) logger.debug("ValidatorHandler.handleRequest ends.");
Handler.next(exchange, next);
}

Expand Down

0 comments on commit fdcd3fb

Please sign in to comment.