package com.wgcloud.filter;
|
|
|
import com.wgcloud.config.CommonConfig;
|
import com.wgcloud.entity.AccountInfo;
|
import com.wgcloud.util.staticvar.StaticKeys;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import javax.servlet.*;
|
import javax.servlet.annotation.WebFilter;
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpSession;
|
import java.io.IOException;
|
|
/**
|
* http请求过滤器,拦截不是从路由过来的请求
|
*
|
* @author wgcloud
|
*/
|
@WebFilter(filterName = "authRestFilter", urlPatterns = {"/*"})
|
public class AuthRestFilter implements Filter {
|
|
static Logger log = LoggerFactory.getLogger(AuthRestFilter.class);
|
|
@Autowired
|
CommonConfig commonConfig;
|
|
//静态资源和不需要登录的URL
|
String[] static_resource = {"/fileSafe/agentList", "/shellInfo/agentList", "/shellInfo/shellCallback", "/fileWarnInfo/agentStateListList", "/fileWarnInfo/agentList", "/heathMonitor/agentList", "/dbTable/agentList",
|
"/systemInfoOpen/", "/systemInfo/agentList", "/agentLogGo/minTask", "/agentGo/minTask", "/agentDiskGo/minTask", "/dceInfo/agentList",
|
"/login/toLogin", "/login/login", "/appInfo/agentList", "/dockerInfo/agentList", "/portInfo/agentList", "/license/",
|
"/static/", "/resources/", "/log/agentList", "/customInfo/agentList", "/agentCustomGo/minTask", "/dbInfo/agentList", "/agentDbTableGo/minTask",
|
"/agentHeathMonitorGo/minTask", "/agentDceInfoGo/minTask", "/agentSnmpInfoGo/minTask", "/snmpInfo/agentList"};
|
|
|
//公众看板URL
|
String[] dash_views = {"/dash/main", "/systemInfo/systemInfoList", "/systemInfo/systemInfoListAjax", "/systemInfo/detail", "/systemInfo/chart", "/warnInfo/warnCountAjax"};
|
|
//大屏URL
|
String[] daping_views = {"/daping/index", "/dapingNew/index"};
|
|
//只读账号不能进行的操作
|
String[] guest_no_views = {"/del", "/save", "/edit", "/editBatch"};
|
|
@Override
|
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
final HttpServletResponse response = (HttpServletResponse) servletResponse;
|
final HttpServletRequest request = (HttpServletRequest) servletRequest;
|
final HttpSession session = request.getSession();
|
AccountInfo accountInfo = (AccountInfo) session.getAttribute(StaticKeys.LOGIN_KEY);
|
String uri = request.getRequestURI();
|
log.debug("uri----" + uri);
|
String servletPath = request.getServletPath();
|
log.debug("servletPath----" + servletPath);
|
menuActive(session, uri);
|
|
//已登陆,跳转到index begin
|
if (accountInfo != null && (servletPath.startsWith("/login/toLogin") || uri.endsWith("tssw/") || uri.endsWith("tssw"))) {
|
response.sendRedirect("/tssw/dash/main");
|
return;
|
}
|
//已登陆,跳转到index end
|
|
//只读账号已登陆,校验是否是非法操作 begin
|
//是非法操作直接跳转到错误页面
|
if (accountInfo != null && StaticKeys.ROLE_GUEST.equals(accountInfo.getRole())) {
|
for (String ss : guest_no_views) {
|
if (servletPath.endsWith(ss)) {
|
response.sendRedirect("/tssw/common/error/guestError");
|
return;
|
}
|
}
|
}
|
//只读账号已登陆,校验是否是非法操作 end
|
|
//静态资源过滤 begin
|
for (String ss : static_resource) {
|
if (servletPath.startsWith(ss)) {
|
filterChain.doFilter(servletRequest, servletResponse);
|
return;
|
}
|
}
|
//静态资源过滤 end
|
|
//公众看板处理 begin
|
if (accountInfo == null) {
|
for (String ss : dash_views) {
|
if (servletPath.startsWith(ss) && StaticKeys.TRUE_VAL.equals(commonConfig.getDashView()) && request.getParameter(StaticKeys.DASH_VIEW_ACCOUNT) != null) {
|
filterChain.doFilter(servletRequest, servletResponse);
|
return;
|
}
|
}
|
}
|
//公众看板处理 end
|
|
//大屏看板处理 begin
|
if (accountInfo == null) {
|
for (String ss : daping_views) {
|
if (servletPath.startsWith(ss) && StaticKeys.TRUE_VAL.equals(commonConfig.getDapingView())) {
|
filterChain.doFilter(servletRequest, servletResponse);
|
return;
|
}
|
}
|
}
|
//大屏看板处理 end
|
|
//未登录跳转到登陆页面 begin
|
if (accountInfo == null) {
|
response.sendRedirect("/tssw/login/toLogin");
|
return;
|
}
|
//未登录跳转到登陆页面 end
|
|
filterChain.doFilter(servletRequest, servletResponse);
|
}
|
|
|
/**
|
* 添加菜单标识
|
*
|
* @param session
|
* @param uri
|
*/
|
public void menuActive(HttpSession session, String uri) {
|
if (uri.indexOf("/log/") > -1) {
|
session.setAttribute("menuActive", "21");
|
return;
|
}
|
if (uri.indexOf("/dash/main") > -1) {
|
session.setAttribute("menuActive", "01");
|
return;
|
}
|
if (uri.indexOf("/systemInfo/systemInfoList") > -1 || uri.indexOf("/systemInfo/detail") > -1 || uri.indexOf("/systemInfo/chart") > -1 || uri.indexOf("/dash/hostDraw") > -1) {
|
session.setAttribute("menuActive", "12");
|
return;
|
}
|
if (uri.indexOf("/appInfo") > -1) {
|
session.setAttribute("menuActive", "13");
|
return;
|
}
|
if (uri.indexOf("/dockerInfo") > -1) {
|
session.setAttribute("menuActive", "14");
|
return;
|
}
|
if (uri.indexOf("/portInfo") > -1) {
|
session.setAttribute("menuActive", "15");
|
return;
|
}
|
if (uri.indexOf("/fileWarnInfo") > -1) {
|
session.setAttribute("menuActive", "16");
|
return;
|
}
|
if (uri.indexOf("/fileSafe") > -1) {
|
session.setAttribute("menuActive", "17");
|
return;
|
}
|
if (uri.indexOf("/customInfo") > -1) {
|
session.setAttribute("menuActive", "18");
|
return;
|
}
|
if (uri.indexOf("/mailset") > -1) {
|
session.setAttribute("menuActive", "22");
|
return;
|
}
|
if (uri.indexOf("/shellInfo") > -1) {
|
session.setAttribute("menuActive", "23");
|
return;
|
}
|
if (uri.indexOf("/hostGroup") > -1) {
|
session.setAttribute("menuActive", "24");
|
return;
|
}
|
if (uri.indexOf("/accountInfo") > -1) {
|
session.setAttribute("menuActive", "25");
|
return;
|
}
|
if (uri.indexOf("/dbInfo") > -1) {
|
session.setAttribute("menuActive", "41");
|
return;
|
}
|
if (uri.indexOf("/dbTable") > -1) {
|
session.setAttribute("menuActive", "42");
|
return;
|
}
|
if (uri.indexOf("/heathMonitor") > -1) {
|
session.setAttribute("menuActive", "51");
|
return;
|
}
|
if (uri.indexOf("/dceInfo") > -1) {
|
session.setAttribute("menuActive", "61");
|
return;
|
}
|
if (uri.indexOf("/snmpInfo") > -1) {
|
session.setAttribute("menuActive", "62");
|
return;
|
}
|
if (uri.indexOf("/tuopu/tuopuListHost") > -1) {
|
session.setAttribute("menuActive", "71");
|
return;
|
}
|
if (uri.indexOf("/tuopu/tuopuListSt") > -1) {
|
session.setAttribute("menuActive", "72");
|
return;
|
}
|
if (uri.indexOf("/equipment") > -1) {
|
session.setAttribute("menuActive", "81");
|
return;
|
}
|
if (uri.indexOf("/report") > -1) {
|
session.setAttribute("menuActive", "91");
|
return;
|
}
|
session.setAttribute("menuActive", "11");
|
return;
|
|
}
|
|
}
|