From 51fb8f23e45717c9252eebec1678bcade5df73e9 Mon Sep 17 00:00:00 2001 From: wenshao Date: Thu, 23 Aug 2012 20:17:27 +0800 Subject: [PATCH] refactor login --- .../druid/support/http/StatViewServlet.java | 65 ++++++++++--------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/alibaba/druid/support/http/StatViewServlet.java b/src/main/java/com/alibaba/druid/support/http/StatViewServlet.java index a38e3a81b6..89439e1d86 100644 --- a/src/main/java/com/alibaba/druid/support/http/StatViewServlet.java +++ b/src/main/java/com/alibaba/druid/support/http/StatViewServlet.java @@ -191,42 +191,47 @@ public class StatViewServlet extends HttpServlet { if (username.equals(_username) && password.equals(_password)) { request.getSession().setAttribute(SESSION_USER_KEY, username); response.getWriter().print("success"); - } else response.getWriter().print("error"); - } else if (session.getAttribute(SESSION_USER_KEY) == null - && !("/login.html".equals(path) || path.startsWith("/css") || path.startsWith("/js"))) { + } else { + response.getWriter().print("error"); + } + return; + } + + if (isRequireAuth() && session.getAttribute(SESSION_USER_KEY) == null + && !("/login.html".equals(path) || path.startsWith("/css") || path.startsWith("/js"))) { if (contextPath == null || contextPath.equals("") || contextPath.equals("/")) { response.sendRedirect("/login.html"); } else { response.sendRedirect("login.html"); } - } else { - - if ("".equals(path)) { - if (contextPath == null || contextPath.equals("") || contextPath.equals("/")) { - response.sendRedirect("/druid/index.html"); - } else { - response.sendRedirect("druid/index.html"); - } - return; - } - - if ("/".equals(path)) { - response.sendRedirect("index.html"); - return; - } - - if (path.indexOf(".json") >= 0) { - String fullUrl = path; - if (request.getQueryString() != null && request.getQueryString().length() > 0) { - fullUrl += "?" + request.getQueryString(); - } - response.getWriter().print(statService.service(fullUrl)); - return; - } - - // find file in resources path - returnResourceFile(path, uri, response); + return; } + + if ("".equals(path)) { + if (contextPath == null || contextPath.equals("") || contextPath.equals("/")) { + response.sendRedirect("/druid/index.html"); + } else { + response.sendRedirect("druid/index.html"); + } + return; + } + + if ("/".equals(path)) { + response.sendRedirect("index.html"); + return; + } + + if (path.indexOf(".json") >= 0) { + String fullUrl = path; + if (request.getQueryString() != null && request.getQueryString().length() > 0) { + fullUrl += "?" + request.getQueryString(); + } + response.getWriter().print(statService.service(fullUrl)); + return; + } + + // find file in resources path + returnResourceFile(path, uri, response); } private void returnResourceFile(String fileName, String uri, HttpServletResponse response) throws ServletException,