统一身份认证机关关联与账号自创建
This commit is contained in:
parent
9b3d43cde0
commit
ce9be17995
|
|
@ -313,4 +313,12 @@ public abstract class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取一个新的UUID(无横杠)
|
||||||
|
* @return UUID
|
||||||
|
*/
|
||||||
|
public static String newUUID(){
|
||||||
|
return UUID.randomUUID().toString().replace("-", EMPTY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -63,6 +60,8 @@ public class OAuth2Controller extends BaseController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private IImsUserService iImsUserService;
|
private IImsUserService iImsUserService;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
private IImsOrgService iImsOrgService;
|
||||||
|
@Autowired
|
||||||
private IUserSupInfoService userSupInfoService;
|
private IUserSupInfoService userSupInfoService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private OrgUM orgUM;
|
private OrgUM orgUM;
|
||||||
|
|
@ -74,6 +73,8 @@ public class OAuth2Controller extends BaseController {
|
||||||
private TUsersService usersService;
|
private TUsersService usersService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
@Autowired
|
||||||
|
private IImsOrgMatchService iImsOrgMatchService;
|
||||||
|
|
||||||
private final static String USER_LOGIN_SELECTION = "USER_LOGIN_SELECTION:";
|
private final static String USER_LOGIN_SELECTION = "USER_LOGIN_SELECTION:";
|
||||||
|
|
||||||
|
|
@ -657,13 +658,45 @@ public class OAuth2Controller extends BaseController {
|
||||||
idCardList.add(DigestUtils.md5DigestAsHex(idCard.toLowerCase().getBytes(StandardCharsets.UTF_8)));
|
idCardList.add(DigestUtils.md5DigestAsHex(idCard.toLowerCase().getBytes(StandardCharsets.UTF_8)));
|
||||||
|
|
||||||
List<UserSupInfo> supList = userSupInfoService.lambdaQuery().in(UserSupInfo::getIdcardAbstr, idCardList).list();
|
List<UserSupInfo> supList = userSupInfoService.lambdaQuery().in(UserSupInfo::getIdcardAbstr, idCardList).list();
|
||||||
|
List<TUsers> list;
|
||||||
if (CollectionUtils.isEmpty(supList)) {
|
if (CollectionUtils.isEmpty(supList)) {
|
||||||
return ResponseEntity.status(HttpStatus.FOUND)
|
// 未找到匹配账号,自动创建用户
|
||||||
.location(java.net.URI.create("/integration/#/login?requestId=" + requestId + "&error=" + URLEncoder.encode("无匹配的综合监管用户,请联系系统管理员", "UTF-8")))
|
log.info("统一认证平台OAuth2回调接口,未找到匹配账号,将自动创建,requestId:{},用户名:{},身份证:{}", requestId, userInfo.getUserName(), userInfo.getIdCard());
|
||||||
.build();
|
TUsers newUser = new TUsers();
|
||||||
|
newUser.setUserid(StringUtils.newUUID());
|
||||||
|
newUser.setUsername(userInfo.getCode());
|
||||||
|
newUser.setRealname(userInfo.getName());
|
||||||
|
newUser.setPassword("C45D3989C0A5FA71");
|
||||||
|
newUser.setLocked("0");
|
||||||
|
newUser.setDeleted("0");
|
||||||
|
ImsOrgMatch imsOrgMatch = matchOrg(userInfo.getCode());
|
||||||
|
if (imsOrgMatch == null || StringUtils.isBlank(imsOrgMatch.getOrgdeptid())) {
|
||||||
|
return ResponseEntity.status(HttpStatus.FOUND)
|
||||||
|
.location(java.net.URI.create("/integration/#/login?requestId=" + requestId + "&error=" + URLEncoder.encode("统一身份机关匹配失败,无法创建本系统用户", "UTF-8")))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
newUser.setOrgunitid(imsOrgMatch.getOrgunitid());
|
||||||
|
newUser.setOrgdeptid(imsOrgMatch.getOrgdeptid());
|
||||||
|
newUser.setUserprop(99);
|
||||||
|
newUser.setUserstatus("1");
|
||||||
|
newUser.setImsusercode(userInfo.getUserId());
|
||||||
|
usersService.save(newUser);
|
||||||
|
|
||||||
|
UserSupInfo newSupInfo = new UserSupInfo();
|
||||||
|
ImsUser byId = iImsUserService.getById(userInfo.getCode());
|
||||||
|
String mobile = byId.getMobile();
|
||||||
|
newSupInfo.setUserid(newUser.getUserid());
|
||||||
|
newSupInfo.setMobileAbstr(DigestUtils.md5DigestAsHex(mobile.getBytes(StandardCharsets.UTF_8)));
|
||||||
|
newSupInfo.setIdcardAbstr(DigestUtils.md5DigestAsHex(idCard.getBytes(StandardCharsets.UTF_8)));
|
||||||
|
newSupInfo.setMobileEnc(SM4Utils.encrypt(mobile, sm4Key));
|
||||||
|
newSupInfo.setIdcardEnc(SM4Utils.encrypt(idCard, sm4Key));
|
||||||
|
userSupInfoService.save(newSupInfo);
|
||||||
|
|
||||||
|
list = Collections.singletonList(newUser);
|
||||||
|
} else {
|
||||||
|
list = usersService.lambdaQuery().in(TUsers::getUserid, supList.stream().map(UserSupInfo::getUserid).collect(Collectors.toList()))
|
||||||
|
.eq(TUsers::getDeleted, CommonConstants.FALSE_0).list();
|
||||||
}
|
}
|
||||||
List<TUsers> list = usersService.lambdaQuery().in(TUsers::getUserid, supList.stream().map(UserSupInfo::getUserid).collect(Collectors.toList()))
|
|
||||||
.eq(TUsers::getDeleted, CommonConstants.FALSE_0).list();
|
|
||||||
if (CollectionUtils.isEmpty(list)) {
|
if (CollectionUtils.isEmpty(list)) {
|
||||||
return ResponseEntity.status(HttpStatus.FOUND)
|
return ResponseEntity.status(HttpStatus.FOUND)
|
||||||
.location(java.net.URI.create("/integration/#/login?requestId=" + requestId + "&error=" + URLEncoder.encode("无匹配的综合监管用户,请联系系统管理员", "UTF-8")))
|
.location(java.net.URI.create("/integration/#/login?requestId=" + requestId + "&error=" + URLEncoder.encode("无匹配的综合监管用户,请联系系统管理员", "UTF-8")))
|
||||||
|
|
@ -800,4 +833,20 @@ public class OAuth2Controller extends BaseController {
|
||||||
return ResponseEntity.ok(RestResult.error(ResultCode.BUSINESS_LOGIC_ERROR, "登出失败: " + e.getMessage()));
|
return ResponseEntity.ok(RestResult.error(ResultCode.BUSINESS_LOGIC_ERROR, "登出失败: " + e.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 匹配用户的机关信息
|
||||||
|
*
|
||||||
|
* @param usercode 统一身份认证那边的用户code
|
||||||
|
* @return 用户信息
|
||||||
|
*/
|
||||||
|
private ImsOrgMatch matchOrg(String usercode) {
|
||||||
|
ImsUser byId = iImsUserService.getById(usercode);
|
||||||
|
String userorgcode = byId.getUserorgcode();
|
||||||
|
if (StringUtils.isBlank(userorgcode)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
userorgcode = userorgcode.split(";")[0];
|
||||||
|
return iImsOrgMatchService.getById(userorgcode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
package com.chinaweal.aiccs.org.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一身份认证机关匹配关系表
|
||||||
|
* @author lroyia
|
||||||
|
* @since 2026/4/30 09:57
|
||||||
|
**/
|
||||||
|
@Data
|
||||||
|
@ApiModel("统一身份认证机关匹配关系")
|
||||||
|
@TableName(value = "IMS_ORG_MATCH", schema = "CXAICORG")
|
||||||
|
public class ImsOrgMatch implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一身份认证那边的机关编码
|
||||||
|
*/
|
||||||
|
@TableId("IMS_ORG_CODE")
|
||||||
|
@ApiModelProperty("统一身份认证那边的机关编码")
|
||||||
|
private String imsOrgCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单位id
|
||||||
|
*/
|
||||||
|
@TableField("ORGUNITID")
|
||||||
|
@ApiModelProperty("单位id")
|
||||||
|
private String orgunitid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单位名称
|
||||||
|
*/
|
||||||
|
@TableField("ORGUNITNAME")
|
||||||
|
@ApiModelProperty("单位名称")
|
||||||
|
private String orgunitname;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门id
|
||||||
|
*/
|
||||||
|
@TableField("ORGDEPTID")
|
||||||
|
@ApiModelProperty("部门id")
|
||||||
|
private String orgdeptid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门名称
|
||||||
|
*/
|
||||||
|
@TableField("ORGDEPTNAME")
|
||||||
|
@ApiModelProperty("部门名称")
|
||||||
|
private String orgdeptname;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.chinaweal.aiccs.org.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.chinaweal.aiccs.org.entity.ImsOrgMatch;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一身份认证机关匹配关系 Mapper
|
||||||
|
* @author lroyia
|
||||||
|
* @since 2026/4/30 09:57
|
||||||
|
**/
|
||||||
|
public interface ImsOrgMatchMapper extends BaseMapper<ImsOrgMatch> {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.chinaweal.aiccs.org.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.chinaweal.aiccs.org.entity.ImsOrgMatch;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一身份认证机关匹配关系服务接口
|
||||||
|
* @author lroyia
|
||||||
|
* @since 2026/4/30 09:57
|
||||||
|
**/
|
||||||
|
public interface IImsOrgMatchService extends IService<ImsOrgMatch> {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.chinaweal.aiccs.org.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.chinaweal.aiccs.org.entity.ImsOrgMatch;
|
||||||
|
import com.chinaweal.aiccs.org.mapper.ImsOrgMatchMapper;
|
||||||
|
import com.chinaweal.aiccs.org.service.IImsOrgMatchService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一身份认证机关匹配关系服务实现
|
||||||
|
* @author lroyia
|
||||||
|
* @since 2026/4/30 09:57
|
||||||
|
**/
|
||||||
|
@Service
|
||||||
|
public class ImsOrgMatchServiceImpl extends ServiceImpl<ImsOrgMatchMapper, ImsOrgMatch> implements IImsOrgMatchService {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.chinaweal.aiccs.org.mapper.ImsOrgMatchMapper">
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Loading…
Reference in New Issue