|
@@ -5,15 +5,15 @@ import com.community.commom.constant.Constant;
|
5
|
5
|
import com.community.commom.mode.ResponseBean;
|
6
|
6
|
import com.community.commom.session.UserElement;
|
7
|
7
|
import com.community.huiju.constant.Header;
|
|
8
|
+import com.community.huiju.constant.RequestURI;
|
8
|
9
|
import com.community.huiju.constant.Status;
|
9
|
10
|
import com.netflix.zuul.ZuulFilter;
|
10
|
11
|
import com.netflix.zuul.context.RequestContext;
|
11
|
12
|
import com.netflix.zuul.exception.ZuulException;
|
12
|
13
|
import lombok.extern.slf4j.Slf4j;
|
13
|
14
|
import org.apache.commons.lang.StringUtils;
|
14
|
|
-import org.springframework.http.HttpMethod;
|
15
|
|
-import org.springframework.http.MediaType;
|
16
|
15
|
import org.springframework.stereotype.Component;
|
|
16
|
+import org.springframework.util.AntPathMatcher;
|
17
|
17
|
|
18
|
18
|
import javax.servlet.http.HttpServletRequest;
|
19
|
19
|
import javax.servlet.http.HttpServletResponse;
|
|
@@ -26,9 +26,11 @@ import javax.servlet.http.HttpServletResponse;
|
26
|
26
|
@Slf4j
|
27
|
27
|
public class DomainZuulPostFilter extends ZuulFilter {
|
28
|
28
|
|
|
29
|
+ private AntPathMatcher matcher = new AntPathMatcher();
|
|
30
|
+
|
29
|
31
|
@Override
|
30
|
32
|
public String filterType() {
|
31
|
|
- return "post";
|
|
33
|
+ return "pre";
|
32
|
34
|
}
|
33
|
35
|
|
34
|
36
|
@Override
|
|
@@ -54,30 +56,33 @@ public class DomainZuulPostFilter extends ZuulFilter {
|
54
|
56
|
response.setContentType("application/json;charset=UTF-8");
|
55
|
57
|
HttpServletRequest request = ctx.getRequest();
|
56
|
58
|
String token = request.getHeader(Header.REQUEST_X_AUTH_TOKEN.getValue());
|
57
|
|
- String loginType = request.getHeader(Header.LOGIN_TYPE.getValue());
|
|
59
|
+ // String loginType = request.getHeader(Header.LOGIN_TYPE.getValue());
|
|
60
|
+ // 根据URL判断是访问哪一个端
|
|
61
|
+ String requestURI = request.getRequestURI();
|
|
62
|
+ ResponseBean responseBean = new ResponseBean();
|
|
63
|
+
|
58
|
64
|
if (StringUtils.isBlank(token)) {
|
59
|
65
|
|
60
|
66
|
}else {
|
61
|
67
|
log.info("获取的token: {}", token);
|
62
|
|
- ResponseBean responseBean = new ResponseBean();
|
63
|
|
- // APP 端
|
64
|
|
- if (Constant.APP_LOGIN_TYPE.equals(loginType.trim())){
|
|
68
|
+
|
|
69
|
+ if (matcher.match(RequestURI.APP_API.getUrl(), requestURI)) {
|
65
|
70
|
UserElement appElement = (UserElement) request.getSession().getAttribute(Constant.APP_USER_SESSION);
|
66
|
71
|
if (null == appElement) {
|
67
|
72
|
responseBean.addError(Status.RESPONSE_STATUS_803.getValue(),Status.RESPONSE_STATUS_803.getComment());
|
|
73
|
+ ctx.setSendZuulResponse(false);
|
68
|
74
|
ctx.setResponseBody(JSONObject.toJSONString(responseBean));
|
69
|
75
|
}
|
70
|
76
|
|
71
|
|
- // WEB 端
|
72
|
|
- } else {
|
|
77
|
+ } else if (matcher.match(RequestURI.OPERATE_API.getUrl(), requestURI) || matcher.match(RequestURI.PROPERTY_API.getUrl(), requestURI)) {
|
73
|
78
|
UserElement webOperateElement = (UserElement) request.getSession().getAttribute(Constant.WEB_USER_SESSION);
|
74
|
79
|
if (null == webOperateElement) {
|
75
|
80
|
responseBean.addError(Status.RESPONSE_STATUS_803.getValue(),Status.RESPONSE_STATUS_803.getComment());
|
|
81
|
+ ctx.setSendZuulResponse(false);
|
76
|
82
|
ctx.setResponseBody(JSONObject.toJSONString(responseBean));
|
77
|
83
|
}
|
78
|
84
|
}
|
79
|
85
|
|
80
|
|
-
|
81
|
86
|
}
|
82
|
87
|
|
83
|
88
|
return null;
|