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");
|
}
|
|
}
|
}
|
}
|
}
|