【修改】删除权限,增加白名单,修改mac地址的校验方式

This commit is contained in:
huababa1
2025-10-29 12:07:56 +08:00
parent 3c77645ca6
commit 9c456f2fa8
21 changed files with 258 additions and 152 deletions

View File

@@ -8,6 +8,7 @@ import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pc.exam.pp.framework.common.pojo.CommonResult;
import pc.exam.pp.framework.security.core.util.SecurityFrameworkUtils;
import pc.exam.pp.framework.tenant.core.aop.TenantIgnore;
import pc.exam.pp.module.exam.dal.dataobject.EducationPaperParam;
import pc.exam.pp.module.exam.dal.dataobject.ExamWhiteListDO;
@@ -109,16 +110,5 @@ public class EducationPaperParamController {
}
return CommonResult.success("200");
}
@GetMapping("/getAppWhiteList/{taskId}")
@PermitAll
@TenantIgnore
@Operation(summary = "查看白名单列表", description = "查看白名单列表")
public CommonResult<List<String>> getAppWhiteList(@PathVariable("taskId") String taskId){
// 使用传入的IP进行ping查看是否存在连接并返回信号的强度
System.out.println(educationPaperParamService.getAppWhiteList(taskId));
return success(educationPaperParamService.getAppWhiteList(taskId));
}
}

View File

@@ -0,0 +1,65 @@
package pc.exam.pp.module.exam.controller.admin.paper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pc.exam.pp.framework.common.pojo.CommonResult;
import pc.exam.pp.framework.common.pojo.PageResult;
import pc.exam.pp.framework.common.util.object.BeanUtils;
import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperTaskPageVo;
import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperWhitePageVo;
import pc.exam.pp.module.exam.dal.dataobject.EducationPaperTask;
import pc.exam.pp.module.exam.dal.dataobject.ExamWhiteListDO;
import pc.exam.pp.module.exam.service.paper.IEducationPaperParamService;
import pc.exam.pp.module.exam.service.paper.IEducationPaperWhiteService;
import java.util.List;
import static pc.exam.pp.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 试卷通用参数")
@RestController
@RequestMapping("/exam/white")
public class EducationPaperWhiteAppController {
@Autowired
private IEducationPaperWhiteService educationPaperWhiteService;
@Operation(summary = "新增白名单")
@PostMapping("/addAppWhite")
public CommonResult addAppWhite(@RequestBody ExamWhiteListDO ExamWhiteListDO) {
return CommonResult.success(educationPaperWhiteService.insertWhiteApp(ExamWhiteListDO));
}
@Operation(summary = "获取白名单详细信息")
@GetMapping(value = "/getWhite")
public CommonResult getWhite(@RequestParam("id") String id) {
ExamWhiteListDO examWhiteListDO = educationPaperWhiteService.selectWhiteById(id);
return CommonResult.success(examWhiteListDO);
}
@PutMapping("/updateAppWhite")
@Operation(summary = "修改白名单列表", description = "修改白名单列表")
public CommonResult updateAppWhite(@RequestBody ExamWhiteListDO ExamWhiteListDO) {
return success(educationPaperWhiteService.updateAppList(ExamWhiteListDO));
}
@GetMapping("/getAppWhiteList")
@Operation(summary = "学生端查看白名单列表", description = "查看白名单列表")
public CommonResult<List<String>> getAppWhiteList(){
return success(educationPaperWhiteService.getAppWhiteListString());
}
@GetMapping("/getAppWhiteListCenter")
@Operation(summary = "中心端查看白名单列表", description = "查看白名单列表")
public CommonResult<PageResult<ExamWhiteListDO>> getAppWhiteListCenter(PaperWhitePageVo paperWhitePageVo) {
//获取租户id
// Long loginTenantId = SecurityFrameworkUtils.getLoginTenantId();
PageResult<ExamWhiteListDO> appWhiteList = educationPaperWhiteService.getAppWhiteList(paperWhitePageVo);
return CommonResult.success(BeanUtils.toBean(appWhiteList, ExamWhiteListDO.class));
}
@Operation(summary = "删除白名单")
@DeleteMapping("/delWhite/{id}")
public CommonResult removeAppWhite(@PathVariable String id) {
return CommonResult.success(educationPaperWhiteService.deleteWhiteAppByParamIds(id));
}
}

View File

@@ -0,0 +1,22 @@
package pc.exam.pp.module.exam.controller.admin.paper.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import pc.exam.pp.framework.common.pojo.PageParam;
import java.time.LocalDateTime;
import static pc.exam.pp.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "白名单vo")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class PaperWhitePageVo extends PageParam {
private String name;
}

View File

@@ -93,7 +93,5 @@ public class EducationPaperParam
private String isScoreDetail;
// 是否删除考生文件
private String isDelete;
// 白名单
@TableField(exist = false)
private List<ExamWhiteListDO> whiteList;
}

View File

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import pc.exam.pp.framework.tenant.core.db.TenantBaseDO;
@TableName("exam_white_list")
@Data
@@ -14,6 +15,9 @@ import lombok.*;
public class ExamWhiteListDO {
@TableId
private Long id;
private String taskId;
private String name;
/**
* 多租户编号
*/
private Long tenantId;
}

View File

@@ -3,7 +3,12 @@ package pc.exam.pp.module.exam.dal.mysql.paper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import pc.exam.pp.framework.common.pojo.PageResult;
import pc.exam.pp.framework.mybatis.core.mapper.BaseMapperX;
import pc.exam.pp.framework.mybatis.core.query.LambdaQueryWrapperX;
import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperTaskPageVo;
import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperWhitePageVo;
import pc.exam.pp.module.exam.dal.dataobject.EducationPaperParam;
import pc.exam.pp.module.exam.dal.dataobject.EducationPaperTask;
import pc.exam.pp.module.exam.dal.dataobject.ExamWhiteListDO;
@@ -15,5 +20,13 @@ public interface ExamWhiteListMapper extends BaseMapperX<ExamWhiteListDO> {
void deleteByTaskId(String taskId);
List<String> selectNameByTaskId(String taskId);
List<String> selectNameByTaskId();
int deleteWhiteById(String id);
default PageResult<ExamWhiteListDO> getAppWhiteList(PaperWhitePageVo paperWhitePageVo) {
return selectPage(paperWhitePageVo, new LambdaQueryWrapperX<ExamWhiteListDO>()
.likeIfPresent(ExamWhiteListDO::getName, paperWhitePageVo.getName()));
}
}

View File

@@ -25,8 +25,7 @@ public class EducationPaperParamServiceImpl implements IEducationPaperParamServi
private EducationPaperParamMapper educationPaperParamMapper;
@Autowired
private EducationPaperTaskMapper educationPaperTaskMapper;
@Autowired
private ExamWhiteListMapper examWhiteListMapper;
/**
* 查询通用参数
@@ -61,16 +60,16 @@ public class EducationPaperParamServiceImpl implements IEducationPaperParamServi
@Override
public int insertEducationPaperParam(EducationPaperParam educationPaperParam)
{
List<ExamWhiteListDO> whiteList = educationPaperParam.getWhiteList();
String taskId = educationPaperParam.getTaskId();
// ✅ 统一赋值
if (whiteList != null && !whiteList.isEmpty()) {
for (ExamWhiteListDO examWhiteListDO : whiteList) {
examWhiteListDO.setTaskId(taskId);
examWhiteListDO.setName(examWhiteListDO.getName());
}
examWhiteListMapper.insertBatch(whiteList);
}
// List<ExamWhiteListDO> whiteList = educationPaperParam.getWhiteList();
// String taskId = educationPaperParam.getTaskId();
// // ✅ 统一赋值
// if (whiteList != null && !whiteList.isEmpty()) {
// for (ExamWhiteListDO examWhiteListDO : whiteList) {
// examWhiteListDO.setTaskId(taskId);
// examWhiteListDO.setName(examWhiteListDO.getName());
// }
// examWhiteListMapper.insertBatch(whiteList);
// }
return educationPaperParamMapper.insertEducationPaperParam(educationPaperParam);
}
@@ -83,20 +82,20 @@ public class EducationPaperParamServiceImpl implements IEducationPaperParamServi
@Override
public int updateEducationPaperParam(EducationPaperParam educationPaperParam)
{
List<ExamWhiteListDO> whiteList = educationPaperParam.getWhiteList();
String taskId = educationPaperParam.getTaskId();
if (taskId!=null){
//删除旧白名单
examWhiteListMapper.deleteByTaskId(taskId);
//插入新白名单
if (whiteList != null && !whiteList.isEmpty()) {
for (ExamWhiteListDO examWhiteListDO : whiteList) {
examWhiteListDO.setTaskId(taskId);
examWhiteListDO.setName(examWhiteListDO.getName());
}
examWhiteListMapper.insertBatch(whiteList);
}
}
// List<ExamWhiteListDO> whiteList = educationPaperParam.getWhiteList();
// String taskId = educationPaperParam.getTaskId();
// if (taskId!=null){
// //删除旧白名单
// examWhiteListMapper.deleteByTaskId(taskId);
// //插入新白名单
// if (whiteList != null && !whiteList.isEmpty()) {
// for (ExamWhiteListDO examWhiteListDO : whiteList) {
// examWhiteListDO.setTaskId(taskId);
// examWhiteListDO.setName(examWhiteListDO.getName());
// }
// examWhiteListMapper.insertBatch(whiteList);
// }
// }
return educationPaperParamMapper.updateEducationPaperParam(educationPaperParam);
}
@@ -126,19 +125,13 @@ public class EducationPaperParamServiceImpl implements IEducationPaperParamServi
@Override
public EducationPaperParam selectEducationPaperParamByTaskId(String taskId) {
List<ExamWhiteListDO> whiteList = examWhiteListMapper.selectByTaskId(taskId);
EducationPaperParam educationPaperParam = educationPaperParamMapper.selectEducationPaperParamByTaskId(taskId);
if (whiteList != null && !whiteList.isEmpty()) {
educationPaperParam.setWhiteList(whiteList);
}
return educationPaperParam;
// List<ExamWhiteListDO> whiteList = examWhiteListMapper.selectByTaskId(taskId);
// if (whiteList != null && !whiteList.isEmpty()) {
// educationPaperParam.setWhiteList(whiteList);
// }
return educationPaperParamMapper.selectEducationPaperParamByTaskId(taskId);
}
@Override
public List<String> getAppWhiteList(String taskId) {
return examWhiteListMapper.selectNameByTaskId(taskId);
}
}

View File

@@ -192,12 +192,12 @@ public class EducationPaperTaskServiceImpl implements IEducationPaperTaskService
} else {
educationPaperTask.setIsOne("1");
}
List<ExamWhiteListDO> whiteList = new ArrayList<>();
ExamWhiteListDO examWhiteListDO=new ExamWhiteListDO();
examWhiteListDO.setTaskId(uuid);
examWhiteListDO.setName("ExamStudent");
whiteList.add(examWhiteListDO);
examWhiteListMapper.insertBatch(whiteList);
// List<ExamWhiteListDO> whiteList = new ArrayList<>();
// ExamWhiteListDO examWhiteListDO=new ExamWhiteListDO();
// examWhiteListDO.setTaskId(uuid);
// examWhiteListDO.setName("ExamStudent");
// whiteList.add(examWhiteListDO);
// examWhiteListMapper.insertBatch(whiteList);
@@ -551,13 +551,13 @@ public class EducationPaperTaskServiceImpl implements IEducationPaperTaskService
educationPaperTask.setCreateTime(now);
educationPaperTask.setIsTemplate(1);
//白名单
List<ExamWhiteListDO> whiteList = examWhiteListMapper.selectByTaskId(taskId);
if (whiteList != null && !whiteList.isEmpty()) {
for (ExamWhiteListDO examWhiteListDO : whiteList) {
examWhiteListDO.setTaskId(newtaskId);
}
examWhiteListMapper.insertBatch(whiteList);
}
// List<ExamWhiteListDO> whiteList = examWhiteListMapper.selectByTaskId(taskId);
// if (whiteList != null && !whiteList.isEmpty()) {
// for (ExamWhiteListDO examWhiteListDO : whiteList) {
// examWhiteListDO.setTaskId(newtaskId);
// }
// examWhiteListMapper.insertBatch(whiteList);
// }
educationPaperTaskMapper.insertEducationPaperTask(educationPaperTask);
if (options.contains("1")) {

View File

@@ -64,6 +64,6 @@ public interface IEducationPaperParamService
EducationPaperParam selectEducationPaperParamByTaskId(String taskId);
List<String> getAppWhiteList(String taskId);
}

View File

@@ -0,0 +1,22 @@
package pc.exam.pp.module.exam.service.paper;
import pc.exam.pp.framework.common.pojo.PageResult;
import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperWhitePageVo;
import pc.exam.pp.module.exam.dal.dataobject.EducationPaperTask;
import pc.exam.pp.module.exam.dal.dataobject.ExamWhiteListDO;
import java.util.List;
public interface IEducationPaperWhiteService {
PageResult<ExamWhiteListDO> getAppWhiteList(PaperWhitePageVo paperWhitePageVo);
int updateAppList(ExamWhiteListDO ExamWhiteListDO);
int insertWhiteApp(ExamWhiteListDO examWhiteListDO);
int deleteWhiteAppByParamIds(String id);
ExamWhiteListDO selectWhiteById(String id);
List<String> getAppWhiteListString();
}

View File

@@ -0,0 +1,47 @@
package pc.exam.pp.module.exam.service.paper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pc.exam.pp.framework.common.pojo.PageResult;
import pc.exam.pp.module.exam.controller.admin.paper.vo.PaperWhitePageVo;
import pc.exam.pp.module.exam.dal.dataobject.ExamWhiteListDO;
import pc.exam.pp.module.exam.dal.mysql.paper.ExamWhiteListMapper;
import java.util.List;
@Service
public class IEducationPaperWhiteServiceImpl implements IEducationPaperWhiteService{
@Autowired
private ExamWhiteListMapper examWhiteListMapper;
@Override
public PageResult<ExamWhiteListDO> getAppWhiteList(PaperWhitePageVo paperWhitePageVo) {
return examWhiteListMapper.getAppWhiteList(paperWhitePageVo);
}
@Override
public int updateAppList(ExamWhiteListDO ExamWhiteListDO) {
return examWhiteListMapper.updateById(ExamWhiteListDO);
}
@Override
public int insertWhiteApp(ExamWhiteListDO examWhiteListDO) {
return examWhiteListMapper.insert(examWhiteListDO);
}
@Override
public int deleteWhiteAppByParamIds(String id) {
return examWhiteListMapper.deleteWhiteById(id);
}
@Override
public ExamWhiteListDO selectWhiteById(String id) {
return examWhiteListMapper.selectById(id);
}
@Override
public List<String> getAppWhiteListString() {
return examWhiteListMapper.selectNameByTaskId();
}
}

View File

@@ -20,11 +20,15 @@
<delete id="deleteByTaskId">
DELETE FROM exam_white_list WHERE task_id = #{taskId}
</delete>
<delete id="deleteWhiteById">
delete from exam_white_list where id =#{id}
</delete>
<select id="selectByTaskId" resultMap="ExamWhiteListDOResult">
select name from exam_white_list where task_id =#{taskId}
</select>
<select id="selectNameByTaskId" resultType="java.lang.String">
select name from exam_white_list where task_id =#{taskId}
SELECT DISTINCT name
FROM exam_white_list
</select>

View File

@@ -19,6 +19,7 @@ public interface ErrorCodeConstants {
ErrorCode AUTH_LOGIN_NICKNAME_NOT = new ErrorCode(1_002_000_009, "登录失败,账号昵称不正确");
ErrorCode AUTH_LOGIN_BAD_USERNAME_NOT = new ErrorCode(1_002_000_010, "登录失败,账号不正确");
ErrorCode AUTH_LOGIN_BAD_MAC_NOT = new ErrorCode(1_002_000_011, "登录失败MAC地址不正确");
// ========== 菜单模块 1-002-001-000 ==========
ErrorCode MENU_NAME_DUPLICATE = new ErrorCode(1_002_001_000, "已经存在该名字的菜单");
ErrorCode MENU_PARENT_NOT_EXISTS = new ErrorCode(1_002_001_001, "父菜单不存在");

View File

@@ -38,7 +38,7 @@ public class PermissionController {
@Operation(summary = "获得角色拥有的菜单编号")
@Parameter(name = "roleId", description = "角色编号", required = true)
@GetMapping("/list-role-menus")
@PreAuthorize("@ss.hasPermission('system:permission:assign-role-menu')")
// @PreAuthorize("@ss.hasPermission('system:permission:assign-role-menu')")
public CommonResult<Set<Long>> getRoleMenuList(Long roleId) {
return success(permissionService.getRoleMenuListByRoleId(roleId));
}
@@ -52,7 +52,7 @@ public class PermissionController {
@PostMapping("/assign-role-menu")
@Operation(summary = "赋予角色菜单")
@PreAuthorize("@ss.hasPermission('system:permission:assign-role-menu')")
// @PreAuthorize("@ss.hasPermission('system:permission:assign-role-menu')")
public CommonResult<Boolean> assignRoleMenu(@Validated @RequestBody PermissionAssignRoleMenuReqVO reqVO) {
// 开启多租户的情况下,需要过滤掉未开通的菜单
tenantService.handleTenantMenu(menuIds -> reqVO.getMenuIds().removeIf(menuId -> !CollUtil.contains(menuIds, menuId)));
@@ -64,7 +64,7 @@ public class PermissionController {
@PostMapping("/assign-role-data-scope")
@Operation(summary = "赋予角色数据权限")
@PreAuthorize("@ss.hasPermission('system:permission:assign-role-data-scope')")
// @PreAuthorize("@ss.hasPermission('system:permission:assign-role-data-scope')")
public CommonResult<Boolean> assignRoleDataScope(@Valid @RequestBody PermissionAssignRoleDataScopeReqVO reqVO) {
permissionService.assignRoleDataScope(reqVO.getRoleId(), reqVO.getDataScope(), reqVO.getDataScopeDeptIds());
return success(true);
@@ -73,14 +73,14 @@ public class PermissionController {
@Operation(summary = "获得管理员拥有的角色编号列表")
@Parameter(name = "userId", description = "用户编号", required = true)
@GetMapping("/list-user-roles")
@PreAuthorize("@ss.hasPermission('system:permission:assign-user-role')")
// @PreAuthorize("@ss.hasPermission('system:permission:assign-user-role')")
public CommonResult<Set<Long>> listAdminRoles(@RequestParam("userId") Long userId) {
return success(permissionService.getUserRoleIdListByUserId(userId));
}
@Operation(summary = "赋予用户角色")
@PostMapping("/assign-user-role")
@PreAuthorize("@ss.hasPermission('system:permission:assign-user-role')")
// @PreAuthorize("@ss.hasPermission('system:permission:assign-user-role')")
public CommonResult<Boolean> assignUserRole(@Validated @RequestBody PermissionAssignUserRoleReqVO reqVO) {
permissionService.assignUserRole(reqVO.getUserId(), reqVO.getRoleIds());
return success(true);

View File

@@ -60,7 +60,7 @@ public class UserController {
@PostMapping("/create")
@Operation(summary = "新增用户")
@PreAuthorize("@ss.hasPermission('system:user:create')")
// @PreAuthorize("@ss.hasPermission('system:user:create')")
public CommonResult<Long> createUser(@Valid @RequestBody UserSaveReqVO reqVO) {
Long id = userService.createUser(reqVO);
return success(id);
@@ -82,7 +82,7 @@ public class UserController {
@PutMapping("update")
@Operation(summary = "修改用户")
@PreAuthorize("@ss.hasPermission('system:user:update')")
// @PreAuthorize("@ss.hasPermission('system:user:update')")
public CommonResult<Boolean> updateUser(@Valid @RequestBody UserSaveReqVO reqVO) {
userService.updateUser(reqVO);
return success(true);
@@ -106,7 +106,7 @@ public class UserController {
@DeleteMapping("/delete")
@Operation(summary = "删除用户")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('system:user:delete')")
// @PreAuthorize("@ss.hasPermission('system:user:delete')")
public CommonResult<Boolean> deleteUser(@RequestParam("id") Long id) {
userService.deleteUser(id);
return success(true);
@@ -114,7 +114,7 @@ public class UserController {
@PutMapping("/update-password")
@Operation(summary = "重置用户密码")
@PreAuthorize("@ss.hasPermission('system:user:update-password')")
// @PreAuthorize("@ss.hasPermission('system:user:update-password')")
public CommonResult<Boolean> updateUserPassword(@Valid @RequestBody UserUpdatePasswordReqVO reqVO) {
userService.updateUserPassword(reqVO.getId(), reqVO.getPassword());
return success(true);
@@ -122,7 +122,7 @@ public class UserController {
@PutMapping("/update-status")
@Operation(summary = "修改用户状态")
@PreAuthorize("@ss.hasPermission('system:user:update')")
// @PreAuthorize("@ss.hasPermission('system:user:update')")
public CommonResult<Boolean> updateUserStatus(@Valid @RequestBody UserUpdateStatusReqVO reqVO) {
userService.updateUserStatus(reqVO.getId(), reqVO.getStatus());
return success(true);
@@ -172,7 +172,7 @@ public class UserController {
@GetMapping("/get")
@Operation(summary = "获得用户详情")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('system:user:query')")
// @PreAuthorize("@ss.hasPermission('system:user:query')")
public CommonResult<UserRespVO> getUser(@RequestParam("id") Long id) {
AdminUserDO user = userService.getUser(id);
if (user == null) {
@@ -199,7 +199,7 @@ public class UserController {
@GetMapping("/export")
@Operation(summary = "导出用户")
@PreAuthorize("@ss.hasPermission('system:user:export')")
// @PreAuthorize("@ss.hasPermission('system:user:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportUserList(@Validated UserPageReqVO exportReqVO,
HttpServletResponse response) throws IOException {
@@ -262,7 +262,7 @@ public class UserController {
@Parameter(name = "file", description = "Excel 文件", required = true),
@Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true")
})
@PreAuthorize("@ss.hasPermission('system:user:import')")
// @PreAuthorize("@ss.hasPermission('system:user:import')")
public CommonResult<UserImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
@RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception {
List<UserImportExcelVO> list = ExcelUtils.read(file, UserImportExcelVO.class);

View File

@@ -47,4 +47,8 @@ public interface TenantMapper extends BaseMapperX<TenantDO> {
return selectList(TenantDO::getStatus, status);
}
default TenantDO selectMacByTenantId(Long tenantId) {
return selectOne(TenantDO::getId, tenantId);
}
}

View File

@@ -16,7 +16,9 @@ import pc.exam.pp.module.system.api.social.dto.SocialUserRespDTO;
import pc.exam.pp.module.system.controller.admin.auth.vo.*;
import pc.exam.pp.module.system.convert.auth.AuthConvert;
import pc.exam.pp.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO;
import pc.exam.pp.module.system.dal.dataobject.tenant.TenantDO;
import pc.exam.pp.module.system.dal.dataobject.user.AdminUserDO;
import pc.exam.pp.module.system.dal.mysql.tenant.TenantMapper;
import pc.exam.pp.module.system.enums.logger.LoginLogTypeEnum;
import pc.exam.pp.module.system.enums.logger.LoginResultEnum;
import pc.exam.pp.module.system.enums.oauth2.OAuth2ClientConstants;
@@ -37,6 +39,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pc.exam.pp.module.system.util.oauth2.MacUtils;
import java.util.Objects;
@@ -71,6 +74,8 @@ public class AdminAuthServiceImpl implements AdminAuthService {
private SmsCodeApi smsCodeApi;
@Resource
private ConfigService configService;
@Resource
private TenantMapper tenantMapper;
/**
* 验证码的开关,默认为 true
*/
@@ -156,6 +161,13 @@ public class AdminAuthServiceImpl implements AdminAuthService {
} else {
// 使用账号密码,进行登录
user = authenticate(reqVO.getUsername(), reqVO.getPassword());
Long tenantId = user.getTenantId();
TenantDO tenantDO= tenantMapper.selectMacByTenantId(tenantId);
String website = tenantDO.getWebsite();
String physicalMac = MacUtils.getPhysicalMac();
if (!physicalMac.equals(website)){
throw exception(AUTH_LOGIN_BAD_MAC_NOT);
}
}
// 如果 socialType 非空,说明需要绑定社交用户
if (reqVO.getSocialType() != null) {

View File

@@ -1,49 +0,0 @@
package pc.exam.pp.server.config;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import pc.exam.pp.module.system.util.oauth2.MacUtils;
import java.util.List;
@Slf4j
@Component
public class MacValidator {
private final SystemMacProperties macProperties;
public MacValidator(SystemMacProperties macProperties) {
this.macProperties = macProperties;
}
@PostConstruct
public void validateMac() {
try {
String localMac = String.valueOf(MacUtils.getPhysicalMac());
if (localMac == null || localMac.isEmpty()) {
throw new IllegalStateException("无法获取本机 MAC 地址!");
}
String allowed = macProperties.getAllowedMac();
if (allowed == null || allowed.isEmpty()) {
throw new IllegalStateException("系统未配置允许的 MAC 地址!");
}
boolean match = normalize(allowed).equals(normalize(localMac));
if (!match) {
throw new IllegalStateException("该机器 MAC 地址未授权!本机:" + localMac);
}
log.info("✅ MAC 验证通过,本机 MAC: {}", localMac);
} catch (Exception e) {
log.error("❌ MAC 验证失败: {}", e.getMessage());
System.exit(1); // 阻止启动
}
}
private String normalize(String mac) {
return mac == null ? "" : mac.replaceAll("[-:]", "").toUpperCase();
}
}

View File

@@ -1,18 +0,0 @@
package pc.exam.pp.server.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.List;
@Data
@Component
@ConfigurationProperties(prefix = "system") // 对应 application.yml 中的 system: 节点
public class SystemMacProperties {
/**
* 允许的 MAC 地址列表
*/
private String allowedMac;
}

View File

@@ -263,5 +263,4 @@ justauth:
pf4j:
# pluginsDir: /tmp/
pluginsDir: ../plugins
system:
allowed-mac: E4-54-E8-25-F6-14

View File

@@ -304,7 +304,6 @@ exam:
- exam_knowledge_points
- exam_specialty
- exam_app_check
- exam_white_list
- system_tenant
- system_tenant_package
- system_dict_data