Commit b35edf95e5097e10ab2f04443e4c3c65d649afc6
Merge remote-tracking branch 'origin/lingang' into lingang
# Conflicts: # src/main/java/com/bsth/CXFConfig.java
Showing
11 changed files
with
569 additions
and
254 deletions
src/main/java/com/bsth/CXFConfig.java
| @@ -14,6 +14,7 @@ import com.bsth.server_rs.bigdata.BigscreenService; | @@ -14,6 +14,7 @@ import com.bsth.server_rs.bigdata.BigscreenService; | ||
| 14 | import com.bsth.server_rs.departure.DepartureRestService; | 14 | import com.bsth.server_rs.departure.DepartureRestService; |
| 15 | import com.bsth.server_rs.destroy.DestroyDetailRestService; | 15 | import com.bsth.server_rs.destroy.DestroyDetailRestService; |
| 16 | import com.bsth.server_rs.directive.DirectiveRestService; | 16 | import com.bsth.server_rs.directive.DirectiveRestService; |
| 17 | +import com.bsth.server_rs.dks.BxRestService; | ||
| 17 | import com.bsth.server_rs.dks.DksRestService; | 18 | import com.bsth.server_rs.dks.DksRestService; |
| 18 | import com.bsth.server_rs.electric.ElectricService; | 19 | import com.bsth.server_rs.electric.ElectricService; |
| 19 | import com.bsth.server_rs.exception.AesExceptionMapper; | 20 | import com.bsth.server_rs.exception.AesExceptionMapper; |
| @@ -143,13 +144,15 @@ public class CXFConfig { | @@ -143,13 +144,15 @@ public class CXFConfig { | ||
| 143 | private QhSchService qhSchService; | 144 | private QhSchService qhSchService; |
| 144 | 145 | ||
| 145 | 146 | ||
| 147 | + @Autowired | ||
| 148 | + private BxRestService bxRestService; | ||
| 149 | + | ||
| 146 | @Bean | 150 | @Bean |
| 147 | public Server rsServer() { | 151 | public Server rsServer() { |
| 148 | JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean(); | 152 | JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean(); |
| 149 | endpoint.setBus(springBus()); | 153 | endpoint.setBus(springBus()); |
| 150 | endpoint.setAddress("/rest"); | 154 | endpoint.setAddress("/rest"); |
| 151 | - endpoint.setServiceBeans(Arrays.<Object>asList( | ||
| 152 | - new LineRestService(), | 155 | + endpoint.setServiceBeans(Arrays.<Object>asList( new LineRestService(), |
| 153 | new CarRestService(), | 156 | new CarRestService(), |
| 154 | new PersonRestService(), | 157 | new PersonRestService(), |
| 155 | gpsRestService, | 158 | gpsRestService, |
| @@ -172,6 +175,7 @@ public class CXFConfig { | @@ -172,6 +175,7 @@ public class CXFConfig { | ||
| 172 | dksRestService, | 175 | dksRestService, |
| 173 | xxfbRestService, | 176 | xxfbRestService, |
| 174 | manHoursRestService, | 177 | manHoursRestService, |
| 178 | + bxRestService, | ||
| 175 | qhSchService)); | 179 | qhSchService)); |
| 176 | endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper())); | 180 | endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper())); |
| 177 | //endpoint.setFeatures(Arrays.asList(new Swagger2Feature())); | 181 | //endpoint.setFeatures(Arrays.asList(new Swagger2Feature())); |
src/main/java/com/bsth/StartCommand.java
| @@ -7,6 +7,7 @@ import com.bsth.server_rs.man_hours.ManHoursRefreshScheduler; | @@ -7,6 +7,7 @@ import com.bsth.server_rs.man_hours.ManHoursRefreshScheduler; | ||
| 7 | import com.bsth.server_rs.schedule.real.thread.ExecSchDataRefreshThread; | 7 | import com.bsth.server_rs.schedule.real.thread.ExecSchDataRefreshThread; |
| 8 | import com.bsth.server_rs.schedule.real.thread.SchInOutDataRefreshThread; | 8 | import com.bsth.server_rs.schedule.real.thread.SchInOutDataRefreshThread; |
| 9 | import com.bsth.server_rs.thread.RfidCardInfoPersistenceThread; | 9 | import com.bsth.server_rs.thread.RfidCardInfoPersistenceThread; |
| 10 | +import com.bsth.service.SystemParamService; | ||
| 10 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 11 | import org.springframework.boot.CommandLineRunner; | 12 | import org.springframework.boot.CommandLineRunner; |
| 12 | import org.springframework.stereotype.Component; | 13 | import org.springframework.stereotype.Component; |
| @@ -37,6 +38,9 @@ public class StartCommand implements CommandLineRunner{ | @@ -37,6 +38,9 @@ public class StartCommand implements CommandLineRunner{ | ||
| 37 | @Autowired | 38 | @Autowired |
| 38 | ManHoursRefreshScheduler manHoursRefreshScheduler; | 39 | ManHoursRefreshScheduler manHoursRefreshScheduler; |
| 39 | 40 | ||
| 41 | + @Autowired | ||
| 42 | + SystemParamService systemParamService; | ||
| 43 | + | ||
| 40 | @Override | 44 | @Override |
| 41 | public void run(String... arg0){ | 45 | public void run(String... arg0){ |
| 42 | 46 | ||
| @@ -53,6 +57,7 @@ public class StartCommand implements CommandLineRunner{ | @@ -53,6 +57,7 @@ public class StartCommand implements CommandLineRunner{ | ||
| 53 | //定时刷新基础信息 | 57 | //定时刷新基础信息 |
| 54 | Application.mainServices.scheduleWithFixedDelay(basicDataRefreshThread, 30, 30, TimeUnit.MINUTES); | 58 | Application.mainServices.scheduleWithFixedDelay(basicDataRefreshThread, 30, 30, TimeUnit.MINUTES); |
| 55 | manHoursRefreshScheduler.refresh(); | 59 | manHoursRefreshScheduler.refresh(); |
| 60 | + systemParamService.refresh(); | ||
| 56 | } catch (Exception e) { | 61 | } catch (Exception e) { |
| 57 | e.printStackTrace(); | 62 | e.printStackTrace(); |
| 58 | } | 63 | } |
src/main/java/com/bsth/common/SystemParamKeys.java
0 → 100644
| 1 | +package com.bsth.common; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * @author Hill | ||
| 5 | + */ | ||
| 6 | +public class SystemParamKeys { | ||
| 7 | + | ||
| 8 | + public static final String SPECIAL_ROLES = "special.roles"; | ||
| 9 | + | ||
| 10 | + public static final String LIMIT_PASSWORDS = "limit.passwords"; | ||
| 11 | + | ||
| 12 | + public static final String LIMIT_URIS = "limit.uris"; | ||
| 13 | + | ||
| 14 | + public static final String LIMIT_LINES = "limit.lines"; | ||
| 15 | + | ||
| 16 | + public static final String LIMIT_DEVICES = "limit.devices"; | ||
| 17 | +} |
src/main/java/com/bsth/entity/SystemParam.java
0 → 100644
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | +import javax.persistence.*; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * @author Hill | ||
| 7 | + */ | ||
| 8 | +@Entity | ||
| 9 | +@Table(name = "bsth_c_sys_param") | ||
| 10 | +public class SystemParam { | ||
| 11 | + | ||
| 12 | + @Id | ||
| 13 | + @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| 14 | + private Integer id; | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * 键名(唯一) | ||
| 18 | + */ | ||
| 19 | + private String key; | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 值 | ||
| 23 | + */ | ||
| 24 | + private String value; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 备注 | ||
| 28 | + */ | ||
| 29 | + private String remark; | ||
| 30 | + | ||
| 31 | + public Integer getId() { | ||
| 32 | + return id; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public void setId(Integer id) { | ||
| 36 | + this.id = id; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public String getKey() { | ||
| 40 | + return key; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public void setKey(String key) { | ||
| 44 | + this.key = key; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public String getValue() { | ||
| 48 | + return value; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public void setValue(String value) { | ||
| 52 | + this.value = value; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public String getRemark() { | ||
| 56 | + return remark; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public void setRemark(String remark) { | ||
| 60 | + this.remark = remark; | ||
| 61 | + } | ||
| 62 | +} |
src/main/java/com/bsth/repository/SystemParamRepository.java
0 → 100644
src/main/java/com/bsth/server_rs/AuthorizeInterceptor_IN.java
| 1 | -package com.bsth.server_rs; | ||
| 2 | - | ||
| 3 | -import com.bsth.server_rs.exception.AesException; | ||
| 4 | -import com.bsth.service.UserService; | ||
| 5 | -import org.apache.commons.lang3.StringEscapeUtils; | ||
| 6 | -import org.apache.cxf.interceptor.Fault; | ||
| 7 | -import org.apache.cxf.message.Message; | ||
| 8 | -import org.apache.cxf.phase.AbstractPhaseInterceptor; | ||
| 9 | -import org.apache.cxf.phase.Phase; | ||
| 10 | -import org.eclipse.jetty.util.MultiMap; | ||
| 11 | -import org.eclipse.jetty.util.UrlEncoded; | ||
| 12 | -import org.slf4j.Logger; | ||
| 13 | -import org.slf4j.LoggerFactory; | ||
| 14 | -import org.springframework.beans.BeansException; | ||
| 15 | -import org.springframework.context.ApplicationContext; | ||
| 16 | -import org.springframework.context.ApplicationContextAware; | ||
| 17 | -import org.springframework.stereotype.Component; | ||
| 18 | - | ||
| 19 | -import java.security.MessageDigest; | ||
| 20 | -import java.util.Arrays; | ||
| 21 | -import java.util.HashMap; | ||
| 22 | -import java.util.Map; | ||
| 23 | -import java.util.Set; | ||
| 24 | - | ||
| 25 | -/** | ||
| 26 | - * rest 接口授权校验(IN 输入拦截) | ||
| 27 | - * Created by panzhao on 2017/3/28. | ||
| 28 | - */ | ||
| 29 | -@Component | ||
| 30 | -public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor<Message> implements ApplicationContextAware { | ||
| 31 | - | ||
| 32 | - private static final String SIGN = "sign"; | ||
| 33 | - private static final String TIMESTAMP = "timestamp"; | ||
| 34 | - private static final String NONCE = "nonce"; | ||
| 35 | - private static final String PASSWORD = "password"; | ||
| 36 | - private static final int MAX_TIME_DIFF = 1000 * 60 * 10; | ||
| 37 | - private static Map<String, String> pwd2nonceMap; | ||
| 38 | - | ||
| 39 | - static UserService userService; | ||
| 40 | - | ||
| 41 | - static Logger logger = LoggerFactory.getLogger(AuthorizeInterceptor_IN.class); | ||
| 42 | - | ||
| 43 | - public AuthorizeInterceptor_IN() { | ||
| 44 | - super(Phase.RECEIVE); | ||
| 45 | - } | ||
| 46 | - | ||
| 47 | - static { | ||
| 48 | - pwd2nonceMap = new HashMap<>(); | ||
| 49 | - } | ||
| 50 | - | ||
| 51 | - @Override | ||
| 52 | - public void handleMessage(Message message) throws Fault { | ||
| 53 | - | ||
| 54 | - long t = System.currentTimeMillis(); | ||
| 55 | - if (message.get(Message.QUERY_STRING) == null) { | ||
| 56 | - throw new AesException(AesException.MISS_SIGN); | ||
| 57 | - } | ||
| 58 | - | ||
| 59 | - //放行wadl | ||
| 60 | - if(message.get(Message.QUERY_STRING).equals("_wadl") | ||
| 61 | - && message.get(Message.PATH_INFO).equals("/webservice/rest")){ | ||
| 62 | - return ; | ||
| 63 | - } | ||
| 64 | - | ||
| 65 | - //获取参数,不包括 url 路径参数 只包括?号之后的 | ||
| 66 | - String queryString = StringEscapeUtils.unescapeHtml4(message.get(Message.QUERY_STRING).toString()); | ||
| 67 | - MultiMap<String> params = new MultiMap<>(); | ||
| 68 | - UrlEncoded.decodeTo(queryString, params, "utf-8"); | ||
| 69 | - Map<String, String> map = multi2One(params); | ||
| 70 | - | ||
| 71 | - if (!map.containsKey(SIGN)) { | ||
| 72 | - throw new AesException(AesException.MISS_SIGN); | ||
| 73 | - } | ||
| 74 | - if (!map.containsKey(TIMESTAMP)) { | ||
| 75 | - throw new AesException(AesException.MISS_TIMESTAMP); | ||
| 76 | - } | ||
| 77 | - | ||
| 78 | - try{ | ||
| 79 | - long timestamp = Long.parseLong(map.get(TIMESTAMP)); | ||
| 80 | - if(Math.abs(t - timestamp) > MAX_TIME_DIFF){ | ||
| 81 | - throw new AesException(AesException.INVALID_TIMESTAMP); | ||
| 82 | - } | ||
| 83 | - }catch(Exception e){ | ||
| 84 | - throw new AesException(AesException.INVALID_TIMESTAMP); | ||
| 85 | - } | ||
| 86 | - | ||
| 87 | - if (!map.containsKey(NONCE)) { | ||
| 88 | - throw new AesException(AesException.MISS_NONCE); | ||
| 89 | - } | ||
| 90 | - if (!map.containsKey(PASSWORD)) { | ||
| 91 | - throw new AesException(AesException.MISS_PWD); | ||
| 92 | - } | ||
| 93 | - | ||
| 94 | - String prevNonce = pwd2nonceMap.get(map.get(PASSWORD)); | ||
| 95 | - if(prevNonce != null && prevNonce.equals(map.get(NONCE))) | ||
| 96 | - throw new AesException(AesException.NO_RANDOM_NONCE); | ||
| 97 | - | ||
| 98 | - if (userService.get(map.get(PASSWORD)) == null) { | ||
| 99 | - throw new AesException(AesException.INVALID_PWD); | ||
| 100 | - } | ||
| 101 | - | ||
| 102 | - String sign = map.get(SIGN); | ||
| 103 | - map.remove(SIGN); | ||
| 104 | - String sh1 = ""; | ||
| 105 | - try { | ||
| 106 | - sh1 = getSHA1(map); | ||
| 107 | - } catch (Exception e) { | ||
| 108 | - throw new AesException(AesException.SIGN_CHECK_ERROR); | ||
| 109 | - } | ||
| 110 | - | ||
| 111 | - if (!sign.equals(sh1)) { | ||
| 112 | - throw new AesException(AesException.SIGN_CHECK_FAIL); | ||
| 113 | - } | ||
| 114 | - } | ||
| 115 | - | ||
| 116 | - public static Map<String, String> multi2One(MultiMap<String> params) { | ||
| 117 | - Map<String, String> map = new HashMap<>(); | ||
| 118 | - Set<String> ks = params.keySet(); | ||
| 119 | - for (String k : ks) { | ||
| 120 | - map.put(k, params.getString(k)); | ||
| 121 | - } | ||
| 122 | - return map; | ||
| 123 | - } | ||
| 124 | - | ||
| 125 | - | ||
| 126 | - public static String getSHA1(Map<String, String> map) throws Exception { | ||
| 127 | - | ||
| 128 | - try { | ||
| 129 | - String[] array = new String[map.size()]; | ||
| 130 | - map.values().toArray(array); | ||
| 131 | - StringBuffer sb = new StringBuffer(); | ||
| 132 | - | ||
| 133 | - // 字符串排序 | ||
| 134 | - Arrays.sort(array); | ||
| 135 | - for (int i = 0; i < array.length; i++) { | ||
| 136 | - sb.append(array[i]); | ||
| 137 | - } | ||
| 138 | - String str = sb.toString(); | ||
| 139 | - // SHA1签名生成 | ||
| 140 | - MessageDigest md = MessageDigest.getInstance("SHA-1"); | ||
| 141 | - md.update(str.getBytes()); | ||
| 142 | - byte[] digest = md.digest(); | ||
| 143 | - | ||
| 144 | - StringBuffer hexstr = new StringBuffer(); | ||
| 145 | - String shaHex = ""; | ||
| 146 | - for (int i = 0; i < digest.length; i++) { | ||
| 147 | - shaHex = Integer.toHexString(digest[i] & 0xFF); | ||
| 148 | - if (shaHex.length() < 2) { | ||
| 149 | - hexstr.append(0); | ||
| 150 | - } | ||
| 151 | - hexstr.append(shaHex); | ||
| 152 | - } | ||
| 153 | - return hexstr.toString(); | ||
| 154 | - } catch (Exception e) { | ||
| 155 | - logger.error("", e); | ||
| 156 | - throw e; | ||
| 157 | - } | ||
| 158 | - } | ||
| 159 | - | ||
| 160 | - @Override | ||
| 161 | - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||
| 162 | - userService = applicationContext.getBean(UserService.class); | ||
| 163 | - } | ||
| 164 | -} | 1 | +package com.bsth.server_rs; |
| 2 | + | ||
| 3 | +import com.bsth.common.SystemParamKeys; | ||
| 4 | +import com.bsth.server_rs.exception.AesException; | ||
| 5 | +import com.bsth.service.SystemParamService; | ||
| 6 | +import com.bsth.service.UserService; | ||
| 7 | +import org.apache.commons.lang3.StringEscapeUtils; | ||
| 8 | +import org.apache.cxf.interceptor.Fault; | ||
| 9 | +import org.apache.cxf.message.Message; | ||
| 10 | +import org.apache.cxf.phase.AbstractPhaseInterceptor; | ||
| 11 | +import org.apache.cxf.phase.Phase; | ||
| 12 | +import org.eclipse.jetty.util.MultiMap; | ||
| 13 | +import org.eclipse.jetty.util.UrlEncoded; | ||
| 14 | +import org.slf4j.Logger; | ||
| 15 | +import org.slf4j.LoggerFactory; | ||
| 16 | +import org.springframework.beans.BeansException; | ||
| 17 | +import org.springframework.beans.factory.InitializingBean; | ||
| 18 | +import org.springframework.context.ApplicationContext; | ||
| 19 | +import org.springframework.context.ApplicationContextAware; | ||
| 20 | +import org.springframework.stereotype.Component; | ||
| 21 | + | ||
| 22 | +import java.security.MessageDigest; | ||
| 23 | +import java.util.Arrays; | ||
| 24 | +import java.util.HashMap; | ||
| 25 | +import java.util.Map; | ||
| 26 | +import java.util.Set; | ||
| 27 | + | ||
| 28 | +/** | ||
| 29 | + * rest 接口授权校验(IN 输入拦截) | ||
| 30 | + * Created by panzhao on 2017/3/28. | ||
| 31 | + */ | ||
| 32 | +@Component | ||
| 33 | +public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor<Message> implements ApplicationContextAware { | ||
| 34 | + | ||
| 35 | + private static final String SIGN = "sign"; | ||
| 36 | + private static final String TIMESTAMP = "timestamp"; | ||
| 37 | + private static final String NONCE = "nonce"; | ||
| 38 | + private static final String PASSWORD = "password"; | ||
| 39 | + private static final int MAX_TIME_DIFF = 1000 * 60 * 10; | ||
| 40 | + private static Map<String, String> pwd2nonceMap; | ||
| 41 | + | ||
| 42 | + static UserService userService; | ||
| 43 | + | ||
| 44 | + static SystemParamService systemParamService; | ||
| 45 | + | ||
| 46 | + static Logger logger = LoggerFactory.getLogger(AuthorizeInterceptor_IN.class); | ||
| 47 | + | ||
| 48 | + public AuthorizeInterceptor_IN() { | ||
| 49 | + super(Phase.RECEIVE); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + static { | ||
| 53 | + pwd2nonceMap = new HashMap<>(); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + @Override | ||
| 57 | + public void handleMessage(Message message) throws Fault { | ||
| 58 | + | ||
| 59 | + long t = System.currentTimeMillis(); | ||
| 60 | + if (message.get(Message.QUERY_STRING) == null) { | ||
| 61 | + throw new AesException(AesException.MISS_SIGN); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + //放行wadl | ||
| 65 | + if(message.get(Message.QUERY_STRING).equals("_wadl") | ||
| 66 | + && message.get(Message.PATH_INFO).equals("/webservice/rest")){ | ||
| 67 | + return ; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + //获取参数,不包括 url 路径参数 只包括?号之后的 | ||
| 71 | + String queryString = StringEscapeUtils.unescapeHtml4(message.get(Message.QUERY_STRING).toString()); | ||
| 72 | + MultiMap<String> params = new MultiMap<>(); | ||
| 73 | + UrlEncoded.decodeTo(queryString, params, "utf-8"); | ||
| 74 | + Map<String, String> map = multi2One(params); | ||
| 75 | + | ||
| 76 | + if (!map.containsKey(SIGN)) { | ||
| 77 | + throw new AesException(AesException.MISS_SIGN); | ||
| 78 | + } | ||
| 79 | + if (!map.containsKey(TIMESTAMP)) { | ||
| 80 | + throw new AesException(AesException.MISS_TIMESTAMP); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + try{ | ||
| 84 | + long timestamp = Long.parseLong(map.get(TIMESTAMP)); | ||
| 85 | + if(Math.abs(t - timestamp) > MAX_TIME_DIFF){ | ||
| 86 | + throw new AesException(AesException.INVALID_TIMESTAMP); | ||
| 87 | + } | ||
| 88 | + }catch(Exception e){ | ||
| 89 | + throw new AesException(AesException.INVALID_TIMESTAMP); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + if (!map.containsKey(NONCE)) { | ||
| 93 | + throw new AesException(AesException.MISS_NONCE); | ||
| 94 | + } | ||
| 95 | + if (!map.containsKey(PASSWORD)) { | ||
| 96 | + throw new AesException(AesException.MISS_PWD); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + String prevNonce = pwd2nonceMap.get(map.get(PASSWORD)); | ||
| 100 | + if(prevNonce != null && prevNonce.equals(map.get(NONCE))) | ||
| 101 | + throw new AesException(AesException.NO_RANDOM_NONCE); | ||
| 102 | + | ||
| 103 | + if (userService.get(map.get(PASSWORD)) == null) { | ||
| 104 | + throw new AesException(AesException.INVALID_PWD); | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + String sign = map.get(SIGN); | ||
| 108 | + map.remove(SIGN); | ||
| 109 | + String sh1 = ""; | ||
| 110 | + try { | ||
| 111 | + sh1 = getSHA1(map); | ||
| 112 | + } catch (Exception e) { | ||
| 113 | + throw new AesException(AesException.SIGN_CHECK_ERROR); | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + if (!sign.equals(sh1)) { | ||
| 117 | + throw new AesException(AesException.SIGN_CHECK_FAIL); | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + validate(map, message); | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + private static void validate(Map<String, String> map, Message message) { | ||
| 124 | + String limitPasswords = systemParamService.getValue(SystemParamKeys.LIMIT_PASSWORDS); | ||
| 125 | + String limitUris = systemParamService.getValue(SystemParamKeys.LIMIT_URIS); | ||
| 126 | + if (limitPasswords != null && limitPasswords.indexOf(String.format("%s,", map.get(PASSWORD))) > -1) { | ||
| 127 | + if (limitUris != null && limitUris.indexOf(String.format("%s,", message.get(Message.REQUEST_URI))) == -1) { | ||
| 128 | + throw new AesException(AesException.INVALID_URI); | ||
| 129 | + } | ||
| 130 | + } | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + public static Map<String, String> multi2One(MultiMap<String> params) { | ||
| 134 | + Map<String, String> map = new HashMap<>(); | ||
| 135 | + Set<String> ks = params.keySet(); | ||
| 136 | + for (String k : ks) { | ||
| 137 | + map.put(k, params.getString(k)); | ||
| 138 | + } | ||
| 139 | + return map; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + | ||
| 143 | + public static String getSHA1(Map<String, String> map) throws Exception { | ||
| 144 | + | ||
| 145 | + try { | ||
| 146 | + String[] array = new String[map.size()]; | ||
| 147 | + map.values().toArray(array); | ||
| 148 | + StringBuffer sb = new StringBuffer(); | ||
| 149 | + | ||
| 150 | + // 字符串排序 | ||
| 151 | + Arrays.sort(array); | ||
| 152 | + for (int i = 0; i < array.length; i++) { | ||
| 153 | + sb.append(array[i]); | ||
| 154 | + } | ||
| 155 | + String str = sb.toString(); | ||
| 156 | + // SHA1签名生成 | ||
| 157 | + MessageDigest md = MessageDigest.getInstance("SHA-1"); | ||
| 158 | + md.update(str.getBytes()); | ||
| 159 | + byte[] digest = md.digest(); | ||
| 160 | + | ||
| 161 | + StringBuffer hexstr = new StringBuffer(); | ||
| 162 | + String shaHex = ""; | ||
| 163 | + for (int i = 0; i < digest.length; i++) { | ||
| 164 | + shaHex = Integer.toHexString(digest[i] & 0xFF); | ||
| 165 | + if (shaHex.length() < 2) { | ||
| 166 | + hexstr.append(0); | ||
| 167 | + } | ||
| 168 | + hexstr.append(shaHex); | ||
| 169 | + } | ||
| 170 | + return hexstr.toString(); | ||
| 171 | + } catch (Exception e) { | ||
| 172 | + logger.error("", e); | ||
| 173 | + throw e; | ||
| 174 | + } | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + @Override | ||
| 178 | + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||
| 179 | + userService = applicationContext.getBean(UserService.class); | ||
| 180 | + systemParamService = applicationContext.getBean(SystemParamService.class); | ||
| 181 | + } | ||
| 182 | +} |
src/main/java/com/bsth/server_rs/dks/BxRestService.java
0 → 100644
| 1 | +package com.bsth.server_rs.dks; | ||
| 2 | + | ||
| 3 | +import com.bsth.common.SystemParamKeys; | ||
| 4 | +import com.bsth.entity.ElecInfo; | ||
| 5 | +import com.bsth.entity.OilInfo; | ||
| 6 | +import com.bsth.entity.SchedulePlanInfo; | ||
| 7 | +import com.bsth.entity.ScheduleRealInfo; | ||
| 8 | +import com.bsth.redis.ElecRedisService; | ||
| 9 | +import com.bsth.redis.OilRedisService; | ||
| 10 | +import com.bsth.redis.ScheduleRedisService; | ||
| 11 | +import com.bsth.repository.SchedulePlanInfoRepository; | ||
| 12 | +import com.bsth.repository.ScheduleRealInfoRepository; | ||
| 13 | +import com.bsth.server_rs.AuthorizeInterceptor_IN; | ||
| 14 | +import com.bsth.server_rs.base_info.car.Car; | ||
| 15 | +import com.bsth.server_rs.base_info.car.buffer.CarBufferData; | ||
| 16 | +import com.bsth.server_rs.base_info.line.Line; | ||
| 17 | +import com.bsth.server_rs.base_info.line.buffer.LineBufferData; | ||
| 18 | +import com.bsth.server_rs.base_info.station.buffer.StationBufferData; | ||
| 19 | +import com.bsth.server_rs.base_info.station.entity.StationRotue; | ||
| 20 | +import com.bsth.server_rs.gps.buffer.GpsRealDataBuffer; | ||
| 21 | +import com.bsth.server_rs.gps.entity.GpsEntity; | ||
| 22 | +import com.bsth.server_ws.util.ScheduleCalculator; | ||
| 23 | +import com.bsth.service.SystemParamService; | ||
| 24 | +import com.bsth.util.Arith; | ||
| 25 | +import com.google.common.collect.ArrayListMultimap; | ||
| 26 | +import org.joda.time.DateTime; | ||
| 27 | +import org.joda.time.format.DateTimeFormat; | ||
| 28 | +import org.slf4j.Logger; | ||
| 29 | +import org.slf4j.LoggerFactory; | ||
| 30 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 31 | +import org.springframework.jdbc.core.BatchPreparedStatementSetter; | ||
| 32 | +import org.springframework.jdbc.core.BeanPropertyRowMapper; | ||
| 33 | +import org.springframework.jdbc.core.JdbcTemplate; | ||
| 34 | +import org.springframework.jdbc.datasource.DataSourceTransactionManager; | ||
| 35 | +import org.springframework.scheduling.annotation.EnableScheduling; | ||
| 36 | +import org.springframework.scheduling.annotation.Scheduled; | ||
| 37 | +import org.springframework.stereotype.Component; | ||
| 38 | +import org.springframework.transaction.TransactionDefinition; | ||
| 39 | +import org.springframework.transaction.TransactionStatus; | ||
| 40 | +import org.springframework.transaction.support.DefaultTransactionDefinition; | ||
| 41 | +import org.springframework.util.StringUtils; | ||
| 42 | + | ||
| 43 | +import javax.ws.rs.GET; | ||
| 44 | +import javax.ws.rs.Path; | ||
| 45 | +import javax.ws.rs.PathParam; | ||
| 46 | +import javax.ws.rs.Produces; | ||
| 47 | +import javax.ws.rs.core.MediaType; | ||
| 48 | +import java.sql.PreparedStatement; | ||
| 49 | +import java.sql.SQLException; | ||
| 50 | +import java.util.*; | ||
| 51 | + | ||
| 52 | +/** | ||
| 53 | + * @author Hill | ||
| 54 | + * @date 2021-09 | ||
| 55 | + */ | ||
| 56 | +@Component | ||
| 57 | +@Path("/bx") | ||
| 58 | +@Produces({MediaType.APPLICATION_JSON}) | ||
| 59 | +public class BxRestService { | ||
| 60 | + | ||
| 61 | + private final static Logger log = LoggerFactory.getLogger(BxRestService.class); | ||
| 62 | + | ||
| 63 | + @Autowired | ||
| 64 | + private AuthorizeInterceptor_IN authorizeInterceptorIn; | ||
| 65 | + | ||
| 66 | + @Autowired | ||
| 67 | + private JdbcTemplate jdbcTemplate; | ||
| 68 | + | ||
| 69 | + @Autowired | ||
| 70 | + private ScheduleRealInfoRepository scheduleRealInfoRepository; | ||
| 71 | + | ||
| 72 | + @Autowired | ||
| 73 | + private SchedulePlanInfoRepository schedulePlanInfoRepository; | ||
| 74 | + | ||
| 75 | + @Autowired | ||
| 76 | + private ScheduleRedisService scheduleRedisService; | ||
| 77 | + | ||
| 78 | + @Autowired | ||
| 79 | + private OilRedisService oilRedisService; | ||
| 80 | + | ||
| 81 | + @Autowired | ||
| 82 | + private ElecRedisService elecRedisService; | ||
| 83 | + | ||
| 84 | + @Autowired | ||
| 85 | + private SystemParamService systemParamService; | ||
| 86 | + | ||
| 87 | + @GET | ||
| 88 | + @Path("/line") | ||
| 89 | + public List<Line> findAllLine() { | ||
| 90 | + List<Line> result = new ArrayList<>(); | ||
| 91 | + String limitLines = systemParamService.getValue(SystemParamKeys.LIMIT_LINES); | ||
| 92 | + if (limitLines == null) { | ||
| 93 | + return result; | ||
| 94 | + } | ||
| 95 | + for (Line line : LineBufferData.findAll()) { | ||
| 96 | + if (limitLines.indexOf(String.format("%s,", line.getLineCode())) > -1) { | ||
| 97 | + result.add(line); | ||
| 98 | + } | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + return result; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + @GET | ||
| 105 | + @Path("/station") | ||
| 106 | + public Map<String, Collection<StationRotue>> findAllStation() { | ||
| 107 | + Map<String, Collection<StationRotue>> result = new HashMap<>(); | ||
| 108 | + String limitLines = systemParamService.getValue(SystemParamKeys.LIMIT_LINES); | ||
| 109 | + if (limitLines == null) { | ||
| 110 | + return result; | ||
| 111 | + } | ||
| 112 | + for (Map.Entry<String, Collection<StationRotue>> entry : StationBufferData.findAllRoute().entrySet()) { | ||
| 113 | + String key = entry.getKey(), lineCode = key.split("_")[0]; | ||
| 114 | + if (limitLines.indexOf(String.format("%s,", lineCode)) > -1) { | ||
| 115 | + result.put(key, entry.getValue()); | ||
| 116 | + } | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + return result; | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + @GET | ||
| 123 | + @Path("/vehicle") | ||
| 124 | + public List<Car> findAllVehicle() { | ||
| 125 | + List<Car> result = new ArrayList<>(); | ||
| 126 | + String limitDevices = systemParamService.getValue(SystemParamKeys.LIMIT_DEVICES); | ||
| 127 | + if (limitDevices == null) { | ||
| 128 | + return result; | ||
| 129 | + } | ||
| 130 | + for (Car car : CarBufferData.findAll()) { | ||
| 131 | + if (limitDevices.indexOf(String.format("%s,", car.getEquipmentCode())) > -1) { | ||
| 132 | + result.add(car); | ||
| 133 | + } | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + return result; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + @GET | ||
| 140 | + @Path("/gps/all") | ||
| 141 | + public List<GpsEntity> findAllGps() { | ||
| 142 | + List<GpsEntity> result = new ArrayList<>(); | ||
| 143 | + String limitDevices = systemParamService.getValue(SystemParamKeys.LIMIT_DEVICES); | ||
| 144 | + if (limitDevices == null) { | ||
| 145 | + return result; | ||
| 146 | + } | ||
| 147 | + for (GpsEntity gps : GpsRealDataBuffer.all()) { | ||
| 148 | + if (limitDevices.indexOf(String.format("%s,", gps.getDeviceId())) > -1) { | ||
| 149 | + result.add(gps); | ||
| 150 | + } | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + return result; | ||
| 154 | + } | ||
| 155 | +} |
src/main/java/com/bsth/server_rs/exception/AesException.java
| 1 | -package com.bsth.server_rs.exception; | ||
| 2 | - | ||
| 3 | -/** | ||
| 4 | - * Created by panzhao on 2017/3/28. | ||
| 5 | - */ | ||
| 6 | -public class AesException extends RuntimeException { | ||
| 7 | - | ||
| 8 | - public final static int OK = 0; | ||
| 9 | - public final static int MISS_SIGN = -30001; | ||
| 10 | - public final static int MISS_TIMESTAMP = -30002; | ||
| 11 | - public final static int MISS_NONCE = -30003; | ||
| 12 | - public final static int NO_RANDOM_NONCE = -30005; | ||
| 13 | - public final static int MISS_PWD = -30004; | ||
| 14 | - public final static int SIGN_CHECK_ERROR = -40001; | ||
| 15 | - public final static int SIGN_CHECK_FAIL = -40002; | ||
| 16 | - public final static int INVALID_PWD = -40003; | ||
| 17 | - public final static int INVALID_TIMESTAMP = -40004; | ||
| 18 | - | ||
| 19 | - private int code; | ||
| 20 | - | ||
| 21 | - private static String getMessage(int code) { | ||
| 22 | - switch (code) { | ||
| 23 | - case MISS_SIGN: | ||
| 24 | - return "sign参数丢失"; | ||
| 25 | - case MISS_TIMESTAMP: | ||
| 26 | - return "timestamp参数丢失"; | ||
| 27 | - case MISS_NONCE: | ||
| 28 | - return "nonce参数丢失"; | ||
| 29 | - case NO_RANDOM_NONCE: | ||
| 30 | - return "nonce参数异常"; | ||
| 31 | - case MISS_PWD: | ||
| 32 | - return "密码参数丢失"; | ||
| 33 | - case INVALID_PWD: | ||
| 34 | - return "无效的密码"; | ||
| 35 | - case SIGN_CHECK_ERROR: | ||
| 36 | - return "签名校验时出现异常"; | ||
| 37 | - case SIGN_CHECK_FAIL: | ||
| 38 | - return "无效的签名"; | ||
| 39 | - case INVALID_TIMESTAMP: | ||
| 40 | - return "无效的时间戳"; | ||
| 41 | - default: | ||
| 42 | - return null; | ||
| 43 | - } | ||
| 44 | - } | ||
| 45 | - | ||
| 46 | - public int getCode() { | ||
| 47 | - return code; | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | - public AesException(int code) { | ||
| 51 | - super(getMessage(code)); | ||
| 52 | - this.code = code; | ||
| 53 | - } | ||
| 54 | -} | 1 | +package com.bsth.server_rs.exception; |
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * Created by panzhao on 2017/3/28. | ||
| 5 | + */ | ||
| 6 | +public class AesException extends RuntimeException { | ||
| 7 | + | ||
| 8 | + public final static int OK = 0; | ||
| 9 | + public final static int MISS_SIGN = -30001; | ||
| 10 | + public final static int MISS_TIMESTAMP = -30002; | ||
| 11 | + public final static int MISS_NONCE = -30003; | ||
| 12 | + public final static int NO_RANDOM_NONCE = -30005; | ||
| 13 | + public final static int MISS_PWD = -30004; | ||
| 14 | + public final static int SIGN_CHECK_ERROR = -40001; | ||
| 15 | + public final static int SIGN_CHECK_FAIL = -40002; | ||
| 16 | + public final static int INVALID_PWD = -40003; | ||
| 17 | + public final static int INVALID_TIMESTAMP = -40004; | ||
| 18 | + public final static int INVALID_URI = -40005; | ||
| 19 | + | ||
| 20 | + private int code; | ||
| 21 | + | ||
| 22 | + private static String getMessage(int code) { | ||
| 23 | + switch (code) { | ||
| 24 | + case MISS_SIGN: | ||
| 25 | + return "sign参数丢失"; | ||
| 26 | + case MISS_TIMESTAMP: | ||
| 27 | + return "timestamp参数丢失"; | ||
| 28 | + case MISS_NONCE: | ||
| 29 | + return "nonce参数丢失"; | ||
| 30 | + case NO_RANDOM_NONCE: | ||
| 31 | + return "nonce参数异常"; | ||
| 32 | + case MISS_PWD: | ||
| 33 | + return "密码参数丢失"; | ||
| 34 | + case INVALID_PWD: | ||
| 35 | + return "无效的密码"; | ||
| 36 | + case SIGN_CHECK_ERROR: | ||
| 37 | + return "签名校验时出现异常"; | ||
| 38 | + case SIGN_CHECK_FAIL: | ||
| 39 | + return "无效的签名"; | ||
| 40 | + case INVALID_TIMESTAMP: | ||
| 41 | + return "无效的时间戳"; | ||
| 42 | + case INVALID_URI: | ||
| 43 | + return "无效的URI"; | ||
| 44 | + default: | ||
| 45 | + return null; | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public int getCode() { | ||
| 50 | + return code; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public AesException(int code) { | ||
| 54 | + super(getMessage(code)); | ||
| 55 | + this.code = code; | ||
| 56 | + } | ||
| 57 | +} |
src/main/java/com/bsth/service/SystemParamService.java
0 → 100644
src/main/java/com/bsth/service/impl/SystemParamServiceImpl.java
0 → 100644
| 1 | +package com.bsth.service.impl; | ||
| 2 | + | ||
| 3 | +import com.bsth.entity.SystemParam; | ||
| 4 | +import com.bsth.repository.SystemParamRepository; | ||
| 5 | +import com.bsth.service.SystemParamService; | ||
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 7 | +import org.springframework.scheduling.annotation.EnableScheduling; | ||
| 8 | +import org.springframework.scheduling.annotation.Scheduled; | ||
| 9 | +import org.springframework.stereotype.Service; | ||
| 10 | + | ||
| 11 | +import java.util.HashMap; | ||
| 12 | +import java.util.Map; | ||
| 13 | + | ||
| 14 | +@Service | ||
| 15 | +@EnableScheduling | ||
| 16 | +public class SystemParamServiceImpl implements SystemParamService { | ||
| 17 | + | ||
| 18 | + @Autowired | ||
| 19 | + private SystemParamRepository systemParamRepository; | ||
| 20 | + | ||
| 21 | + private Map<String, String> pairs = new HashMap<>(); | ||
| 22 | + | ||
| 23 | + @Scheduled(cron = "0 0/30 * * * ?") | ||
| 24 | + public void refresh() { | ||
| 25 | + for (SystemParam sp : systemParamRepository.findAll()) { | ||
| 26 | + pairs.put(sp.getKey(), sp.getValue()); | ||
| 27 | + } | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + public String getValue(String key) { | ||
| 31 | + return pairs.get(key); | ||
| 32 | + } | ||
| 33 | +} |
src/main/resources/application-prod.properties
| 1 | -server.port=9089 | ||
| 2 | -management.port= 9001 | ||
| 3 | -management.address= 127.0.0.1 | ||
| 4 | - | ||
| 5 | -spring.jpa.hibernate.ddl-auto= none | ||
| 6 | -spring.jpa.hibernate.naming_strategy= org.hibernate.cfg.ImprovedNamingStrategy | ||
| 7 | -#DATABASE | ||
| 8 | -spring.jpa.database= MYSQL | ||
| 9 | -spring.jpa.show-sql= false | ||
| 10 | -spring.datasource.driver-class-name= com.mysql.jdbc.Driver | ||
| 11 | -spring.datasource.url= jdbc:mysql://10.10.150.103:3306/control?useUnicode=true&characterEncoding=utf-8&useSSL=false | ||
| 12 | -spring.datasource.username= root | ||
| 13 | -spring.datasource.password= Aa123456 | ||
| 14 | -#DATASOURCE | ||
| 15 | -spring.datasource.max-active=100 | ||
| 16 | -spring.datasource.max-idle=8 | ||
| 17 | -spring.datasource.min-idle=8 | ||
| 18 | -spring.datasource.initial-size=3 | ||
| 19 | - | ||
| 20 | -spring.datasource.test-on-borrow=true | ||
| 21 | -spring.datasource.test-on-connect=true | ||
| 22 | -spring.datasource.test-on-return=true | ||
| 23 | -spring.datasource.test-while-idle=true | ||
| 24 | -spring.datasource.validation-query=select 1 | ||
| 25 | - | ||
| 26 | -#REDIS | ||
| 27 | -spring.redis.database=0 | ||
| 28 | -spring.redis.host=10.10.150.103 | ||
| 29 | -spring.redis.password=bsth_control_001 | ||
| 30 | -spring.redis.port=28008 | ||
| 31 | - | ||
| 32 | -http.control.service_data_url= http://10.10.150.103:9088/companyService | ||
| 33 | -http.control.secret.key= dVPHJkWUt5FhMT7jrM2dLV7QvlHAmZFd42rs1P0usBx8A7HZki | ||
| 34 | - | 1 | +server.port=9089 |
| 2 | +management.port= 9001 | ||
| 3 | +management.address= 127.0.0.1 | ||
| 4 | + | ||
| 5 | +spring.jpa.hibernate.ddl-auto= none | ||
| 6 | +spring.jpa.hibernate.naming_strategy= org.hibernate.cfg.ImprovedNamingStrategy | ||
| 7 | +#DATABASE | ||
| 8 | +spring.jpa.database= MYSQL | ||
| 9 | +spring.jpa.show-sql= false | ||
| 10 | +spring.datasource.driver-class-name= com.mysql.jdbc.Driver | ||
| 11 | +spring.datasource.url= jdbc:mysql://10.10.150.103:3306/control?useUnicode=true&characterEncoding=utf-8&useSSL=false | ||
| 12 | +spring.datasource.username= root | ||
| 13 | +spring.datasource.password= fsodlgjiuigAQF2$9fs9 | ||
| 14 | +#DATASOURCE | ||
| 15 | +spring.datasource.max-active=100 | ||
| 16 | +spring.datasource.max-idle=8 | ||
| 17 | +spring.datasource.min-idle=8 | ||
| 18 | +spring.datasource.initial-size=3 | ||
| 19 | + | ||
| 20 | +spring.datasource.test-on-borrow=true | ||
| 21 | +spring.datasource.test-on-connect=true | ||
| 22 | +spring.datasource.test-on-return=true | ||
| 23 | +spring.datasource.test-while-idle=true | ||
| 24 | +spring.datasource.validation-query=select 1 | ||
| 25 | + | ||
| 26 | +#REDIS | ||
| 27 | +spring.redis.database=0 | ||
| 28 | +spring.redis.host=10.10.150.103 | ||
| 29 | +spring.redis.password=bsth_control_001 | ||
| 30 | +spring.redis.port=28008 | ||
| 31 | + | ||
| 32 | +http.control.service_data_url= http://10.10.150.103:9088/companyService | ||
| 33 | +http.control.secret.key= dVPHJkWUt5FhMT7jrM2dLV7QvlHAmZFd42rs1P0usBx8A7HZki | ||
| 34 | + | ||
| 35 | http.gps.real.url= http://10.10.150.103:8080/transport_server/rtgps/ | 35 | http.gps.real.url= http://10.10.150.103:8080/transport_server/rtgps/ |
| 36 | \ No newline at end of file | 36 | \ No newline at end of file |