You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
3.3 KiB
79 lines
3.3 KiB
3 years ago
|
package com.fr.plugin;
|
||
|
|
||
|
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider;
|
||
|
import com.fr.decision.webservice.v10.login.LoginService;
|
||
|
import com.fr.json.JSONObject;
|
||
|
import com.fr.log.FineLoggerFactory;
|
||
|
import com.fr.plugin.beans.UserLogBean;
|
||
|
import com.fr.plugin.entitys.RelationLogEntity;
|
||
|
import com.fr.stable.StringUtils;
|
||
|
|
||
|
import javax.servlet.FilterChain;
|
||
|
import javax.servlet.http.HttpServletRequest;
|
||
|
import javax.servlet.http.HttpServletResponse;
|
||
|
import java.util.stream.Collectors;
|
||
|
|
||
|
public class LogMacFilter extends AbstractGlobalRequestFilterProvider {
|
||
|
@Override
|
||
|
public String filterName() {
|
||
|
return "logMac";
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String[] urlPatterns() {
|
||
|
return new String[]{
|
||
|
"/decision/login",
|
||
|
"/decision/v10/entry/access/*"
|
||
|
};
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain filterChain) {
|
||
|
try {
|
||
|
MultiReadHttpServletRequest request = new MultiReadHttpServletRequest(req);
|
||
|
LogMacFunction myFunction = new LogMacFunction();
|
||
|
String uri = req.getRequestURI();
|
||
|
if (uri.contains("v10/entry/access")) {
|
||
|
String terminal = req.getHeader("terminal");
|
||
|
String op = req.getParameter("op");
|
||
|
String cmd = req.getParameter("cmd");
|
||
|
if ("APP".equals(terminal) && StringUtils.equals(op, "fs_main") && StringUtils.equals(cmd, "entry_report")) {
|
||
|
String name = LoginService.getInstance().getCurrentUserNameFromRequest(request);
|
||
|
RelationLogEntity relation = myFunction.findRelation(name);
|
||
|
if (relation != null) {
|
||
|
myFunction.addLoginHistory(relation);
|
||
|
FineLoggerFactory.getLogger().info("login app access log success " + relation.getUserName() + " " + relation.getMacAddr());
|
||
|
} else {
|
||
|
FineLoggerFactory.getLogger().info("login not find mac relation");
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
|
if ("POST".equalsIgnoreCase(req.getMethod())) {
|
||
|
String terminal = req.getHeader("terminal");
|
||
|
if ("APP".equals(terminal)) {
|
||
|
String body = request.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
|
||
|
JSONObject json = new JSONObject(body);
|
||
|
UserLogBean bean = new UserLogBean();
|
||
|
if (json.has("username")) {
|
||
|
bean.setName(json.getString("username"));
|
||
|
}
|
||
|
if (json.has("deviceName")) {
|
||
|
bean.setDeviceName(json.getString("deviceName"));
|
||
|
}
|
||
|
if (json.has("macAddress")) {
|
||
|
bean.setMac(json.getString("macAddress"));
|
||
|
}
|
||
|
|
||
|
myFunction.save(bean);
|
||
|
}
|
||
|
FineLoggerFactory.getLogger().info("login with" + req.getHeaderNames());
|
||
|
}
|
||
|
}
|
||
|
filterChain.doFilter(request, res);
|
||
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e);
|
||
|
}
|
||
|
}
|
||
|
}
|