|
@@ -1,19 +1,18 @@
|
1
|
1
|
package com.yaozhitech.spring5.intercept;
|
2
|
2
|
|
3
|
|
-import java.util.Arrays;
|
4
|
|
-import java.util.List;
|
5
|
|
-
|
6
|
3
|
import javax.servlet.http.HttpServletRequest;
|
7
|
4
|
import javax.servlet.http.HttpServletResponse;
|
8
|
5
|
|
9
|
6
|
import org.slf4j.Logger;
|
10
|
7
|
import org.slf4j.LoggerFactory;
|
|
8
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
9
|
+import org.springframework.beans.factory.annotation.Value;
|
11
|
10
|
import org.springframework.web.method.HandlerMethod;
|
12
|
11
|
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
13
|
12
|
|
14
|
13
|
import com.yaozhitech.spring5.annotation.IgnoreClientToken;
|
15
|
14
|
import com.yaozhitech.spring5.common.exception.auth.ClientForbiddenException;
|
16
|
|
-import com.yaozhitech.spring5.config.ServiceAuthConfig;
|
|
15
|
+import com.yaozhitech.spring5.provider.AuthServerProvider;
|
17
|
16
|
import com.yaozhitech.spring5.utils.JwtUtils;
|
18
|
17
|
|
19
|
18
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -27,13 +26,11 @@ import lombok.extern.slf4j.Slf4j;
|
27
|
26
|
public class ServiceAuthRestInterceptor extends HandlerInterceptorAdapter {
|
28
|
27
|
private Logger logger = LoggerFactory.getLogger(ServiceAuthRestInterceptor.class);
|
29
|
28
|
|
30
|
|
-// @Autowired
|
31
|
|
-// private ServiceAuthUtil serviceAuthUtil;
|
32
|
|
-//
|
33
|
|
-// @Autowired
|
34
|
|
- private ServiceAuthConfig serviceAuthConfig;
|
35
|
|
-
|
36
|
|
- private List<String> allowedClient = Arrays.asList("admin", "order", "gateway");
|
|
29
|
+ @Autowired
|
|
30
|
+ private AuthServerProvider clientAuthProvider;
|
|
31
|
+
|
|
32
|
+ @Value("${spring.application.name}")
|
|
33
|
+ private String applicationName;
|
37
|
34
|
|
38
|
35
|
@Override
|
39
|
36
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
|
@@ -52,20 +49,21 @@ public class ServiceAuthRestInterceptor extends HandlerInterceptorAdapter {
|
52
|
49
|
return super.preHandle(request, response, handler);
|
53
|
50
|
}
|
54
|
51
|
|
55
|
|
- String token = request.getHeader("x-auth-client");
|
|
52
|
+ String token = request.getHeader("x-auth-token");
|
56
|
53
|
logger.info(token);
|
57
|
54
|
|
|
55
|
+ String client = request.getHeader("x-auth-client");
|
|
56
|
+
|
58
|
57
|
if (token.equals("gateway")) {
|
59
|
58
|
return super.preHandle(request, response, handler);
|
60
|
59
|
}
|
61
|
60
|
|
62
|
61
|
try {
|
63
|
|
- String uniqueName = JwtUtils.getUsername(token);
|
64
|
|
- for (String client : allowedClient) {
|
65
|
|
- if (client.equals(uniqueName.split("\\.")[0])) {
|
66
|
|
- return super.preHandle(request, response, handler);
|
67
|
|
- }
|
|
62
|
+ String uniqueName = JwtUtils.getUsername(client);
|
|
63
|
+ if (Boolean.TRUE.equals(clientAuthProvider.verify(applicationName, uniqueName.split("\\.")[0], uniqueName.split("\\.")[1]))) {
|
|
64
|
+ return super.preHandle(request, response, handler);
|
68
|
65
|
}
|
|
66
|
+
|
69
|
67
|
} catch (Exception e) {
|
70
|
68
|
log.error(e.getMessage(), e);
|
71
|
69
|
throw new ClientForbiddenException("Client verfy error");
|