|
@@ -1,22 +1,27 @@
|
|
|
package com.dragoninfo.dcuc.authweb.restcontroller.api.authservice.v4.controller;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
-import com.auth0.jwt.JWT;
|
|
|
-import com.auth0.jwt.interfaces.DecodedJWT;
|
|
|
+import com.dragoninfo.dcuc.auth.api.vo.BusinessRespEnum;
|
|
|
+import com.dragoninfo.dcuc.auth.api.vo.ResultRespVO;
|
|
|
import com.dragoninfo.dcuc.auth.auth.api.IApiDataAuthFacade;
|
|
|
import com.dragoninfo.dcuc.auth.auth.dto.AppDataSensitiveLevelDTO;
|
|
|
import com.dragoninfo.dcuc.auth.auth.dto.AppFunInfoDTO;
|
|
|
import com.dragoninfo.dcuc.auth.auth.dto.DataItemsDto;
|
|
|
import com.dragoninfo.dcuc.auth.auth.dto.RoleApiDto;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.dto.data.DataAuthV2ReqDTO;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.dto.data.DataAuthV2RespDTO;
|
|
|
import com.dragoninfo.dcuc.auth.auth.facade.IRoleFacade;
|
|
|
import com.dragoninfo.dcuc.auth.auth.facade.IServiceAuthFlowFacade;
|
|
|
import com.dragoninfo.dcuc.auth.auth.facade.IStaffAssignAuthInfoFacade;
|
|
|
import com.dragoninfo.dcuc.auth.auth.vo.ServiceAuthenticationResVO;
|
|
|
-import com.dragoninfo.dcuc.authweb.restcontroller.api.authservice.v4.enums.BusinessRespEnum;
|
|
|
-import com.dragoninfo.dcuc.auth.sub.dto.AuthUserDTO;
|
|
|
-import com.dragoninfo.dcuc.auth.sub.facade.IAuthUserInfoFacade;
|
|
|
+import com.dragoninfo.dcuc.auth.sub.vo.AuthUserVo;
|
|
|
+import com.dragoninfo.dcuc.auth.token.facade.IAuthTokenFacade;
|
|
|
+import com.dragoninfo.dcuc.auth.token.vo.TokenDetailRespVo;
|
|
|
+import com.dragoninfo.dcuc.auth.token.vo.UserTokenInfoRespVO;
|
|
|
import com.dragoninfo.dcuc.authweb.restcontroller.api.authservice.v4.vo.*;
|
|
|
import com.dragoninfo.dcuc.common.utils.LangUtil;
|
|
|
+import com.dragoninfo.dcuc.common.utils.ResponseUtil;
|
|
|
+import com.dragonsoft.duceap.base.entity.http.ResponseDTO;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
@@ -24,8 +29,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.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -40,24 +48,21 @@ import java.util.List;
|
|
|
@RequestMapping(value = "/api/auth-service/v4/")
|
|
|
public class AuthV4Controller {
|
|
|
|
|
|
- @Autowired
|
|
|
- private IAuthUserInfoFacade userFacade;
|
|
|
-
|
|
|
@Autowired
|
|
|
private IStaffAssignAuthInfoFacade staffAssignAuthInfoFacade;
|
|
|
|
|
|
@Autowired
|
|
|
private IServiceAuthFlowFacade serviceAuthFlowFacade;
|
|
|
|
|
|
- @Autowired
|
|
|
- private IAuthUserInfoFacade authUserInfoFacade;
|
|
|
-
|
|
|
@Autowired
|
|
|
private IRoleFacade roleFacade;
|
|
|
|
|
|
@Autowired
|
|
|
private IApiDataAuthFacade apiDataAuthFacade;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IAuthTokenFacade authTokenFacade;
|
|
|
+
|
|
|
/**
|
|
|
* 应用级鉴权
|
|
|
*
|
|
@@ -72,13 +77,19 @@ public class AuthV4Controller {
|
|
|
return ResultRespVO.resultEnumMessage(BusinessRespEnum.TOKEN_FAIL);
|
|
|
}
|
|
|
|
|
|
- DecodedJWT decode = JWT.decode(appTokenId);
|
|
|
- String idcard = decode.getClaim("idCard").asString();
|
|
|
+ TokenDetailRespVo tokenInfo = authTokenFacade.getByAppTokenId(appTokenId, true, false);
|
|
|
|
|
|
- AuthUserDTO userInfo = userFacade.findByIdcard(idcard);
|
|
|
+ AuthUserVo userInfo = tokenInfo.getUserInfo();
|
|
|
if (userInfo == null) {
|
|
|
return ResultRespVO.respRequestErrorMessage("用户不存在");
|
|
|
}
|
|
|
+
|
|
|
+ // 缓存应用令牌
|
|
|
+ UserTokenInfoRespVO userToken = tokenInfo.getUserToken();
|
|
|
+ int expiredTime = (int) ((userToken.getExpireAt().getTime() - System.currentTimeMillis()) / 1000);
|
|
|
+
|
|
|
+ authTokenFacade.cacheStandardUserToken(userInfo.getIdcard(), userToken.getId(), expiredTime);
|
|
|
+
|
|
|
String userId = userInfo.getId();
|
|
|
List<AppDataSensitiveLevelDTO> appList = staffAssignAuthInfoFacade.getAppLitByUserId(userId);
|
|
|
|
|
@@ -106,23 +117,19 @@ public class AuthV4Controller {
|
|
|
String taskId = functionAuthReqVO.getTaskId();
|
|
|
|
|
|
if (StrUtil.isBlank(appTokenId)) {
|
|
|
- return ResultRespVO.resultEnumMessage(BusinessRespEnum.TOKEN_FAIL);
|
|
|
+ return ResultRespVO.resultEnumMessage(BusinessRespEnum.PARAM_ERROR);
|
|
|
}
|
|
|
-
|
|
|
- DecodedJWT decode = JWT.decode(appTokenId);
|
|
|
- String idcard = decode.getClaim("idCard").asString();
|
|
|
- String appCode = decode.getClaim("appCode").asString();
|
|
|
-
|
|
|
-
|
|
|
- AuthUserDTO userInfo = authUserInfoFacade.findByIdcard(idcard);
|
|
|
+ TokenDetailRespVo tokenInfo = authTokenFacade.getByAppTokenId(appTokenId, true, false);
|
|
|
+ AuthUserVo userInfo = tokenInfo.getUserInfo();
|
|
|
if (userInfo == null) {
|
|
|
- return ResultRespVO.respRequestErrorMessage("idcard无权限,或身份证错误");
|
|
|
+ return ResultRespVO.resultEnumMessage(BusinessRespEnum.AUTH_FAIL);
|
|
|
}
|
|
|
+ String appCode = tokenInfo.getAppToken().getAppId();
|
|
|
|
|
|
RoleApiDto roleApiDto = new RoleApiDto();
|
|
|
roleApiDto.setAppCode(appCode);
|
|
|
roleApiDto.setUserId(userInfo.getId());
|
|
|
- roleApiDto.setIdcard(idcard);
|
|
|
+ roleApiDto.setIdcard(userInfo.getIdcard());
|
|
|
List<AppFunInfoDTO> menus = roleFacade.getMenus(roleApiDto);
|
|
|
|
|
|
StringBuilder functionAuthBuilder = new StringBuilder();
|
|
@@ -147,14 +154,17 @@ public class AuthV4Controller {
|
|
|
String appTokenId = serviceAuthReqVO.getAppTokenId();
|
|
|
String taskId = serviceAuthReqVO.getTaskId();
|
|
|
if (StrUtil.isBlank(appTokenId)) {
|
|
|
- return ResultRespVO.resultEnumMessage(BusinessRespEnum.TOKEN_FAIL);
|
|
|
+ return ResultRespVO.resultEnumMessage(BusinessRespEnum.PARAM_ERROR);
|
|
|
}
|
|
|
|
|
|
- DecodedJWT decode = JWT.decode(appTokenId);
|
|
|
- String appCode = decode.getClaim("appCode").asString();
|
|
|
- String idcard = decode.getClaim("idcard").asString();
|
|
|
+ TokenDetailRespVo tokenInfo = authTokenFacade.getByAppTokenId(appTokenId, true, false);
|
|
|
+ AuthUserVo userInfo = tokenInfo.getUserInfo();
|
|
|
+ if (userInfo == null) {
|
|
|
+ return ResultRespVO.resultEnumMessage(BusinessRespEnum.AUTH_FAIL);
|
|
|
+ }
|
|
|
+ String appCode = tokenInfo.getAppToken().getAppId();
|
|
|
|
|
|
- List<ServiceAuthenticationResVO> serviceAuthenticationResVOList = serviceAuthFlowFacade.serviceAuthentication(idcard, appCode, "", "");
|
|
|
+ List<ServiceAuthenticationResVO> serviceAuthenticationResVOList = serviceAuthFlowFacade.serviceAuthentication(userInfo.getIdcard(), appCode, "", "");
|
|
|
|
|
|
StringBuilder serviceAuthBuilder = new StringBuilder();
|
|
|
|
|
@@ -175,16 +185,41 @@ public class AuthV4Controller {
|
|
|
*/
|
|
|
@PostMapping("dataAuth")
|
|
|
public ResultRespVO<List<DataAuthRespVO>> dataAuth(@RequestBody DataAuthReqVO dataAuthReqVO) {
|
|
|
- String resourceId = dataAuthReqVO.getResourceId();
|
|
|
- String taskId = dataAuthReqVO.getTaskId();
|
|
|
+ String appTokenId = dataAuthReqVO.getAppTokenId();
|
|
|
+
|
|
|
+ if (StrUtil.isBlank(appTokenId)) {
|
|
|
+ return ResultRespVO.resultEnumMessage(BusinessRespEnum.PARAM_ERROR);
|
|
|
+ }
|
|
|
|
|
|
- // todo 数据级鉴权
|
|
|
+ String resourceId = dataAuthReqVO.getResourceId();
|
|
|
+ if (StrUtil.isBlank(resourceId)) {
|
|
|
+ return ResultRespVO.resultEnumMessage(BusinessRespEnum.PARAM_ERROR);
|
|
|
+ }
|
|
|
|
|
|
- DataAuthRespVO dataAuthRespVO = new DataAuthRespVO();
|
|
|
+ TokenDetailRespVo tokenInfo = authTokenFacade.getByAppTokenId(appTokenId, true, false);
|
|
|
+ AuthUserVo userInfo = tokenInfo.getUserInfo();
|
|
|
+ if (null == userInfo) {
|
|
|
+ return ResultRespVO.resultEnumMessage(BusinessRespEnum.AUTH_FAIL);
|
|
|
+ }
|
|
|
|
|
|
- List<DataAuthRespVO> dataAuthRespVOList = new ArrayList<>();
|
|
|
- dataAuthRespVOList.add(dataAuthRespVO);
|
|
|
- return ResultRespVO.success(dataAuthRespVOList);
|
|
|
+ DataAuthV2ReqDTO v2ReqDTO = new DataAuthV2ReqDTO();
|
|
|
+ v2ReqDTO.setIdcard(userInfo.getIdcard());
|
|
|
+ v2ReqDTO.setResourceId(resourceId);
|
|
|
+
|
|
|
+ ResponseDTO<DataAuthV2RespDTO> dto = apiDataAuthFacade.dataItemsCheckV2(v2ReqDTO);
|
|
|
+ if (!ResponseUtil.isSuccess(dto)) {
|
|
|
+ return ResultRespVO.resultEnumMessage(BusinessRespEnum.AUTH_FAIL);
|
|
|
+ } else {
|
|
|
+ DataAuthV2RespDTO respDTO = (DataAuthV2RespDTO) dto.getResult();
|
|
|
+ Set<String> resultSet = respDTO.getItemIdentifier();
|
|
|
+ List<DataAuthRespVO> collect = Optional.ofNullable(resultSet).orElse(Collections.emptySet()).stream().map(e -> {
|
|
|
+ DataAuthRespVO vo = new DataAuthRespVO();
|
|
|
+ vo.setResourceId(resourceId);
|
|
|
+ vo.setItemIdentifier(e);
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return ResultRespVO.success(collect);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@PostMapping("userOrgDataAuth")
|