|
|
@@ -28,10 +28,9 @@ public class ApiSignLoginInterceptor extends HandlerInterceptorAdapter {
|
|
|
private static final String TIMESTAMP_KEY = "Timestamp";
|
|
|
private static final String SIGN_KEY = "Signature";
|
|
|
private static final String RequestId = "RequestId";
|
|
|
- private static Map<String,String> tokenConfig = TokenProperties.getAllProperty();
|
|
|
+ private static final String FCODE = "fCode";//工厂代码
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
|
|
logger.info(String.format("Content-Type:%s,URI:%s,Header:%s,bodyparam:%s"
|
|
|
@@ -46,13 +45,12 @@ public class ApiSignLoginInterceptor extends HandlerInterceptorAdapter {
|
|
|
String accessKey = request.getHeader(ACCESS_KEY);
|
|
|
String requestId = request.getHeader(RequestId);
|
|
|
String originSign = request.getHeader(SIGN_KEY);
|
|
|
- Object accessSecret_O = baseDao.getFieldDataByCondition("EMPLOYEE", "EM_APISECRET", "EM_CODE='" + accessKey + "' and nvl(EM_ISAPI,0)<>0");
|
|
|
- String accessSecret = accessSecret_O == null ? "" : accessSecret_O.toString();
|
|
|
+ String fCode = request.getHeader(FCODE);
|
|
|
logger.info("timestamp=="+timestamp);
|
|
|
logger.info("accessKey=="+accessKey);
|
|
|
logger.info("requestId=="+requestId);
|
|
|
logger.info("originSign=="+originSign);
|
|
|
-
|
|
|
+ logger.info("fCode=="+fCode);
|
|
|
if (StringUtils.isEmpty(requestId)) {
|
|
|
ApiResult apiResult = new ApiResult();
|
|
|
apiResult.setCode(ErrorMessage.REQUESTID_ILLEGAL.getCode());
|
|
|
@@ -67,16 +65,6 @@ public class ApiSignLoginInterceptor extends HandlerInterceptorAdapter {
|
|
|
apiResult.setRequestId(requestId);
|
|
|
throw new ApiSystemException(apiResult);
|
|
|
}
|
|
|
-
|
|
|
- // 检查KEY是否合理
|
|
|
- if (StringUtils.isEmpty(accessKey) || StringUtils.isEmpty(accessSecret)) {
|
|
|
- ApiResult apiResult = new ApiResult();
|
|
|
- apiResult.setCode(ErrorMessage.ACCESSKEY_ILLEGAL.getCode());
|
|
|
- apiResult.setMessage(ErrorMessage.ACCESSKEY_ILLEGAL.getMessage());
|
|
|
- apiResult.setRequestId(requestId);
|
|
|
- throw new ApiSystemException(apiResult);
|
|
|
- }
|
|
|
-
|
|
|
Long ts = Long.valueOf(timestamp);
|
|
|
// 禁止超时签名
|
|
|
if (System.currentTimeMillis() - ts > SIGN_EXPIRED_TIME) {
|
|
|
@@ -87,7 +75,50 @@ public class ApiSignLoginInterceptor extends HandlerInterceptorAdapter {
|
|
|
System.out.println(System.currentTimeMillis());
|
|
|
throw new ApiSystemException(apiResult);
|
|
|
}
|
|
|
-
|
|
|
+ if (StringUtils.isEmpty(accessKey)) {
|
|
|
+ ApiResult apiResult = new ApiResult();
|
|
|
+ apiResult.setCode(ErrorMessage.ACCESSKEY_ILLEGAL.getCode());
|
|
|
+ apiResult.setMessage(ErrorMessage.ACCESSKEY_ILLEGAL.getMessage());
|
|
|
+ apiResult.setRequestId(requestId);
|
|
|
+ throw new ApiSystemException(apiResult);
|
|
|
+ }
|
|
|
+ //判断工厂
|
|
|
+ if(StringUtils.isEmpty(fCode)) {
|
|
|
+ ApiResult apiResult = new ApiResult();
|
|
|
+ apiResult.setCode(ErrorMessage.FAC_EMPTY.getCode());
|
|
|
+ apiResult.setMessage(ErrorMessage.FAC_EMPTY.getMessage());
|
|
|
+ apiResult.setRequestId(requestId);
|
|
|
+ throw new ApiSystemException(apiResult);
|
|
|
+ }
|
|
|
+ if(!baseDao.checkIf("MESAPI_FAC","FCODE='"+fCode+"' and ACCESSKEY = '"+accessKey+"' and MACODE is not null and APISECRET is not null ")) {
|
|
|
+ ApiResult apiResult = new ApiResult();
|
|
|
+ apiResult.setCode(ErrorMessage.FAC_ILLEGAL.getCode());
|
|
|
+ apiResult.setMessage(String.format(ErrorMessage.FAC_ILLEGAL.getMessage(),fCode));
|
|
|
+ apiResult.setRequestId(requestId);
|
|
|
+ throw new ApiSystemException(apiResult);
|
|
|
+ }
|
|
|
+ if(!baseDao.checkIf("MESAPI_FAC","FCODE='"+fCode+"' and ACCESSKEY = '"+accessKey+"' and ENABLED = 1 ")) {
|
|
|
+ ApiResult apiResult = new ApiResult();
|
|
|
+ apiResult.setCode(ErrorMessage.FAC_DISABLED.getCode());
|
|
|
+ apiResult.setMessage(String.format(ErrorMessage.FAC_DISABLED.getMessage(),fCode));
|
|
|
+ apiResult.setRequestId(requestId);
|
|
|
+ throw new ApiSystemException(apiResult);
|
|
|
+ }
|
|
|
+ if(!baseDao.checkIf("MESAPI_FAC,master","ma_user = MACODE and FCODE='"+fCode+"' and ACCESSKEY = '"+accessKey+"'")){
|
|
|
+ ApiResult apiResult = new ApiResult();
|
|
|
+ apiResult.setCode(ErrorMessage.FAC_ILLEGAL.getCode());
|
|
|
+ apiResult.setMessage(String.format(ErrorMessage.FAC_ILLEGAL.getMessage(),fCode));
|
|
|
+ apiResult.setRequestId(requestId);
|
|
|
+ throw new ApiSystemException(apiResult);
|
|
|
+ }
|
|
|
+ String accessSecret = baseDao.getFieldDataByCondition("MESAPI_FAC", "nvl(max(APISECRET),'')", "FCODE='"+fCode+"' and ACCESSKEY = '"+accessKey+"' and ENABLED = 1 ").toString();
|
|
|
+ if (StringUtils.isEmpty(accessSecret)) {
|
|
|
+ ApiResult apiResult = new ApiResult();
|
|
|
+ apiResult.setCode(ErrorMessage.ACCESSKEY_ILLEGAL.getCode());
|
|
|
+ apiResult.setMessage(ErrorMessage.ACCESSKEY_ILLEGAL.getMessage());
|
|
|
+ apiResult.setRequestId(requestId);
|
|
|
+ throw new ApiSystemException(apiResult);
|
|
|
+ }
|
|
|
if (!verificationSign(accessKey, accessSecret,timestamp,requestId,originSign)) {
|
|
|
ApiResult apiResult = new ApiResult();
|
|
|
apiResult.setCode(ErrorMessage.SIGNATURE_ILLEGAL.getCode());
|