From 2c0c7fe6f984a16f9f2cf1b2e402db2447dc26ea Mon Sep 17 00:00:00 2001 From: Steve Hu Date: Thu, 22 Aug 2024 15:10:41 -0400 Subject: [PATCH] fixes #396 use the handleRequest from abstract handlers for security handlers --- .../networknt/openapi/JwtVerifyHandler.java | 25 ------------------- .../openapi/SimpleJwtVerifyHandler.java | 25 ------------------- .../networknt/openapi/SwtVerifyHandler.java | 24 ------------------ 3 files changed, 74 deletions(-) diff --git a/openapi-security/src/main/java/com/networknt/openapi/JwtVerifyHandler.java b/openapi-security/src/main/java/com/networknt/openapi/JwtVerifyHandler.java index 3b0d12a..a2e1be4 100644 --- a/openapi-security/src/main/java/com/networknt/openapi/JwtVerifyHandler.java +++ b/openapi-security/src/main/java/com/networknt/openapi/JwtVerifyHandler.java @@ -69,31 +69,6 @@ public JwtVerifyHandler() { this.basePath = handlerConfig == null ? "/" : handlerConfig.getBasePath(); } - @Override - @SuppressWarnings("unchecked") - public void handleRequest(final HttpServerExchange exchange) throws Exception { - - 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(reqPath::startsWith)) { - if(logger.isTraceEnabled()) - logger.trace("Skip request path base on skipPathPrefixes for " + reqPath); - Handler.next(exchange, next); - if (logger.isDebugEnabled()) - logger.debug("JwtVerifyHandler.handleRequest ends."); - return; - } - // only UnifiedSecurityHandler will have the jwkServiceIds as the third parameter. - if(handleJwt(exchange, null, reqPath, null)) { - if(logger.isDebugEnabled()) logger.debug("JwtVerifyHandler.handleRequest ends."); - Handler.next(exchange, next); - } - } - @Override public List getSpecScopes(HttpServerExchange exchange, Map auditInfo) throws Exception { /* get openapi operation */ diff --git a/openapi-security/src/main/java/com/networknt/openapi/SimpleJwtVerifyHandler.java b/openapi-security/src/main/java/com/networknt/openapi/SimpleJwtVerifyHandler.java index fd62ca9..1465b4d 100644 --- a/openapi-security/src/main/java/com/networknt/openapi/SimpleJwtVerifyHandler.java +++ b/openapi-security/src/main/java/com/networknt/openapi/SimpleJwtVerifyHandler.java @@ -33,31 +33,6 @@ public SimpleJwtVerifyHandler() { this.basePath = handlerConfig == null ? "/" : handlerConfig.getBasePath(); } - @Override - @SuppressWarnings("unchecked") - public void handleRequest(final HttpServerExchange exchange) throws Exception { - - if (logger.isDebugEnabled()) - logger.debug("SimpleJwtVerifyHandler.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(reqPath::startsWith)) { - if(logger.isTraceEnabled()) - logger.trace("Skip request path base on skipPathPrefixes for {}", reqPath); - Handler.next(exchange, next); - if (logger.isDebugEnabled()) - logger.debug("SimpleJwtVerifyHandler.handleRequest ends."); - return; - } - // only UnifiedSecurityHandler will have the jwkServiceIds as the third parameter. - if(handleJwt(exchange, null, reqPath, null)) { - if(logger.isDebugEnabled()) logger.debug("SimpleJwtVerifyHandler.handleRequest ends."); - Handler.next(exchange, next); - } - } - @Override public HttpHandler getNext() { return next; diff --git a/openapi-security/src/main/java/com/networknt/openapi/SwtVerifyHandler.java b/openapi-security/src/main/java/com/networknt/openapi/SwtVerifyHandler.java index 9dc68c2..0053e32 100644 --- a/openapi-security/src/main/java/com/networknt/openapi/SwtVerifyHandler.java +++ b/openapi-security/src/main/java/com/networknt/openapi/SwtVerifyHandler.java @@ -62,30 +62,6 @@ public void reload() { ModuleRegistry.registerModule(SecurityConfig.CONFIG_NAME, SwtVerifyHandler.class.getName(), Config.getNoneDecryptedInstance().getJsonMapConfigNoCache(SecurityConfig.CONFIG_NAME), null); } - @Override - public void handleRequest(HttpServerExchange exchange) throws Exception { - if (logger.isDebugEnabled()) - logger.debug("SwtVerifyHandler.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(reqPath::startsWith)) { - if(logger.isTraceEnabled()) - logger.trace("Skip request path base on skipPathPrefixes for " + reqPath); - Handler.next(exchange, next); - if (logger.isDebugEnabled()) - logger.debug("SwtVerifyHandler.handleRequest ends."); - return; - } - // only UnifiedSecurityHandler will have the jwkServiceIds as the third parameter. - if(handleSwt(exchange, reqPath, null)) { - if(logger.isDebugEnabled()) logger.debug("SwtVerifyHandler.handleRequest ends."); - Handler.next(exchange, next); - } - } - - @Override public List getSpecScopes(HttpServerExchange exchange, Map auditInfo) throws Exception { /* get openapi operation */