|
@@ -9,13 +9,12 @@ import com.tianbo.util.Date.DateUtil; |
|
@@ -9,13 +9,12 @@ import com.tianbo.util.Date.DateUtil; |
9
|
import io.swagger.annotations.ApiOperation;
|
9
|
import io.swagger.annotations.ApiOperation;
|
10
|
import lombok.extern.slf4j.Slf4j;
|
10
|
import lombok.extern.slf4j.Slf4j;
|
11
|
import org.springframework.beans.factory.annotation.Autowired;
|
11
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
12
|
+import org.springframework.beans.factory.annotation.Value;
|
12
|
import org.springframework.web.bind.annotation.*;
|
13
|
import org.springframework.web.bind.annotation.*;
|
13
|
|
14
|
|
14
|
import javax.annotation.Resource;
|
15
|
import javax.annotation.Resource;
|
15
|
-import java.util.Date;
|
|
|
16
|
-import java.util.List;
|
|
|
17
|
-import java.util.Map;
|
|
|
18
|
-import java.util.UUID;
|
16
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
17
|
+import java.util.*;
|
19
|
|
18
|
|
20
|
@Slf4j
|
19
|
@Slf4j
|
21
|
@RestController
|
20
|
@RestController
|
|
@@ -31,6 +30,9 @@ public class NmmsController { |
|
@@ -31,6 +30,9 @@ public class NmmsController { |
31
|
@Resource
|
30
|
@Resource
|
32
|
COMPANYUSERMapper companyuserMapper;
|
31
|
COMPANYUSERMapper companyuserMapper;
|
33
|
|
32
|
|
|
|
33
|
+ @Value("${sso.witheIP}")
|
|
|
34
|
+ private String whiteIP;
|
|
|
35
|
+
|
34
|
@ApiOperation(value = "删除分单信息", notes = "awba主单号格式\\d{3}-\\d{8},awbh分单号")
|
36
|
@ApiOperation(value = "删除分单信息", notes = "awba主单号格式\\d{3}-\\d{8},awbh分单号")
|
35
|
@DeleteMapping("/delOriginAWBH")
|
37
|
@DeleteMapping("/delOriginAWBH")
|
36
|
public ResultJson getCustomMessageId(@RequestParam(value = "awba",required = true) String awba,
|
38
|
public ResultJson getCustomMessageId(@RequestParam(value = "awba",required = true) String awba,
|
|
@@ -53,7 +55,10 @@ public class NmmsController { |
|
@@ -53,7 +55,10 @@ public class NmmsController { |
53
|
@ApiOperation(value = "统一认证平台同步资源接口", notes = "用户信息同步")
|
55
|
@ApiOperation(value = "统一认证平台同步资源接口", notes = "用户信息同步")
|
54
|
@PostMapping(value = "/userSynchronization")
|
56
|
@PostMapping(value = "/userSynchronization")
|
55
|
@ResponseBody
|
57
|
@ResponseBody
|
56
|
- public ResultMessage userSynchronization(@RequestBody UAM uam) throws Exception {
|
58
|
+ public ResultMessage userSynchronization(@RequestBody UAM uam, HttpServletRequest request) {
|
|
|
59
|
+ if(!witheIP(request)){
|
|
|
60
|
+ return new ResultMessage("401", "资源同步失败,来源IP非法");
|
|
|
61
|
+ };
|
57
|
if ("user".equals(uam.getResType())){
|
62
|
if ("user".equals(uam.getResType())){
|
58
|
|
63
|
|
59
|
List<UserData> list = uam.getData();
|
64
|
List<UserData> list = uam.getData();
|
|
@@ -89,4 +94,40 @@ public class NmmsController { |
|
@@ -89,4 +94,40 @@ public class NmmsController { |
89
|
return new ResultMessage("201","不是用户信息");
|
94
|
return new ResultMessage("201","不是用户信息");
|
90
|
}
|
95
|
}
|
91
|
|
96
|
|
|
|
97
|
+ private boolean witheIP(HttpServletRequest request){
|
|
|
98
|
+
|
|
|
99
|
+ List<String> witheIPList = Arrays.asList(whiteIP.split(","));
|
|
|
100
|
+ // 优先取 X-Real-IP
|
|
|
101
|
+ String ip = request.getHeader("X-Real-IP");
|
|
|
102
|
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){
|
|
|
103
|
+ log.info("X-Real-IP = [{}]",ip);
|
|
|
104
|
+ ip = request.getHeader("x-forwarded-for");
|
|
|
105
|
+ log.info("x-forwarded-for= [{}]",ip);
|
|
|
106
|
+ }
|
|
|
107
|
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){
|
|
|
108
|
+ ip = request.getRemoteAddr();
|
|
|
109
|
+ log.info("RemoteAddr= [{}]",ip);
|
|
|
110
|
+ if ("0:0:0:0:0:0:0:1".equals(ip))
|
|
|
111
|
+ {
|
|
|
112
|
+ ip = "unknown";
|
|
|
113
|
+ log.info(ip);
|
|
|
114
|
+ }
|
|
|
115
|
+ }
|
|
|
116
|
+ if ("unknown".equalsIgnoreCase(ip)){
|
|
|
117
|
+ ip = "unknown";
|
|
|
118
|
+ }
|
|
|
119
|
+ int index = ip.indexOf(',');
|
|
|
120
|
+ if (index >= 0){
|
|
|
121
|
+ ip = ip.substring(0, index);
|
|
|
122
|
+ }
|
|
|
123
|
+ log.info("用户IP来源为:[{}]",ip);
|
|
|
124
|
+ for (String whitIp : witheIPList ) {
|
|
|
125
|
+ if(ip.contains(whitIp)){
|
|
|
126
|
+ return true;
|
|
|
127
|
+ }
|
|
|
128
|
+ }
|
|
|
129
|
+ log.info("用户IP[{}]来源非法",ip);
|
|
|
130
|
+ return false;
|
|
|
131
|
+ }
|
|
|
132
|
+
|
92
|
} |
133
|
} |