From a42d7cc1f879c5369e858e03589f10124979e6cc Mon Sep 17 00:00:00 2001 From: ArchILLtect Date: Wed, 17 Dec 2025 18:23:57 -0600 Subject: [PATCH] chore: enhance AuthGuardFilter and JSP files for improved static asset handling and layout consistency --- .../codeforge/web/AuthGuardFilter.java | 32 +++++++++++++++++-- .../nickhanson/codeforge/web/HomeServlet.java | 2 +- .../webapp/WEB-INF/jsp/challenges/detail.jsp | 1 + .../webapp/WEB-INF/jsp/challenges/list.jsp | 1 + src/main/webapp/WEB-INF/jsp/drill/solve.jsp | 1 - src/main/webapp/WEB-INF/jsp/header.jsp | 22 +++---------- src/main/webapp/WEB-INF/jsp/home.jsp | 3 +- .../{WEB-INF/jsp/practice => }/index.jsp | 0 8 files changed, 38 insertions(+), 24 deletions(-) rename src/main/webapp/{WEB-INF/jsp/practice => }/index.jsp (100%) diff --git a/src/main/java/me/nickhanson/codeforge/web/AuthGuardFilter.java b/src/main/java/me/nickhanson/codeforge/web/AuthGuardFilter.java index 3d324fa..633f492 100644 --- a/src/main/java/me/nickhanson/codeforge/web/AuthGuardFilter.java +++ b/src/main/java/me/nickhanson/codeforge/web/AuthGuardFilter.java @@ -6,7 +6,6 @@ import javax.servlet.http.HttpFilter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; import java.io.IOException; import java.util.Set; @@ -37,11 +36,40 @@ protected void doFilter(HttpServletRequest req, HttpServletResponse resp, Filter throws IOException, ServletException { String contextPath = req.getContextPath(); - String path = req.getRequestURI().substring(contextPath.length()); + String uri = req.getRequestURI(); + String path = uri.substring(contextPath.length()); String method = req.getMethod(); boolean needsAuth = false; + // 1) Always allow static assets + if (path.startsWith("/css/") + || path.startsWith("/images/") + || path.startsWith("/apidocs/") + || path.equals("/favicon.ico") + || path.startsWith("/favicon") + || path.endsWith(".css") + || path.endsWith(".js") + || path.endsWith(".png") + || path.endsWith(".jpg") + || path.endsWith(".jpeg") + || path.endsWith(".gif") + || path.endsWith(".svg") + || path.endsWith(".webp")) { + chain.doFilter(req, resp); + return; + } + +// 2) Allow your public pages (home/about/login/error) + if (path.equals("/") || path.equals("/home") + || path.startsWith("/about") + || path.startsWith("/logIn") + || path.startsWith("/logout") + || path.startsWith("/error")) { + chain.doFilter(req, resp); + return; + } + // Check if the request method is POST. if ("POST".equalsIgnoreCase(method)) { // Public practice submissions do NOT require auth diff --git a/src/main/java/me/nickhanson/codeforge/web/HomeServlet.java b/src/main/java/me/nickhanson/codeforge/web/HomeServlet.java index def4b79..5d82286 100644 --- a/src/main/java/me/nickhanson/codeforge/web/HomeServlet.java +++ b/src/main/java/me/nickhanson/codeforge/web/HomeServlet.java @@ -15,7 +15,7 @@ * * @author Nick Hanson */ -@WebServlet(urlPatterns = {"/", "/home"}) +@WebServlet(urlPatterns = {"/home"}) public class HomeServlet extends HttpServlet { private final QuoteService quotes = new QuoteService(); diff --git a/src/main/webapp/WEB-INF/jsp/challenges/detail.jsp b/src/main/webapp/WEB-INF/jsp/challenges/detail.jsp index 94879e8..21e1ef5 100644 --- a/src/main/webapp/WEB-INF/jsp/challenges/detail.jsp +++ b/src/main/webapp/WEB-INF/jsp/challenges/detail.jsp @@ -12,6 +12,7 @@ + diff --git a/src/main/webapp/WEB-INF/jsp/challenges/list.jsp b/src/main/webapp/WEB-INF/jsp/challenges/list.jsp index b4feee8..33f6c69 100644 --- a/src/main/webapp/WEB-INF/jsp/challenges/list.jsp +++ b/src/main/webapp/WEB-INF/jsp/challenges/list.jsp @@ -12,6 +12,7 @@ + diff --git a/src/main/webapp/WEB-INF/jsp/drill/solve.jsp b/src/main/webapp/WEB-INF/jsp/drill/solve.jsp index cf6d124..b5510d8 100644 --- a/src/main/webapp/WEB-INF/jsp/drill/solve.jsp +++ b/src/main/webapp/WEB-INF/jsp/drill/solve.jsp @@ -12,7 +12,6 @@ - diff --git a/src/main/webapp/WEB-INF/jsp/header.jsp b/src/main/webapp/WEB-INF/jsp/header.jsp index c07ff28..c5527b3 100644 --- a/src/main/webapp/WEB-INF/jsp/header.jsp +++ b/src/main/webapp/WEB-INF/jsp/header.jsp @@ -7,17 +7,6 @@ <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - - - - - - Drill Queue - - - - -
@@ -38,22 +27,19 @@ Challenges
  • - + Coding
  • - +
    diff --git a/src/main/webapp/WEB-INF/jsp/home.jsp b/src/main/webapp/WEB-INF/jsp/home.jsp index e469321..c3fdb53 100644 --- a/src/main/webapp/WEB-INF/jsp/home.jsp +++ b/src/main/webapp/WEB-INF/jsp/home.jsp @@ -11,9 +11,8 @@ - - + diff --git a/src/main/webapp/WEB-INF/jsp/practice/index.jsp b/src/main/webapp/index.jsp similarity index 100% rename from src/main/webapp/WEB-INF/jsp/practice/index.jsp rename to src/main/webapp/index.jsp