测试用户
2023-04-13 43393f2bb11cbf9e6af40077bbc5284660e8a754
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.common.servlet;
 
import com.alibaba.druid.support.http.StatViewServlet;
import com.jfinal.plugin.druid.IDruidStatViewAuth;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
 
 
/**
 * @author 廖振钦
 * @date 2022-01-17
 */
@WebServlet
public class JFinalStatViewServlet extends StatViewServlet {
    private static final long serialVersionUID = 2898674199964021798L;
 
    private IDruidStatViewAuth auth = new IDruidStatViewAuth(){
        public boolean isPermitted(HttpServletRequest request) {
            return true;
        }
    };
 
    private String visitPath = "/admin/druid/monitor";
 
    public JFinalStatViewServlet() {
    }
 
    public boolean isPermittedRequest(HttpServletRequest request) {
        return this.auth.isPermitted(request);
    }
 
    public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String contextPath = request.getContextPath();
        String requestURI = request.getRequestURI();
        response.setCharacterEncoding("utf-8");
        if (contextPath == null) {
            contextPath = "";
        }
 
        int index = contextPath.length() + this.visitPath.length();
        String uri = requestURI.substring(0, index);
        String path = requestURI.substring(index);
        if (!this.isPermittedRequest(request)) {
            path = "/nopermit.html";
            this.returnResourceFile(path, uri, response);
        } else {
            String fullUrl;
            if ("/submitLogin".equals(path)) {
                fullUrl = request.getParameter("loginUsername");
                String passwordParam = request.getParameter("loginPassword");
                response.getWriter().print("success");
//                if (this.handler.username.equals(fullUrl) && this.handler.password.equals(passwordParam)) {
//                    request.getSession().setAttribute("druid-user", this.handler.username);
//                    response.getWriter().print("success");
//                } else {
//                    response.getWriter().print("error");
//                }
 
            } else if (this.isRequireAuth() && !this.ContainsUser(request) && !"/login.html".equals(path) && !path.startsWith("/css") && !path.startsWith("/js") && !path.startsWith("/img")) {
                if (contextPath != null && !contextPath.equals("") && !contextPath.equals("/")) {
                    if ("".equals(path)) {
                        response.sendRedirect("druid/login.html");
                    } else {
                        response.sendRedirect("login.html");
                    }
                } else {
                    response.sendRedirect("/druid/login.html");
                }
 
            } else if (!"".equals(path)) {
                if ("/".equals(path)) {
                    response.sendRedirect("index.html");
                } else if (path.indexOf(".json") >= 0) {
                    fullUrl = path;
                    if (request.getQueryString() != null && request.getQueryString().length() > 0) {
                        fullUrl = path + "?" + request.getQueryString();
                    }
 
                    response.getWriter().print(this.process(fullUrl));
                } else {
                    this.returnResourceFile(path, uri, response);
                }
            } else {
                if (contextPath != null && !contextPath.equals("") && !contextPath.equals("/")) {
                    response.sendRedirect("druid/index.html");
                } else {
                    response.sendRedirect("/druid/index.html");
                }
 
            }
        }
    }
}