|
@@ -1,9 +1,20 @@
|
|
|
package com.dragoninfo.dcuc.authweb.restcontroller.api.authservice.v2.controller;
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.auth0.jwt.JWT;
|
|
|
+import com.auth0.jwt.algorithms.Algorithm;
|
|
|
+import com.auth0.jwt.interfaces.DecodedJWT;
|
|
|
import com.dragoninfo.dcuc.auth.auth.api.IApiDataAuthFacade;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.dto.data.DataAuthV2ReqDTO;
|
|
|
import com.dragoninfo.dcuc.auth.auth.vo.DataAuthV2ReqVO;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.dto.data.DataAuthV2RespDTO;
|
|
|
import com.dragoninfo.dcuc.auth.auth.vo.DataAuthV2RespVO;
|
|
|
+import com.dragoninfo.dcuc.auth.sub.dto.AuthUserDTO;
|
|
|
+import com.dragoninfo.dcuc.auth.sub.facade.IAuthUserInfoFacade;
|
|
|
+import com.dragoninfo.dcuc.authweb.restcontroller.api.authservice.v4.enums.BusinessRespEnum;
|
|
|
+import com.dragoninfo.dcuc.authweb.restcontroller.api.authservice.v4.vo.ResultRespVO;
|
|
|
import com.dragoninfo.dcuc.authweb.util.VersionUtils;
|
|
|
+import com.dragoninfo.dcuc.common.utils.ResponseUtil;
|
|
|
import com.dragonsoft.duceap.base.entity.http.ResponseDTO;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
@@ -15,6 +26,11 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* 数据鉴权
|
|
|
*
|
|
@@ -30,10 +46,50 @@ public class DataAuthApiV2Controller {
|
|
|
@Autowired
|
|
|
private IApiDataAuthFacade apiDataAuthFacade;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IAuthUserInfoFacade userFacade;
|
|
|
+
|
|
|
@ApiOperation(value = "数据鉴权")
|
|
|
@ApiImplicitParams({@ApiImplicitParam(name = "dataAuthV2ReqVO", value = "数据资源对象")})
|
|
|
@PostMapping(value = "data-auth/data-items/check")
|
|
|
- public ResponseDTO<DataAuthV2RespVO> checkDataItems(@RequestBody DataAuthV2ReqVO dataAuthV2ReqVO) {
|
|
|
- return apiDataAuthFacade.dataItemsCheckV2(dataAuthV2ReqVO);
|
|
|
+ public ResultRespVO<DataAuthV2RespVO> checkDataItems(@RequestBody DataAuthV2ReqVO dataAuthV2ReqVO) {
|
|
|
+ String appTokenId = dataAuthV2ReqVO.getAppTokenId();
|
|
|
+
|
|
|
+ if (StrUtil.isBlank(appTokenId)) {
|
|
|
+ return ResultRespVO.resultEnumMessage(BusinessRespEnum.TOKEN_FAIL);
|
|
|
+ }
|
|
|
+
|
|
|
+ String resourceId = dataAuthV2ReqVO.getResourceId();
|
|
|
+ if (StrUtil.isBlank(resourceId)) {
|
|
|
+ return ResultRespVO.resultEnumMessage(BusinessRespEnum.PARAM_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ DecodedJWT decode = JWT.decode(appTokenId);
|
|
|
+ String idcard = decode.getClaim("idCard").asString();
|
|
|
+
|
|
|
+ AuthUserDTO userInfo = userFacade.findByIdcard(idcard);
|
|
|
+ if (userInfo == null) {
|
|
|
+ return ResultRespVO.respRequestErrorMessage("用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ DataAuthV2ReqDTO reqDTO = new DataAuthV2ReqDTO();
|
|
|
+ reqDTO.setResourceId(resourceId);
|
|
|
+ reqDTO.setIdcard(userInfo.getIdcard());
|
|
|
+ ResponseDTO<DataAuthV2RespDTO> dto = apiDataAuthFacade.dataItemsCheckV2(reqDTO);
|
|
|
+ if (!ResponseUtil.isSuccess(dto)) {
|
|
|
+ return ResultRespVO.resultEnumMessage(BusinessRespEnum.AUTH_FAIL);
|
|
|
+ } else {
|
|
|
+ DataAuthV2RespDTO respDTO = (DataAuthV2RespDTO) dto.getResult();
|
|
|
+ Set<String> set = respDTO.getItemIdentifier();
|
|
|
+ String join = Optional.ofNullable(set)
|
|
|
+ .orElse(Collections.emptySet())
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.joining(StrUtil.COMMA));
|
|
|
+ DataAuthV2RespVO respVO = new DataAuthV2RespVO();
|
|
|
+ respVO.setResourceId(resourceId);
|
|
|
+ respVO.setItemIdentifier(join);
|
|
|
+ return ResultRespVO.success(respVO);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|