OWL ITS + 탐지시스템(인터넷 진흥원)
이민희
2022-01-13 4545664bbece1b1b185945376b344b1660669a53
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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();
    }
}