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 @@