fix(iam): 完善数据校验
This commit is contained in:
@@ -145,6 +145,11 @@ public class SysPermission implements Serializable {
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* appId
|
||||
*/
|
||||
private String appId;
|
||||
|
||||
/**按钮权限状态(0无效1有效)*/
|
||||
private java.lang.String status;
|
||||
|
||||
|
||||
@@ -75,5 +75,8 @@ public class SysRole implements Serializable {
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
/**
|
||||
* appId
|
||||
*/
|
||||
private String appId;
|
||||
}
|
||||
|
||||
+64
-31
@@ -331,7 +331,6 @@ public class SyncIamController {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
BpmcAcceptDto bpmcAcceptDto = objectMapper.readValue(acceptDecryptPo.getMessageDecryptTabels().getHeader().getData(), BpmcAcceptDto.class);
|
||||
|
||||
// BpmcAcceptDto bpmcAcceptDto = acceptDecryptPo.getMessageDecryptTabels().getHeader();
|
||||
MessageHeader messageHeader = acceptDecryptPo.getMessageHeader();
|
||||
|
||||
if (CharSequenceUtil.isEmpty(bpmcAcceptDto.getType())){
|
||||
@@ -372,21 +371,67 @@ public class SyncIamController {
|
||||
}
|
||||
|
||||
BpmcResponseDto bpmcResponseDto = BpmcResponseDto.success();
|
||||
try {
|
||||
switch (bpmcAcceptDto.getType()){
|
||||
// 角色
|
||||
case DockingConstant.BPMC_TYPE_ROLE:
|
||||
bpmcResponseDto = bpmcTypeRole(objectMapper, bpmcAcceptDto, bpmcResponseDto);
|
||||
break;
|
||||
|
||||
// 分接口类型分别处理
|
||||
if (bpmcAcceptDto.getType().equals(DockingConstant.BPMC_TYPE_ROLE)){
|
||||
RoleDto roleDto = objectMapper.readValue(bpmcAcceptDto.getEntity(), RoleDto.class);
|
||||
// 根据新增/编辑/删除调用不同的业务处理代码
|
||||
// 菜单
|
||||
case DockingConstant.BPMC_TYPE_RESOURCE:
|
||||
bpmcResponseDto = bpmcTypeResource(objectMapper, bpmcAcceptDto, bpmcResponseDto);
|
||||
break;
|
||||
|
||||
// 用户角色关联
|
||||
case DockingConstant.BPMC_TYPE_USER_ROLE:
|
||||
bpmcResponseDto = bpmcTypeUserRole(objectMapper, bpmcAcceptDto, bpmcResponseDto);
|
||||
break;
|
||||
|
||||
// 角色菜单关联
|
||||
case DockingConstant.BPMC_TYPE_ROLE_RESOURCE:
|
||||
bpmcResponseDto = bpmcTypeRoleResource(objectMapper, bpmcAcceptDto, bpmcResponseDto);
|
||||
break;
|
||||
|
||||
default:
|
||||
bpmcResponseDto = BpmcResponseDto.error("接口类型(type)未找到,请检查");
|
||||
break;
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
log.error(e.getMessage());
|
||||
bpmcResponseDto = BpmcResponseDto.error(e.getMessage());
|
||||
}
|
||||
|
||||
return new SendPoDecryptPo<BpmcResponseDto>().response(
|
||||
this.syncIamService.generatorReturnMessageHeader(messageHeader),
|
||||
bpmcResponseDto
|
||||
);
|
||||
}
|
||||
|
||||
private BpmcResponseDto bpmcTypeRoleResource(ObjectMapper objectMapper, BpmcAcceptDto bpmcAcceptDto, BpmcResponseDto bpmcResponseDto) throws JsonProcessingException {
|
||||
List<RoleResourceDto> roleResourceDtoList = objectMapper.readValue(bpmcAcceptDto.getEntity(), new TypeReference<List<RoleResourceDto>>() {});
|
||||
// 根据新增/删除调用不同的业务处理代码
|
||||
if (bpmcAcceptDto.getAction().equals(DockingConstant.BPMC_ACTION_ADD)){
|
||||
bpmcResponseDto = this.syncIamService.roleCreateService(roleDto);
|
||||
} else if (bpmcAcceptDto.getAction().equals(DockingConstant.BPMC_ACTION_UPDATE)) {
|
||||
bpmcResponseDto = this.syncIamService.roleUpdateService(roleDto);
|
||||
bpmcResponseDto = this.syncIamService.roleResourceCreateService(roleResourceDtoList);
|
||||
} else if (bpmcAcceptDto.getAction().equals(DockingConstant.BPMC_ACTION_DELETE)) {
|
||||
bpmcResponseDto = this.syncIamService.roleDeleteService(roleDto);
|
||||
bpmcResponseDto = this.syncIamService.roleResourceDeleteService(roleResourceDtoList);
|
||||
}
|
||||
return bpmcResponseDto;
|
||||
}
|
||||
|
||||
if (bpmcAcceptDto.getType().equals(DockingConstant.BPMC_TYPE_RESOURCE)){
|
||||
private BpmcResponseDto bpmcTypeUserRole(ObjectMapper objectMapper, BpmcAcceptDto bpmcAcceptDto, BpmcResponseDto bpmcResponseDto) throws JsonProcessingException {
|
||||
List<UserRoleDto> userRoleDtoList = objectMapper.readValue(bpmcAcceptDto.getEntity(), new TypeReference<List<UserRoleDto>>() {});
|
||||
// 根据新增/删除调用不同的业务处理代码
|
||||
if (bpmcAcceptDto.getAction().equals(DockingConstant.BPMC_ACTION_ADD)){
|
||||
bpmcResponseDto = this.syncIamService.userRoleCreateService(userRoleDtoList);
|
||||
} else if (bpmcAcceptDto.getAction().equals(DockingConstant.BPMC_ACTION_DELETE)) {
|
||||
bpmcResponseDto = this.syncIamService.userRoleDeleteService(userRoleDtoList);
|
||||
}
|
||||
return bpmcResponseDto;
|
||||
}
|
||||
|
||||
private BpmcResponseDto bpmcTypeResource(ObjectMapper objectMapper, BpmcAcceptDto bpmcAcceptDto, BpmcResponseDto bpmcResponseDto) throws JsonProcessingException {
|
||||
ResourceDto resourceDto = objectMapper.readValue(bpmcAcceptDto.getEntity(), ResourceDto.class);
|
||||
// 根据新增/编辑/删除调用不同的业务处理代码
|
||||
if (bpmcAcceptDto.getAction().equals(DockingConstant.BPMC_ACTION_ADD)){
|
||||
@@ -396,32 +441,20 @@ public class SyncIamController {
|
||||
} else if (bpmcAcceptDto.getAction().equals(DockingConstant.BPMC_ACTION_DELETE)) {
|
||||
bpmcResponseDto = this.syncIamService.resourceDeleteService(resourceDto);
|
||||
}
|
||||
return bpmcResponseDto;
|
||||
}
|
||||
|
||||
if (bpmcAcceptDto.getType().equals(DockingConstant.BPMC_TYPE_USER_ROLE)){
|
||||
List<UserRoleDto> userRoleDtoList = objectMapper.readValue(bpmcAcceptDto.getEntity(), new TypeReference<List<UserRoleDto>>() {});
|
||||
// 根据新增/删除调用不同的业务处理代码
|
||||
private BpmcResponseDto bpmcTypeRole(ObjectMapper objectMapper, BpmcAcceptDto bpmcAcceptDto, BpmcResponseDto bpmcResponseDto) throws JsonProcessingException {
|
||||
RoleDto roleDto = objectMapper.readValue(bpmcAcceptDto.getEntity(), RoleDto.class);
|
||||
// 根据新增/编辑/删除调用不同的业务处理代码
|
||||
if (bpmcAcceptDto.getAction().equals(DockingConstant.BPMC_ACTION_ADD)){
|
||||
bpmcResponseDto = this.syncIamService.userRoleCreateService(userRoleDtoList);
|
||||
bpmcResponseDto = this.syncIamService.roleCreateService(roleDto);
|
||||
} else if (bpmcAcceptDto.getAction().equals(DockingConstant.BPMC_ACTION_UPDATE)) {
|
||||
bpmcResponseDto = this.syncIamService.roleUpdateService(roleDto);
|
||||
} else if (bpmcAcceptDto.getAction().equals(DockingConstant.BPMC_ACTION_DELETE)) {
|
||||
bpmcResponseDto = this.syncIamService.userRoleDeleteService(userRoleDtoList);
|
||||
bpmcResponseDto = this.syncIamService.roleDeleteService(roleDto);
|
||||
}
|
||||
}
|
||||
|
||||
if (bpmcAcceptDto.getType().equals(DockingConstant.BPMC_TYPE_ROLE_RESOURCE)){
|
||||
List<RoleResourceDto> roleResourceDtoList = objectMapper.readValue(bpmcAcceptDto.getEntity(), new TypeReference<List<RoleResourceDto>>() {});
|
||||
// 根据新增/删除调用不同的业务处理代码
|
||||
if (bpmcAcceptDto.getAction().equals(DockingConstant.BPMC_ACTION_ADD)){
|
||||
bpmcResponseDto = this.syncIamService.roleResourceCreateService(roleResourceDtoList);
|
||||
} else if (bpmcAcceptDto.getAction().equals(DockingConstant.BPMC_ACTION_DELETE)) {
|
||||
bpmcResponseDto = this.syncIamService.roleResourceDeleteService(roleResourceDtoList);
|
||||
}
|
||||
}
|
||||
|
||||
return new SendPoDecryptPo<BpmcResponseDto>().response(
|
||||
this.syncIamService.generatorReturnMessageHeader(messageHeader),
|
||||
bpmcResponseDto
|
||||
);
|
||||
return bpmcResponseDto;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+36
-8
@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.bamboocloud.codec.BamboocloudFacade;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -586,6 +587,7 @@ public class SyncIamService {
|
||||
sysRole.setCreateTime(roleDto.getCreateTime());
|
||||
sysRole.setUpdateBy(DockingConstant.IAM_SYSTEM_NAME);
|
||||
sysRole.setUpdateTime(roleDto.getModifyTime());
|
||||
sysRole.setAppId(roleDto.getAppId());
|
||||
|
||||
sysRoleService.save(sysRole);
|
||||
} catch (Exception e){
|
||||
@@ -609,6 +611,8 @@ public class SyncIamService {
|
||||
|
||||
if (sysRole == null){
|
||||
return BpmcResponseDto.error("未找到对应id角色,无法更新");
|
||||
}else {
|
||||
sysRole.setId(roleDto.getId());
|
||||
}
|
||||
|
||||
if (CharSequenceUtil.isNotEmpty(roleDto.getName())){
|
||||
@@ -623,6 +627,10 @@ public class SyncIamService {
|
||||
sysRole.setDescription(roleDto.getDescription());
|
||||
}
|
||||
|
||||
if (CharSequenceUtil.isNotEmpty(roleDto.getAppId())){
|
||||
sysRole.setAppId(roleDto.getAppId());
|
||||
}
|
||||
|
||||
sysRole.setUpdateBy(DockingConstant.IAM_SYSTEM_NAME);
|
||||
|
||||
if (roleDto.getModifyTime() != null){
|
||||
@@ -670,7 +678,13 @@ public class SyncIamService {
|
||||
sysPermission.setPerms(resourceDto.getCode());
|
||||
sysPermission.setComponent(resourceDto.getComponent()); // 组件的路径
|
||||
sysPermission.setUrl(resourceDto.getRedirect()); // 地址栏显示的路径
|
||||
sysPermission.setAppId(resourceDto.getAppId()); // appId
|
||||
if (!Objects.isNull(resourceDto.getSort())){
|
||||
sysPermission.setSortNo(Double.valueOf(resourceDto.getSort()));
|
||||
}else {
|
||||
sysPermission.setSortNo(1D);
|
||||
}
|
||||
|
||||
|
||||
// TODO 菜单英文名数据库中没有,需要确认
|
||||
|
||||
@@ -714,7 +728,6 @@ public class SyncIamService {
|
||||
* 菜单更新
|
||||
*/
|
||||
public BpmcResponseDto resourceUpdateService(ResourceDto resourceDto){
|
||||
try {
|
||||
if (CharSequenceUtil.isEmpty(resourceDto.getId())){
|
||||
return BpmcResponseDto.error("菜单id为空,无法更新");
|
||||
}
|
||||
@@ -723,6 +736,8 @@ public class SyncIamService {
|
||||
|
||||
if (sysPermission == null){
|
||||
return BpmcResponseDto.error("未找到对应id功能权限,无法更新");
|
||||
}else {
|
||||
sysPermission.setId(resourceDto.getId());
|
||||
}
|
||||
|
||||
if (CharSequenceUtil.isNotEmpty(resourceDto.getParentId())){
|
||||
@@ -749,6 +764,10 @@ public class SyncIamService {
|
||||
sysPermission.setSortNo(Double.valueOf(resourceDto.getSort()));
|
||||
}
|
||||
|
||||
if (CharSequenceUtil.isNotEmpty(resourceDto.getAppId())){
|
||||
sysPermission.setAppId(resourceDto.getAppId());
|
||||
}
|
||||
|
||||
// sysPermission的 menuType (0:一级菜单;1:子菜单 ;2:按钮权限)
|
||||
if (DockingConstant.BPMC_RESOURCE_TYPE_MENU == resourceDto.getMenu_type()){
|
||||
if (CharSequenceUtil.isEmpty(resourceDto.getParentId())){
|
||||
@@ -781,11 +800,6 @@ public class SyncIamService {
|
||||
}
|
||||
|
||||
sysPermissionService.editPermission(sysPermission);
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return BpmcResponseDto.error(e.getMessage());
|
||||
}
|
||||
|
||||
return BpmcResponseDto.success();
|
||||
}
|
||||
|
||||
@@ -827,6 +841,14 @@ public class SyncIamService {
|
||||
sysUserRole.setUserId(userInfo.getId());
|
||||
sysUserRole.setRoleId(userRoleDto.getArId());
|
||||
|
||||
// 角色重复性校验
|
||||
int count = sysUserRoleService.count(new LambdaQueryWrapper<SysUserRole>()
|
||||
.eq(SysUserRole::getUserId, sysUserRole.getUserId())
|
||||
.eq(SysUserRole::getRoleId, sysUserRole.getRoleId()));
|
||||
if (count > 0){
|
||||
continue;
|
||||
}
|
||||
|
||||
userRoleList.add(sysUserRole);
|
||||
}
|
||||
}
|
||||
@@ -870,7 +892,13 @@ public class SyncIamService {
|
||||
SysRolePermission sysRolePermission = new SysRolePermission();
|
||||
sysRolePermission.setPermissionId(roleResourceDto.getAmId());
|
||||
sysRolePermission.setRoleId(roleResourceDto.getArId());
|
||||
|
||||
// 重复性校验
|
||||
int count = sysRolePermissionService.count(new LambdaQueryWrapper<SysRolePermission>()
|
||||
.eq(SysRolePermission::getRoleId, sysRolePermission.getRoleId())
|
||||
.eq(SysRolePermission::getPermissionId, sysRolePermission.getPermissionId()));
|
||||
if (count > 0){
|
||||
continue;
|
||||
}
|
||||
sysRolePermissionList.add(sysRolePermission);
|
||||
}
|
||||
this.sysRolePermissionService.saveBatch(sysRolePermissionList);
|
||||
@@ -888,7 +916,7 @@ public class SyncIamService {
|
||||
public BpmcResponseDto roleResourceDeleteService(List<RoleResourceDto> roleResourceDtoList){
|
||||
try {
|
||||
for (RoleResourceDto roleResourceDto : roleResourceDtoList){
|
||||
QueryWrapper<SysRolePermission> queryWrapper = new QueryWrapper<SysRolePermission>();
|
||||
QueryWrapper<SysRolePermission> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("permission_id", roleResourceDto.getAmId());
|
||||
queryWrapper.eq("role_id", roleResourceDto.getArId());
|
||||
|
||||
|
||||
+4
-4
@@ -43,22 +43,22 @@ public class DockingConstant {
|
||||
/**
|
||||
* 竹云统一认证平台,接口类型:角色
|
||||
*/
|
||||
public static String BPMC_TYPE_ROLE = "D_AR";
|
||||
public static final String BPMC_TYPE_ROLE = "D_AR";
|
||||
|
||||
/**
|
||||
* 竹云统一认证平台,接口类型:功能权限
|
||||
*/
|
||||
public static String BPMC_TYPE_RESOURCE = "D_AM";
|
||||
public static final String BPMC_TYPE_RESOURCE = "D_AM";
|
||||
|
||||
/**
|
||||
* 竹云统一认证平台,接口类型:账号与应用角色关系
|
||||
*/
|
||||
public static String BPMC_TYPE_USER_ROLE = "R_USER_AR";
|
||||
public static final String BPMC_TYPE_USER_ROLE = "R_USER_AR";
|
||||
|
||||
/**
|
||||
* 竹云统一认证平台,接口类型:应用角色与应用功能权限关系
|
||||
*/
|
||||
public static String BPMC_TYPE_ROLE_RESOURCE = "R_AR_AM";
|
||||
public static final String BPMC_TYPE_ROLE_RESOURCE = "R_AR_AM";
|
||||
|
||||
/**
|
||||
* 竹云统一认证平台,操作类型:新增
|
||||
|
||||
Reference in New Issue
Block a user