|
@@ -2,11 +2,13 @@ package com.yohoufo.common.interceptor; |
|
@@ -2,11 +2,13 @@ package com.yohoufo.common.interceptor; |
2
|
|
2
|
|
3
|
import com.alibaba.fastjson.JSON;
|
3
|
import com.alibaba.fastjson.JSON;
|
4
|
import com.yoho.core.config.ConfigReader;
|
4
|
import com.yoho.core.config.ConfigReader;
|
|
|
5
|
+import com.yoho.core.rabbitmq.YhProducer;
|
5
|
import com.yoho.core.redis.cluster.annotation.Redis;
|
6
|
import com.yoho.core.redis.cluster.annotation.Redis;
|
6
|
import com.yoho.core.redis.cluster.operations.nosync.YHValueOperations;
|
7
|
import com.yoho.core.redis.cluster.operations.nosync.YHValueOperations;
|
7
|
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
8
|
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
8
|
import com.yoho.core.rest.client.ServiceCaller;
|
9
|
import com.yoho.core.rest.client.ServiceCaller;
|
9
|
import com.yoho.error.event.LogEvent;
|
10
|
import com.yoho.error.event.LogEvent;
|
|
|
11
|
+import com.yoho.service.model.request.SessionFailedBO;
|
10
|
import com.yoho.service.model.request.UserSessionReqBO;
|
12
|
import com.yoho.service.model.request.UserSessionReqBO;
|
11
|
import com.yohoufo.common.annotation.IgnoreSession;
|
13
|
import com.yohoufo.common.annotation.IgnoreSession;
|
12
|
import com.yohoufo.common.exception.GatewayException;
|
14
|
import com.yohoufo.common.exception.GatewayException;
|
|
@@ -71,6 +73,11 @@ public class SecurityInterceptor implements HandlerInterceptor, ApplicationEvent |
|
@@ -71,6 +73,11 @@ public class SecurityInterceptor implements HandlerInterceptor, ApplicationEvent |
71
|
|
73
|
|
72
|
private ApplicationEventPublisher publisher;
|
74
|
private ApplicationEventPublisher publisher;
|
73
|
|
75
|
|
|
|
76
|
+ @Resource(name="ufoExpressInfoProducer")
|
|
|
77
|
+ YhProducer yhProducer;
|
|
|
78
|
+
|
|
|
79
|
+ private static final String SESSION_FAIL_TOPIC = "uic.sessionFail";
|
|
|
80
|
+
|
74
|
@Override
|
81
|
@Override
|
75
|
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
|
82
|
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
|
76
|
|
83
|
|
|
@@ -100,6 +107,7 @@ public class SecurityInterceptor implements HandlerInterceptor, ApplicationEvent |
|
@@ -100,6 +107,7 @@ public class SecurityInterceptor implements HandlerInterceptor, ApplicationEvent |
100
|
String method = params.get("method");
|
107
|
String method = params.get("method");
|
101
|
String uid = params.get("uid");
|
108
|
String uid = params.get("uid");
|
102
|
String appVersion = params.get("app_version");
|
109
|
String appVersion = params.get("app_version");
|
|
|
110
|
+ String businessLine = params.get("business_line");
|
103
|
//==============以下是完全不校验的场景=========================
|
111
|
//==============以下是完全不校验的场景=========================
|
104
|
|
112
|
|
105
|
//2 是否校验全部接口,开关-true:校验全部接口(除去@IgnoreSession注解接口) 开关-false:只校验核心接口
|
113
|
//2 是否校验全部接口,开关-true:校验全部接口(除去@IgnoreSession注解接口) 开关-false:只校验核心接口
|
|
@@ -140,7 +148,8 @@ public class SecurityInterceptor implements HandlerInterceptor, ApplicationEvent |
|
@@ -140,7 +148,8 @@ public class SecurityInterceptor implements HandlerInterceptor, ApplicationEvent |
140
|
//6 如果cookie中没有jSessionID , 但接口又必须校验会话, 则返回 HTTP 401, 需要重新登录.
|
148
|
//6 如果cookie中没有jSessionID , 但接口又必须校验会话, 则返回 HTTP 401, 需要重新登录.
|
141
|
if (jSessionID == null) {
|
149
|
if (jSessionID == null) {
|
142
|
logger.warn("check session failed, can not find session id in cookies, check session info failed, method {}, uid {}, appVersion is {}, clientType is {}, sessionType is {}", method, uid, appVersion, clientType, sessionType);
|
150
|
logger.warn("check session failed, can not find session id in cookies, check session info failed, method {}, uid {}, appVersion is {}, clientType is {}, sessionType is {}", method, uid, appVersion, clientType, sessionType);
|
143
|
- this.verifyFailReport(uid, method, clientType);
|
151
|
+ //this.verifyFailReport(uid, method, clientType);
|
|
|
152
|
+ this.verifyFailReport(uid, method, clientType,null, null, getIP(httpServletRequest), appVersion, businessLine ,sessionType,0);
|
144
|
throw new SessionExpireException(); //重新登录
|
153
|
throw new SessionExpireException(); //重新登录
|
145
|
}
|
154
|
}
|
146
|
|
155
|
|
|
@@ -169,7 +178,8 @@ public class SecurityInterceptor implements HandlerInterceptor, ApplicationEvent |
|
@@ -169,7 +178,8 @@ public class SecurityInterceptor implements HandlerInterceptor, ApplicationEvent |
169
|
//9 校验SESSION, 校验不通过重新登录
|
178
|
//9 校验SESSION, 校验不通过重新登录
|
170
|
if (uid == null || sessionInfo == null || !StringUtils.equals(sessionInfo, uid)) {
|
179
|
if (uid == null || sessionInfo == null || !StringUtils.equals(sessionInfo, uid)) {
|
171
|
logger.warn("check session failed, session unmatched uid, session id {}, uid {} , session info {}, method {}, version is {}, clientType is {}, sessionType is {}", jSessionID, params.get("uid"), sessionInfo, method, appVersion, clientType, sessionType);
|
180
|
logger.warn("check session failed, session unmatched uid, session id {}, uid {} , session info {}, method {}, version is {}, clientType is {}, sessionType is {}", jSessionID, params.get("uid"), sessionInfo, method, appVersion, clientType, sessionType);
|
172
|
- this.verifyFailReport(uid, method, clientType);
|
181
|
+ //this.verifyFailReport(uid, method, clientType);
|
|
|
182
|
+ this.verifyFailReport(uid, method, clientType,jSessionID, sessionInfo, getIP(httpServletRequest), appVersion, businessLine ,sessionType,1);
|
173
|
throw new SessionExpireException(); //重新登录
|
183
|
throw new SessionExpireException(); //重新登录
|
174
|
}
|
184
|
}
|
175
|
}
|
185
|
}
|
|
@@ -194,15 +204,30 @@ public class SecurityInterceptor implements HandlerInterceptor, ApplicationEvent |
|
@@ -194,15 +204,30 @@ public class SecurityInterceptor implements HandlerInterceptor, ApplicationEvent |
194
|
* @param method
|
204
|
* @param method
|
195
|
* @param clientType
|
205
|
* @param clientType
|
196
|
*/
|
206
|
*/
|
197
|
- private void verifyFailReport(String uid, String method, String clientType){
|
207
|
+ private void verifyFailReport(String uid, String method, String clientType,String sessionKey,
|
|
|
208
|
+ String sessionInfo, String ip, String appVersion, String businessLine, String sessionType, int failType){
|
198
|
try{
|
209
|
try{
|
199
|
LogEvent logEvent = new LogEvent.Builder("sessionFail").addArg("uid", uid).addArg("method", method).addArg("clientType", clientType).build();
|
210
|
LogEvent logEvent = new LogEvent.Builder("sessionFail").addArg("uid", uid).addArg("method", method).addArg("clientType", clientType).build();
|
200
|
publisher.publishEvent(logEvent);
|
211
|
publisher.publishEvent(logEvent);
|
|
|
212
|
+ SessionFailedBO failedBO = new SessionFailedBO(uid,method, sessionKey, sessionInfo,ip, appVersion, businessLine, clientType,sessionType, getIntTime(),failType);
|
|
|
213
|
+ sendSessionFailMQ(SESSION_FAIL_TOPIC, failedBO);
|
201
|
}catch (Exception e){
|
214
|
}catch (Exception e){
|
202
|
logger.warn("verifyFailReport: report session verify event faild, uid is {}, method is {}, error is {}", uid, method, e);
|
215
|
logger.warn("verifyFailReport: report session verify event faild, uid is {}, method is {}, error is {}", uid, method, e);
|
203
|
}
|
216
|
}
|
204
|
}
|
217
|
}
|
205
|
|
218
|
|
|
|
219
|
+ private int getIntTime(){
|
|
|
220
|
+ return (int)(System.currentTimeMillis()/1000);
|
|
|
221
|
+ }
|
|
|
222
|
+
|
|
|
223
|
+ private void sendSessionFailMQ(String topic, SessionFailedBO failedBO){
|
|
|
224
|
+ try{
|
|
|
225
|
+ yhProducer.send(topic, failedBO);
|
|
|
226
|
+ logger.info("send sendSessionFailMQ success. topic is {}, param is {}", topic, failedBO);
|
|
|
227
|
+ }catch (Exception e){
|
|
|
228
|
+ logger.warn("send sendSessionFailMQ failed. param is {}, exception is {}", failedBO, e);
|
|
|
229
|
+ }
|
|
|
230
|
+ }
|
206
|
|
231
|
|
207
|
private RedisKeyBuilder getSessionCacheKey(String sessionKey, String clientType, String sessionType){
|
232
|
private RedisKeyBuilder getSessionCacheKey(String sessionKey, String clientType, String sessionType){
|
208
|
RedisKeyBuilder keyBuilder = RedisKeyBuilder.newInstance().appendFixed(SESSION_CACHE_KEY_PRE);
|
233
|
RedisKeyBuilder keyBuilder = RedisKeyBuilder.newInstance().appendFixed(SESSION_CACHE_KEY_PRE);
|