|
@@ -1,164 +0,0 @@
|
|
|
-package com.dragoninfo.dcuc.authweb.business.impl;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.dragoninfo.dcuc.app.entity.ApplyInfo;
|
|
|
-import com.dragoninfo.dcuc.app.facade.IApplyInfoFacade;
|
|
|
-import com.dragoninfo.dcuc.auth.sub.dto.AuthUserDTO;
|
|
|
-import com.dragoninfo.dcuc.auth.sub.facade.IAuthUserInfoFacade;
|
|
|
-import com.dragoninfo.dcuc.auth.sub.vo.ApplyInfoVo;
|
|
|
-import com.dragoninfo.dcuc.authweb.business.IAuthTokenBusiness;
|
|
|
-import com.dragoninfo.dcuc.authweb.config.DcucAuthWebConfig;
|
|
|
-import com.dragoninfo.dcuc.authweb.restcontroller.api.authservice.v4.vo.*;
|
|
|
-import com.dragoninfo.dcuc.authweb.restcontroller.sub.vo.user.AuthUserVo;
|
|
|
-import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
|
|
|
-import com.dragonsoft.duceap.commons.util.string.StringUtils;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.collections4.CollectionUtils;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.core.ParameterizedTypeReference;
|
|
|
-import org.springframework.http.HttpEntity;
|
|
|
-import org.springframework.http.HttpMethod;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.web.client.RestTemplate;
|
|
|
-
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-
|
|
|
- * token业务类
|
|
|
- *
|
|
|
- * @author mazq
|
|
|
- * @date 2023/2/14
|
|
|
- */
|
|
|
-@Slf4j
|
|
|
-@Service
|
|
|
-public class AuthTokenBusinessImpl implements IAuthTokenBusiness {
|
|
|
-
|
|
|
- private RestTemplate restTemplate;
|
|
|
-
|
|
|
- private DcucAuthWebConfig dcucAuthConfig;
|
|
|
-
|
|
|
- private IApplyInfoFacade applyInfoFacade;
|
|
|
-
|
|
|
- private IAuthUserInfoFacade userInfoFacade;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- public void setRestTemplate(RestTemplate restTemplate) {
|
|
|
- this.restTemplate = restTemplate;
|
|
|
- }
|
|
|
-
|
|
|
- @Autowired
|
|
|
- public void setApplyInfoFacade(IApplyInfoFacade applyInfoFacade) {
|
|
|
- this.applyInfoFacade = applyInfoFacade;
|
|
|
- }
|
|
|
-
|
|
|
- @Autowired
|
|
|
- public void setDcucAuthConfig(DcucAuthWebConfig dcucAuthConfig) {
|
|
|
- this.dcucAuthConfig = dcucAuthConfig;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public UserTokenInfoRespVO getUserTokenInfo(String userTokenId) {
|
|
|
-
|
|
|
- String tokenQueryUrl = dcucAuthConfig.getUserTokenQueryUrl();
|
|
|
- return getTokenInfo(tokenQueryUrl, userTokenId);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public AppTokenInfoRespVO getAppTokenInfo(String appTokenId) {
|
|
|
-
|
|
|
- String tokenQueryUrl = dcucAuthConfig.getAppTokenQueryUrl();
|
|
|
- return getTokenInfo(tokenQueryUrl, appTokenId);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public TokenDetailRespVo getByAppTokenId(String appTokenId, boolean needUserInfo, boolean needAppInfo) {
|
|
|
- AppTokenInfoRespVO appToken = getAppTokenInfo(appTokenId);
|
|
|
- if (null == appToken) {
|
|
|
- return TokenDetailRespVo.empty();
|
|
|
- }
|
|
|
- TokenDetailRespVo.TokenDetailRespVoBuilder builder = TokenDetailRespVo.builder();
|
|
|
- UserTokenInfoRespVO userToken = appToken.getUserToken();
|
|
|
- builder.appToken(appToken).userToken(userToken);
|
|
|
-
|
|
|
- if (needUserInfo) {
|
|
|
- AuthUserVo userVo = getAuthUserVo(userToken.getPId());
|
|
|
- builder.userInfo(userVo);
|
|
|
- }
|
|
|
-
|
|
|
- if (needAppInfo) {
|
|
|
- ApplyInfoVo applyInfoVo = new ApplyInfoVo();
|
|
|
- String appCode = appToken.getAppId();
|
|
|
- ApplyInfo applyInfo = applyInfoFacade.getAppByCode(appCode);
|
|
|
- BeanUtils.copyProperties(applyInfo, applyInfoVo);
|
|
|
- builder.applyInfo(applyInfoVo);
|
|
|
- }
|
|
|
- return builder.build();
|
|
|
- }
|
|
|
-
|
|
|
- private AuthUserVo getAuthUserVo(String pid) {
|
|
|
- TokenUserInfoRespVo userInfoRespVo = getTokenUserByPid(pid);
|
|
|
- if (userInfoRespVo == null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- String idcard = userInfoRespVo.getIdcard();
|
|
|
- AuthUserDTO authUserInfo = userInfoFacade.findByIdcard(idcard);
|
|
|
- if (null == authUserInfo) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- AuthUserVo userVo = new AuthUserVo();
|
|
|
- BeanUtils.copyProperties(authUserInfo, userVo);
|
|
|
- return userVo;
|
|
|
- }
|
|
|
-
|
|
|
- private TokenUserInfoRespVo getTokenUserByPid(String pid) {
|
|
|
- if (StringUtils.isBlank(pid)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- String url = dcucAuthConfig.getUserInfoQueryUrl();
|
|
|
- TokenUserInfoReqVo userReqVo = new TokenUserInfoReqVo();
|
|
|
- userReqVo.setId(pid);
|
|
|
- HttpEntity<TokenUserInfoReqVo> entity = new HttpEntity<>(userReqVo);
|
|
|
- ResponseEntity<ResultRespPageVo<TokenUserInfoRespVo>> response = restTemplate.exchange(url, HttpMethod.POST, entity, new ParameterizedTypeReference<ResultRespPageVo<TokenUserInfoRespVo>>() {
|
|
|
- });
|
|
|
- ResultRespPageVo<TokenUserInfoRespVo> respBody = getRespBody(response);
|
|
|
- if (null == respBody) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- ResultRespPageVo.ResultPageContent<TokenUserInfoRespVo> pageContent = respBody.getResult();
|
|
|
- if (null == pageContent) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- List<TokenUserInfoRespVo> rows = pageContent.getRows();
|
|
|
- return CollectionUtils.isEmpty(rows) ? null : rows.get(0);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private <T> T getTokenInfo(String tokenQueryUrl, Object... param) {
|
|
|
- ResponseEntity<ResultRespVO<T>> response = restTemplate.exchange(tokenQueryUrl, HttpMethod.GET, null,
|
|
|
- new ParameterizedTypeReference<ResultRespVO<T>>() {
|
|
|
- }, param);
|
|
|
- ResultRespVO<T> respBody = getRespBody(response);
|
|
|
- if (null == respBody) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- return respBody.getResult();
|
|
|
- }
|
|
|
-
|
|
|
- private <T extends MessageRespVO> T getRespBody(ResponseEntity<T> response) {
|
|
|
- HttpStatus statusCode = response.getStatusCode();
|
|
|
- if (!statusCode.is2xxSuccessful()) {
|
|
|
- log.info("request failed, resp:{}", response);
|
|
|
- return null;
|
|
|
- }
|
|
|
- T body = response.getBody();
|
|
|
- if (body == null || !ResponseStatus.SUCCESS_CODE.equals(body.getStatusCode())) {
|
|
|
- log.info("response body failed, body:{}", JSON.toJSONString(body));
|
|
|
- return null;
|
|
|
- }
|
|
|
- return body;
|
|
|
- }
|
|
|
-}
|