This commit is contained in:
caozehui
2025-03-24 20:38:24 +08:00
parent ce217b8b86
commit c67a2c8323
13 changed files with 41 additions and 225 deletions

View File

@@ -21,7 +21,8 @@ public enum UserResponseEnum {
SUPER_ADMIN_CANNOT_DELETE("A010010", "禁止删除超级管理员用户"),
COMPONENT_NOT_BLANK("A010011", "组件地址不能为空"),
FUNCTION_PATH_FORMAT_ERROR("A010012", "路由地址格式错误"),
SUPER_ADMIN_REPEAT("A010013","超级管理员已存在,请勿重复添加" );
SUPER_ADMIN_REPEAT("A010013","超级管理员已存在,请勿重复添加" ),
RSA_DECRYT_ERROR("A010014","RSA解密失败" );
private String code;
private String message;

View File

@@ -10,10 +10,13 @@ import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.constant.SecurityConstants;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.JwtUtil;
import com.njcn.common.utils.LogUtil;
import com.njcn.common.utils.RSAUtil;
import com.njcn.gather.user.pojo.constant.UserValidMessage;
import com.njcn.gather.user.pojo.enums.UserResponseEnum;
import com.njcn.gather.user.user.pojo.param.SysUserParam;
import com.njcn.gather.user.user.pojo.po.SysUser;
import com.njcn.gather.user.user.pojo.po.Token;
@@ -27,6 +30,8 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.security.KeyPair;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
@@ -40,6 +45,7 @@ public class AuthController extends BaseController {
private final ISysUserService sysUserService;
private final CustomCacheUtil customCacheUtil;
private KeyPair keyPair;
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.AUTHENTICATE)
@@ -48,7 +54,16 @@ public class AuthController extends BaseController {
public HttpResult<Object> login(@RequestBody SysUserParam.LoginParam param) {
String methodDescribe = getMethodDescribe("login");
LogUtil.njcnDebug(log, "{},登录参数为:{}", methodDescribe, param);
SysUser user = sysUserService.getUserByLoginNameAndPassword(param.getUsername(), param.getPassword());
byte[] decode = Base64.getDecoder().decode(param.getUsername());
String username = new String(decode);
String password = null;
try {
password = RSAUtil.decrypt(param.getPassword(), keyPair.getPrivate());
} catch (Exception e) {
throw new BusinessException(UserResponseEnum.RSA_DECRYT_ERROR);
}
SysUser user = sysUserService.getUserByLoginNameAndPassword(username, password);
if (ObjectUtil.isNull(user)) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, UserValidMessage.LOGIN_FAILED);
} else {
@@ -64,6 +79,7 @@ public class AuthController extends BaseController {
token.setUserInfo(map);
customCacheUtil.putWithExpireTime(accessToken, JSON.toJSONString(user), DateUnit.DAY.getMillis() * Integer.MAX_VALUE);
sysUserService.updateLoginTime(user.getId());
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, token, methodDescribe);
}
}
@@ -109,4 +125,15 @@ public class AuthController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
}
}
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
@ApiOperation("获取RSA公钥")
@GetMapping("/getPublicKey")
public HttpResult<String> publicKey() throws Exception {
String methodDescribe = getMethodDescribe("publicKey");
LogUtil.njcnDebug(log, "{}获取RSA公钥", methodDescribe);
keyPair = RSAUtil.generateKeyPair();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, RSAUtil.publicKeyToString(keyPair.getPublic()), methodDescribe);
}
}

View File

@@ -25,7 +25,7 @@ import java.util.List;
@Slf4j
@Component
public class AuthGlobalFilter implements Filter, Ordered {
private final static List<String> IGNORE_URI = Arrays.asList("/admin/login", "/report/generateReport");
private final static List<String> IGNORE_URI = Arrays.asList("/admin/login","/admin/getPublicKey", "/report/generateReport");
@Override
public int getOrder() {

View File

@@ -24,7 +24,6 @@ public class SysUserParam {
private String name;
@ApiModelProperty("部门Id")
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = UserValidMessage.DEPT_ID_FORMAT_ERROR)
private String deptId;
@ApiModelProperty("电话号码")

View File

@@ -0,0 +1,39 @@
package com.njcn.gather.user.user.pojo.po;
import lombok.Data;
import java.util.List;
@Data
public class MenuVO {
/**
* 路由菜单访问路径
*/
private String path;
/**
* 路由 name (对应页面组件 name, 可用作 KeepAlive 缓存标识 && 按钮权限筛选)
*/
private String name;
/**
* 视图文件路径
*/
private String component;
/**
* 路由重定向地址
*/
private String redirect;
/**
* 路由菜单元信息
*/
private MetaVO meta;
/**
* 子集路由菜单信息
*/
private List<MenuVO> children;
}

View File

@@ -0,0 +1,49 @@
package com.njcn.gather.user.user.pojo.po;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class MetaVO {
/**
* 菜单和面包屑对应的图标
*/
private String icon;
/**
* 路由标题 (用作 document.title || 菜单的名称)
*/
private String title;
/**
* 路由外链时填写的访问地址
*/
@JsonProperty("isLink")
private String isLink;
/**
* 是否在菜单中隐藏 (通常列表详情页需要隐藏)
*/
@JsonProperty("isHide")
private boolean isHide;
/**
* 菜单是否全屏 (示例:数据大屏页面)
*/
@JsonProperty("isFull")
private boolean isFull;
/**
* 菜单是否固定在标签页中 (首页通常是固定项)
*/
@JsonProperty("isAffix")
private boolean isAffix;
/**
* 当前路由是否缓存
*/
@JsonProperty("isKeepAlive")
private boolean isKeepAlive;
}

View File

@@ -117,10 +117,9 @@ public interface ISysUserService extends IService<SysUser> {
SysUser getUserByLoginNameAndPassword(String loginName, String password);
/**
* 根据用户ID判断是否是管理员用户
* @param userId 用户ID
* @return true表示是管理员用户false表示不是管理员用户
* 更新用户登录时间为当前时间
*
* @param userId
*/
boolean isAdmin(String userId);
boolean updateLoginTime(String userId);
}

View File

@@ -63,11 +63,7 @@ public class SysFunctionServiceImpl extends ServiceImpl<SysFunctionMapper, SysFu
function.setPids(pidS + "," + functionParam.getPid());
}
}
boolean result = this.save(function);
//if (result) {
//refreshRolesFunctionsCache();
//}
return result;
return this.save(function);
}
@Override
@@ -84,9 +80,6 @@ public class SysFunctionServiceImpl extends ServiceImpl<SysFunctionMapper, SysFu
BeanUtil.copyProperties(param, function);
result = this.updateById(function);
}
// if (result) {
// refreshRolesFunctionsCache();
// }
return result;
}
@@ -98,9 +91,6 @@ public class SysFunctionServiceImpl extends ServiceImpl<SysFunctionMapper, SysFu
List<SysFunction> childrenList = this.lambdaQuery().eq(SysFunction::getState, DataStateEnum.ENABLE.getCode()).eq(SysFunction::getPid, id).list();
if (CollectionUtils.isEmpty(childrenList)) {
result1 = this.lambdaUpdate().set(SysFunction::getState, DataStateEnum.DELETED.getCode()).in(SysFunction::getId, id).update();
// if (result) {
// refreshRolesFunctionsCache();
// }
} else {
throw new BusinessException(UserResponseEnum.EXISTS_CHILDREN_NOT_DELETE);
}

View File

@@ -103,20 +103,6 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
return this.baseMapper.selectList(lambdaQueryWrapper);
}
// @Override
// public boolean selectRelevance(List<String> ids) {
// // 判断角色是否和用户绑定
// List<UserRole> userRoleList = this.userRoleMapper.selectUserRole(ids);
// // 判断角色是否和资源绑定
// List<RoleFunction> roleFunctionList = this.roleFunctionMapper.selectRoleFunction(ids);
// // 判断角色是否和组件绑定
// List<RoleComponent> roleComponentList = this.roleComponentMapper.selectRoleComponet(ids);
// if (!userRoleList.isEmpty() || !roleComponentList.isEmpty() || !roleFunctionList.isEmpty()) {
// return true;
// }
// return false;
// }
/**
* 校验参数,检查是否存在相同名称或编码的角色
*/

View File

@@ -58,7 +58,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
} else {
queryWrapper.orderByDesc("sys_user.update_time");
}
queryWrapper.ne("sys_user.Login_Name", UserConst.SUPER_ADMIN).ne("sys_user.state", UserConst.STATE_DELETE);
queryWrapper.ne("sys_user.state", UserConst.STATE_DELETE);
Page<SysUser> page = this.baseMapper.selectPage(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), queryWrapper);
page.getRecords().forEach(sysUser -> {
List<SysRole> sysRoles = sysUserRoleService.listRoleByUserId(sysUser.getId());
@@ -126,7 +126,6 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
String secretkey = Sm4Utils.globalSecretKey;
Sm4Utils sm4 = new Sm4Utils(secretkey);
sysUser.setPassword(sm4.encryptData_ECB(sysUser.getPassword()));
// todo 别忘记移除登录时间
sysUser.setLoginTime(LocalDateTimeUtil.now());
sysUser.setLoginErrorTimes(0);
sysUser.setState(UserConst.STATE_ENABLE);
@@ -200,17 +199,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
}
@Override
public boolean isAdmin(String userId) {
SysUser user = lambdaQuery().ne(SysUser::getState, UserConst.STATE_DELETE).eq(SysUser::getId, userId).one();
if (ObjectUtil.isNotNull(user)) {
List<SysRole> sysRoles = sysUserRoleService.listRoleByUserId(user.getId());
for (SysRole sysRole : sysRoles) {
if (sysRole.getType().compareTo(RoleConst.TYPE_ADMINISTRATOR) <= 0) {
return true;
}
}
}
return false;
public boolean updateLoginTime(String userId) {
return this.lambdaUpdate().eq(SysUser::getId, userId).set(SysUser::getLoginTime, LocalDateTimeUtil.now()).update();
}
/**