commit | author | age
|
9bcb19
|
1 |
/* |
I |
2 |
Copyright [2020] [https://www.xiaonuo.vip] |
|
3 |
|
|
4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
you may not use this file except in compliance with the License. |
|
6 |
You may obtain a copy of the License at |
|
7 |
|
|
8 |
http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
|
|
10 |
Unless required by applicable law or agreed to in writing, software |
|
11 |
distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
See the License for the specific language governing permissions and |
|
14 |
limitations under the License. |
|
15 |
|
|
16 |
Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: |
|
17 |
|
|
18 |
1.请不要删除和修改根目录下的LICENSE文件。 |
|
19 |
2.请不要删除和修改Snowy源码头部的版权声明。 |
|
20 |
3.请保留源码和相关描述文件的项目出处,作者声明等。 |
|
21 |
4.分发源码时候,请注明软件出处 https://gitee.com/xiaonuobase/snowy |
|
22 |
5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy |
|
23 |
6.若您的项目无法满足以上几点,可申请商业授权,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip |
|
24 |
*/ |
|
25 |
package vip.xiaonuo.sys.core.log.factory; |
|
26 |
|
|
27 |
import cn.hutool.core.date.DateTime; |
|
28 |
import org.aspectj.lang.JoinPoint; |
|
29 |
import vip.xiaonuo.core.annotion.BusinessLog; |
|
30 |
import vip.xiaonuo.core.consts.SymbolConstant; |
|
31 |
import vip.xiaonuo.core.context.constant.ConstantContextHolder; |
|
32 |
import vip.xiaonuo.core.util.CryptogramUtil; |
|
33 |
import vip.xiaonuo.core.util.JoinPointUtil; |
|
34 |
import vip.xiaonuo.sys.core.enums.LogSuccessStatusEnum; |
|
35 |
import vip.xiaonuo.sys.core.enums.VisLogTypeEnum; |
|
36 |
import vip.xiaonuo.sys.modular.log.entity.SysOpLog; |
|
37 |
import vip.xiaonuo.sys.modular.log.entity.SysVisLog; |
|
38 |
|
|
39 |
import java.util.Arrays; |
|
40 |
|
|
41 |
/** |
|
42 |
* 日志对象创建工厂 |
|
43 |
* |
|
44 |
* @author xuyuxiang |
|
45 |
* @date 2020/3/12 14:31 |
|
46 |
*/ |
|
47 |
public class LogFactory { |
|
48 |
|
|
49 |
/** |
|
50 |
* 创建登录日志 |
|
51 |
* |
|
52 |
* @author xuyuxiang |
|
53 |
* @date 2020/3/12 16:09 |
|
54 |
*/ |
|
55 |
static void createSysLoginLog(SysVisLog sysVisLog, String account, String successCode, String failMessage) { |
|
56 |
sysVisLog.setName(VisLogTypeEnum.LOGIN.getMessage()); |
|
57 |
sysVisLog.setSuccess(successCode); |
|
58 |
|
|
59 |
sysVisLog.setVisType(VisLogTypeEnum.LOGIN.getCode()); |
|
60 |
sysVisLog.setVisTime(DateTime.now()); |
|
61 |
sysVisLog.setAccount(account); |
|
62 |
|
|
63 |
if (LogSuccessStatusEnum.SUCCESS.getCode().equals(successCode)) { |
|
64 |
sysVisLog.setMessage(VisLogTypeEnum.LOGIN.getMessage() + LogSuccessStatusEnum.SUCCESS.getMessage()); |
|
65 |
} |
|
66 |
if (LogSuccessStatusEnum.FAIL.getCode().equals(successCode)) { |
|
67 |
sysVisLog.setMessage(VisLogTypeEnum.LOGIN.getMessage() + |
|
68 |
LogSuccessStatusEnum.FAIL.getMessage() + SymbolConstant.COLON + failMessage); |
|
69 |
} |
|
70 |
if (ConstantContextHolder.getCryptogramConfigs().getVisLogEnc()) { |
|
71 |
SysVisLogSign(sysVisLog); |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 |
/** |
|
76 |
* 创建登出日志 |
|
77 |
* |
|
78 |
* @author xuyuxiang |
|
79 |
* @date 2020/3/12 16:09 |
|
80 |
*/ |
|
81 |
static void createSysExitLog(SysVisLog sysVisLog, String account) { |
|
82 |
sysVisLog.setName(VisLogTypeEnum.EXIT.getMessage()); |
|
83 |
sysVisLog.setSuccess(LogSuccessStatusEnum.SUCCESS.getCode()); |
|
84 |
sysVisLog.setMessage(VisLogTypeEnum.EXIT.getMessage() + LogSuccessStatusEnum.SUCCESS.getMessage()); |
|
85 |
sysVisLog.setVisType(VisLogTypeEnum.EXIT.getCode()); |
|
86 |
sysVisLog.setVisTime(DateTime.now()); |
|
87 |
sysVisLog.setAccount(account); |
|
88 |
if (ConstantContextHolder.getCryptogramConfigs().getVisLogEnc()) { |
|
89 |
SysVisLogSign(sysVisLog); |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 |
* 创建操作日志 |
|
95 |
* |
|
96 |
* @author xuyuxiang |
|
97 |
* @date 2020/3/12 16:09 |
|
98 |
*/ |
|
99 |
static void createSysOperationLog(SysOpLog sysOpLog, String account, BusinessLog businessLog, JoinPoint joinPoint, String result) { |
|
100 |
fillCommonSysOpLog(sysOpLog, account, businessLog, joinPoint); |
|
101 |
sysOpLog.setSuccess(LogSuccessStatusEnum.SUCCESS.getCode()); |
|
102 |
sysOpLog.setResult(result); |
|
103 |
sysOpLog.setMessage(LogSuccessStatusEnum.SUCCESS.getMessage()); |
|
104 |
if (ConstantContextHolder.getCryptogramConfigs().getOpLogEnc()) { |
|
105 |
SysOpLogSign(sysOpLog); |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* 创建异常日志 |
|
111 |
* |
|
112 |
* @author xuyuxiang |
|
113 |
* @date 2020/3/16 17:18 |
|
114 |
*/ |
|
115 |
static void createSysExceptionLog(SysOpLog sysOpLog, String account, BusinessLog businessLog, JoinPoint joinPoint, Exception exception) { |
|
116 |
fillCommonSysOpLog(sysOpLog, account, businessLog, joinPoint); |
|
117 |
sysOpLog.setSuccess(LogSuccessStatusEnum.FAIL.getCode()); |
|
118 |
sysOpLog.setMessage(Arrays.toString(exception.getStackTrace())); |
|
119 |
if (ConstantContextHolder.getCryptogramConfigs().getOpLogEnc()) { |
|
120 |
SysOpLogSign(sysOpLog); |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* 生成通用操作日志字段 |
|
126 |
* |
|
127 |
* @author xuyuxiang |
|
128 |
* @date 2020/3/16 17:20 |
|
129 |
*/ |
|
130 |
private static void fillCommonSysOpLog(SysOpLog sysOpLog, String account, BusinessLog businessLog, JoinPoint joinPoint) { |
|
131 |
String className = joinPoint.getTarget().getClass().getName(); |
|
132 |
|
|
133 |
String methodName = joinPoint.getSignature().getName(); |
|
134 |
|
|
135 |
String param = JoinPointUtil.getArgsJsonString(joinPoint); |
|
136 |
|
|
137 |
sysOpLog.setName(businessLog.title()); |
|
138 |
sysOpLog.setOpType(businessLog.opType().ordinal()); |
|
139 |
sysOpLog.setClassName(className); |
|
140 |
sysOpLog.setMethodName(methodName); |
|
141 |
sysOpLog.setParam(param); |
|
142 |
sysOpLog.setOpTime(DateTime.now()); |
|
143 |
sysOpLog.setAccount(account); |
|
144 |
} |
|
145 |
|
|
146 |
/** |
|
147 |
* 构建基础访问日志 |
|
148 |
* |
|
149 |
* @author xuyuxiang |
|
150 |
* @date 2020/3/19 14:36 |
|
151 |
*/ |
|
152 |
public static SysVisLog genBaseSysVisLog(String ip, String location, String browser, String os) { |
|
153 |
SysVisLog sysVisLog = new SysVisLog(); |
|
154 |
sysVisLog.setIp(ip); |
|
155 |
sysVisLog.setLocation(location); |
|
156 |
sysVisLog.setBrowser(browser); |
|
157 |
sysVisLog.setOs(os); |
|
158 |
return sysVisLog; |
|
159 |
} |
|
160 |
|
|
161 |
/** |
|
162 |
* 构建基础操作日志 |
|
163 |
* |
|
164 |
* @author xuyuxiang |
|
165 |
* @date 2020/3/19 14:36 |
|
166 |
*/ |
|
167 |
public static SysOpLog genBaseSysOpLog(String ip, String location, String browser, String os, String url, String method) { |
|
168 |
SysOpLog sysOpLog = new SysOpLog(); |
|
169 |
sysOpLog.setIp(ip); |
|
170 |
sysOpLog.setLocation(location); |
|
171 |
sysOpLog.setBrowser(browser); |
|
172 |
sysOpLog.setOs(os); |
|
173 |
sysOpLog.setUrl(url); |
|
174 |
sysOpLog.setReqMethod(method); |
|
175 |
return sysOpLog; |
|
176 |
} |
|
177 |
|
|
178 |
/** |
|
179 |
* 构建登录登出日志完整性保护(数据签名) |
|
180 |
*/ |
|
181 |
private static SysVisLog SysVisLogSign (SysVisLog sysVisLog) { |
|
182 |
String sysVisLogStr = sysVisLog.toString().replaceAll(" +",""); |
|
183 |
sysVisLog.setSignValue(CryptogramUtil.doSignature(sysVisLogStr)); |
|
184 |
return sysVisLog; |
|
185 |
} |
|
186 |
|
|
187 |
/** |
|
188 |
* 构建操作日志完整性保护(摘要) |
|
189 |
*/ |
|
190 |
private static SysOpLog SysOpLogSign (SysOpLog sysOpLog) { |
|
191 |
String sysVisLogStr = sysOpLog.toString(); |
|
192 |
sysOpLog.setSignValue(CryptogramUtil.doHashValue(sysVisLogStr)); |
|
193 |
return sysOpLog; |
|
194 |
} |
|
195 |
|
|
196 |
} |