package kr.wisestone.owl.util;
|
|
import kr.wisestone.owl.vo.UserVo;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
public class ElasticSearchUtil {
|
|
// 사용자 이력 정보를 만들어 낸다.
|
public static String makeUserActiveHistoryMessage(UserVo userVo, String actionType) {
|
StringBuilder stringBuilder = new StringBuilder();
|
stringBuilder.append("[USER_ACTIVE_HISTORY] ");
|
// 액션 유형
|
stringBuilder.append("[");
|
stringBuilder.append(actionType);
|
stringBuilder.append("] ");
|
// 사용자 정보를 추출해서 문자열로 만든다.
|
makeUserInfo(userVo, stringBuilder, true);
|
|
return stringBuilder.toString();
|
}
|
|
// 사용자 정보를 추출해서 문자열로 만든다.
|
private static void makeUserInfo(UserVo userVo, StringBuilder stringBuilder, boolean decrypt) {
|
// 사용자 아이디
|
stringBuilder.append("[");
|
stringBuilder.append(userVo.getId());
|
stringBuilder.append("] ");
|
// 사용자 이름
|
stringBuilder.append("[");
|
stringBuilder.append(userVo.getName());
|
stringBuilder.append("] ");
|
// 사용자 계정
|
stringBuilder.append("[");
|
// 암호화 되어있을 경우 복호화 한다.
|
if (decrypt) {
|
stringBuilder.append(CommonUtil.decryptAES128(userVo.getAccount()));
|
}
|
else {
|
stringBuilder.append(userVo.getAccount());
|
}
|
|
stringBuilder.append("] ");
|
}
|
|
// 사용자의 시스템 사용 이력을 저장한다.
|
public static String makeUserSessionHistoryMessage(HttpServletRequest httpServletRequest, UserVo userVo) {
|
String agent = httpServletRequest.getHeader("User-Agent").toUpperCase();
|
String browser = null;
|
String os = null;
|
|
if (agent.contains("TRIDENT")) {
|
browser = "MSIE";
|
} else if (agent.contains("CHROME")) {
|
browser = "Chrome";
|
} else if (agent.contains("OPERA")) {
|
browser = "Opera";
|
} else if (agent.contains("SAFARI")) {
|
browser = "Safari";
|
}
|
else if (agent.contains("IPHONE") && agent.contains("MOBILE")) {
|
browser = "iPhone";
|
} else if (agent.contains("ANDROID") && agent.contains("MOBILE")) {
|
browser = "Android";
|
}
|
|
if (agent.contains("WINDOWS")) {
|
os = "Windows";
|
} else if (agent.contains("LINUX")) {
|
os = "Linux";
|
} else if (agent.contains("MACINTOSH")) {
|
os = "Macintosh";
|
} else if (agent.contains("MAC")) {
|
os = "Mac";
|
}
|
|
boolean mobile = agent.matches(".*(IPHONE|IPAD|IPOD|ANDROID|WINDOWS CE|BLACKBERRY|SYMBIAN|WINDOWS PHONE|WEBOS|OPERA MINI|" +
|
"OPERA MOBI|POLARIS|IEMOBILE|LGTELCOM|NOKIA|SONYERICSSON|LG|SAMSUNG).*");
|
|
String ip = httpServletRequest.getHeader("X-FORWARDED-FOR");
|
|
if (ip == null) {
|
ip = httpServletRequest.getRemoteAddr();
|
}
|
|
StringBuilder stringBuilder = new StringBuilder();
|
stringBuilder.append("[USER_SESSION_HISTORY] ");
|
// 접속 브라우저 정보
|
stringBuilder.append("[");
|
stringBuilder.append(browser);
|
stringBuilder.append("] ");
|
// 운영체제 정보
|
stringBuilder.append("[");
|
stringBuilder.append(os);
|
stringBuilder.append("] ");
|
// 모바일 접속 여부
|
stringBuilder.append("[");
|
stringBuilder.append(mobile);
|
stringBuilder.append("] ");
|
// 아이피 정보
|
stringBuilder.append("[");
|
stringBuilder.append(ip);
|
stringBuilder.append("] ");
|
// 사용자 정보를 추출해서 문자열로 만든다.
|
makeUserInfo(userVo, stringBuilder, false);
|
|
return stringBuilder.toString();
|
}
|
}
|