| | |
| | | import com.java110.common.log.LoggerEngine; |
| | | import com.java110.common.util.DateUtil; |
| | | import com.java110.common.util.StringUtil; |
| | | import com.java110.core.client.RestTemplate; |
| | | import com.java110.core.context.ApiDataFlow; |
| | | import com.java110.core.context.DataFlow; |
| | | import com.java110.core.factory.AuthenticationFactory; |
| | |
| | | import com.java110.event.service.api.ServiceDataFlowEventPublishing; |
| | | import com.java110.service.smo.IQueryServiceSMO; |
| | | import org.apache.commons.lang3.math.NumberUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | //@Transactional |
| | | public class ApiServiceSMOImpl extends LoggerEngine implements IApiServiceSMO { |
| | | |
| | | private final static Logger logger = LoggerFactory.getLogger(ApiServiceSMOImpl.class); |
| | | |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | |
| | | DataFlowFactory.addCostTime(dataFlow, "judgeAuthority", "鉴权耗时", startDate); |
| | | throw new NoAuthorityException(ResponseConstant.RESULT_CODE_NO_AUTHORITY_ERROR, "requestTime 格式不对,遵循yyyyMMddHHmmss格式"); |
| | | } |
| | | //用户ID校验 |
| | | if (StringUtil.isNullOrNone(dataFlow.getUserId())){ |
| | | throw new NoAuthorityException(ResponseConstant.RESULT_CODE_NO_AUTHORITY_ERROR, "USER_ID 不能为空"); |
| | | } |
| | | |
| | | |
| | | //判断 AppId 是否有权限操作相应的服务 |
| | |
| | | DataFlowFactory.addCostTime(dataFlow, "judgeAuthority", "鉴权耗时", startDate); |
| | | throw new NoAuthorityException(ResponseConstant.RESULT_CODE_NO_AUTHORITY_ERROR, "AppId 没有权限访问 serviceCode = " + dataFlow.getRequestHeaders().get(CommonConstant.HTTP_SERVICE)); |
| | | } |
| | | |
| | | |
| | | //检验白名单 |
| | | List<String> whileListIp = dataFlow.getAppRoutes().get(0).getWhileListIp(); |
| | |
| | | AppService appService = DataFlowFactory.getService(dataFlow, dataFlow.getRequestHeaders().get(CommonConstant.HTTP_SERVICE)); |
| | | //这里对透传类处理 |
| | | if("NT".equals(appService.getIsInstance())){ |
| | | //如果是透传类 请求方式必须与接口提供方调用方式一致 |
| | | String httpMethod = dataFlow.getRequestCurrentHeaders().get(CommonConstant.HTTP_METHOD); |
| | | if(!appService.getMethod().equals(httpMethod)) { |
| | | throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR, |
| | | "服务【" + appService.getServiceCode() + "】调用方式不对请检查,当前请求方式为:"+httpMethod); |
| | | } |
| | | dataFlow.setApiCurrentService(ServiceCodeConstant.SERVICE_CODE_DO_SERVICE_TRANSFER); |
| | | }else{ |
| | | dataFlow.setApiCurrentService(dataFlow.getRequestHeaders().get(CommonConstant.HTTP_SERVICE)); |