作者 朱兆平

新舱单辅助管理-统一认证实体优化

@@ -135,6 +135,8 @@ customs: @@ -135,6 +135,8 @@ customs:
135 #生成报文文件夹路径,尾部要带斜杠/ 135 #生成报文文件夹路径,尾部要带斜杠/
136 xml-path: customTemplate/ 136 xml-path: customTemplate/
137 transport-number: 460470678920X 137 transport-number: 460470678920X
  138 +sso:
  139 + witheIP: 10.5.14.108,10.5.14.109,10.5.14.110
138 info: 140 info:
139 version: 1.0 141 version: 1.0
140 description: "新舱单辅助管理服务-统一认证、转运管理、提前运抵等" 142 description: "新舱单辅助管理服务-统一认证、转运管理、提前运抵等"
@@ -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 }
1 package com.tianbo.analysis.model; 1 package com.tianbo.analysis.model;
2 2
  3 +import lombok.Data;
  4 +
3 import java.io.Serializable; 5 import java.io.Serializable;
  6 +import java.util.Date;
4 7
5 /** 8 /**
6 * 统一认证返回实体 9 * 统一认证返回实体
7 */ 10 */
  11 +@Data
8 public class ResultMessage implements Serializable { 12 public class ResultMessage implements Serializable {
9 private static final long serialVersionUID = 1L; 13 private static final long serialVersionUID = 1L;
10 14
@@ -87,6 +87,7 @@ @@ -87,6 +87,7 @@
87 AND AGENT_NAME like CONCAT('%',#{agentName,jdbcType=VARCHAR},'%') 87 AND AGENT_NAME like CONCAT('%',#{agentName,jdbcType=VARCHAR},'%')
88 </if> 88 </if>
89 </where> 89 </where>
  90 + order by CREATE_DATE desc
90 </select> 91 </select>
91 <delete id="deleteByPrimaryKey" parameterType="java.lang.String" > 92 <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
92 delete from DOMTRANSIT 93 delete from DOMTRANSIT