|
@@ -0,0 +1,203 @@
|
|
|
+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.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.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.authweb.restcontroller.api.authservice.v4.vo.*;
|
|
|
+import com.dragoninfo.dcuc.common.utils.LangUtil;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+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.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ *
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author huangzqa
|
|
|
+ * @date 2022/8/24
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@Api(tags = {"权限管理对外开放接口V4"})
|
|
|
+@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;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 应用级鉴权
|
|
|
+ *
|
|
|
+ * @param appAuthReqVO 应用级鉴权请求
|
|
|
+ * @return 应用级权限
|
|
|
+ */
|
|
|
+ @PostMapping("appAuth")
|
|
|
+ public ResultRespVO<String> appAuth(@RequestBody AppAuthReqVO appAuthReqVO) {
|
|
|
+ String appTokenId = appAuthReqVO.getAppTokenId();
|
|
|
+
|
|
|
+ if (StrUtil.isBlank(appTokenId)) {
|
|
|
+ return ResultRespVO.resultEnumMessage(BusinessRespEnum.TOKEN_FAIL);
|
|
|
+ }
|
|
|
+
|
|
|
+ DecodedJWT decode = JWT.decode(appTokenId);
|
|
|
+ String idcard = decode.getClaim("idCard").asString();
|
|
|
+
|
|
|
+ AuthUserDTO userInfo = userFacade.findByIdcard(idcard);
|
|
|
+ if (userInfo == null) {
|
|
|
+ return ResultRespVO.respRequestErrorMessage("用户不存在");
|
|
|
+ }
|
|
|
+ String userId = userInfo.getId();
|
|
|
+ List<AppDataSensitiveLevelDTO> appList = staffAssignAuthInfoFacade.getAppLitByUserId(userId);
|
|
|
+
|
|
|
+ StringBuilder appAuthBuilder = new StringBuilder();
|
|
|
+
|
|
|
+ for (AppDataSensitiveLevelDTO appDataSensitiveLevelDTO : appList) {
|
|
|
+ String code = appDataSensitiveLevelDTO.getCode();
|
|
|
+
|
|
|
+ appAuthBuilder.append(code).append(StrUtil.COMMA);
|
|
|
+ }
|
|
|
+
|
|
|
+ String appAuth = LangUtil.subLastSymbol(appAuthBuilder.toString(), StrUtil.COMMA);
|
|
|
+ return ResultRespVO.success(appAuth);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 功能级鉴权
|
|
|
+ *
|
|
|
+ * @param functionAuthReqVO 功能级鉴权求
|
|
|
+ * @return 功能级鉴权
|
|
|
+ */
|
|
|
+ @PostMapping("functionAuth")
|
|
|
+ public ResultRespVO<String> functionAuth(@RequestBody FunctionAuthReqVO functionAuthReqVO) {
|
|
|
+ String appTokenId = functionAuthReqVO.getAppTokenId();
|
|
|
+ String taskId = functionAuthReqVO.getTaskId();
|
|
|
+
|
|
|
+ if (StrUtil.isBlank(appTokenId)) {
|
|
|
+ return ResultRespVO.resultEnumMessage(BusinessRespEnum.TOKEN_FAIL);
|
|
|
+ }
|
|
|
+
|
|
|
+ DecodedJWT decode = JWT.decode(appTokenId);
|
|
|
+ String idcard = decode.getClaim("idCard").asString();
|
|
|
+ String appCode = decode.getClaim("appCode").asString();
|
|
|
+
|
|
|
+
|
|
|
+ AuthUserDTO userInfo = authUserInfoFacade.findByIdcard(idcard);
|
|
|
+ if (userInfo == null) {
|
|
|
+ return ResultRespVO.respRequestErrorMessage("idcard无权限,或身份证错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ RoleApiDto roleApiDto = new RoleApiDto();
|
|
|
+ roleApiDto.setAppCode(appCode);
|
|
|
+ roleApiDto.setUserId(userInfo.getId());
|
|
|
+ roleApiDto.setIdcard(idcard);
|
|
|
+ List<AppFunInfoDTO> menus = roleFacade.getMenus(roleApiDto);
|
|
|
+
|
|
|
+ StringBuilder functionAuthBuilder = new StringBuilder();
|
|
|
+
|
|
|
+ for (AppFunInfoDTO menu : menus) {
|
|
|
+ String code = menu.getCode();
|
|
|
+ functionAuthBuilder.append(code).append(StrUtil.COMMA);
|
|
|
+ }
|
|
|
+
|
|
|
+ String appAuth = LangUtil.subLastSymbol(functionAuthBuilder.toString(), StrUtil.COMMA);
|
|
|
+ return ResultRespVO.success(appAuth);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 服务级鉴权
|
|
|
+ *
|
|
|
+ * @param serviceAuthReqVO 服务级鉴权请求
|
|
|
+ * @return 服务级鉴权
|
|
|
+ */
|
|
|
+ @PostMapping("serviceAuth")
|
|
|
+ public ResultRespVO<String> serviceAuth(@RequestBody ServiceAuthReqVO serviceAuthReqVO) {
|
|
|
+ String appTokenId = serviceAuthReqVO.getAppTokenId();
|
|
|
+ String taskId = serviceAuthReqVO.getTaskId();
|
|
|
+ if (StrUtil.isBlank(appTokenId)) {
|
|
|
+ return ResultRespVO.resultEnumMessage(BusinessRespEnum.TOKEN_FAIL);
|
|
|
+ }
|
|
|
+
|
|
|
+ DecodedJWT decode = JWT.decode(appTokenId);
|
|
|
+ String appCode = decode.getClaim("appCode").asString();
|
|
|
+ String idcard = decode.getClaim("idcard").asString();
|
|
|
+
|
|
|
+ List<ServiceAuthenticationResVO> serviceAuthenticationResVOList = serviceAuthFlowFacade.serviceAuthentication(idcard, appCode, "", "");
|
|
|
+
|
|
|
+ StringBuilder serviceAuthBuilder = new StringBuilder();
|
|
|
+
|
|
|
+ for (ServiceAuthenticationResVO serviceAuthenticationResVO : serviceAuthenticationResVOList) {
|
|
|
+ String serviceCode = serviceAuthenticationResVO.getServiceCode();
|
|
|
+ serviceAuthBuilder.append(serviceCode).append(StrUtil.COMMA);
|
|
|
+ }
|
|
|
+
|
|
|
+ String serviceAuth = LangUtil.subLastSymbol(serviceAuthBuilder.toString(), StrUtil.COMMA);
|
|
|
+ return ResultRespVO.success(serviceAuth);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据级鉴权
|
|
|
+ *
|
|
|
+ * @param dataAuthReqVO 数据级鉴权
|
|
|
+ * @return 数据级鉴权
|
|
|
+ */
|
|
|
+ @PostMapping("dataAuth")
|
|
|
+ public ResultRespVO<List<DataAuthRespVO>> dataAuth(@RequestBody DataAuthReqVO dataAuthReqVO) {
|
|
|
+ String resourceId = dataAuthReqVO.getResourceId();
|
|
|
+ String taskId = dataAuthReqVO.getTaskId();
|
|
|
+
|
|
|
+ // todo 数据级鉴权
|
|
|
+
|
|
|
+ DataAuthRespVO dataAuthRespVO = new DataAuthRespVO();
|
|
|
+
|
|
|
+ List<DataAuthRespVO> dataAuthRespVOList = new ArrayList<>();
|
|
|
+ dataAuthRespVOList.add(dataAuthRespVO);
|
|
|
+ return ResultRespVO.success(dataAuthRespVOList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("userOrgDataAuth")
|
|
|
+ public ResultRespVO<DataAuthRespVO> userOrgDataAuth(@RequestBody UserOrgAuthReqVO userOrgAuthReqVO) {
|
|
|
+
|
|
|
+ String orgCode = userOrgAuthReqVO.getOrgCode();
|
|
|
+ String idcard = userOrgAuthReqVO.getIdcard();
|
|
|
+
|
|
|
+ DataItemsDto dataItemsDto = apiDataAuthFacade.userOrgDataAuth(idcard, orgCode);
|
|
|
+
|
|
|
+ DataAuthRespVO dataAuthRespVO = new DataAuthRespVO();
|
|
|
+ dataAuthRespVO.setResourceId(dataItemsDto.getResourceCode());
|
|
|
+ dataAuthRespVO.setItemIdentifier(dataItemsDto.getDataItemCode());
|
|
|
+ return ResultRespVO.success(dataAuthRespVO);
|
|
|
+ }
|
|
|
+}
|