Commit 930cdfe7 by 胡懿

接口日志访问功能,人员托名功能

parent 9377fa94
123
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.gintone</groupId>
<artifactId>gt-club</artifactId>
<version>${revision}</version>
</parent>
<artifactId>gt-club-biz</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-common</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-excel</artifactId>
</dependency>
<!-- Web 相关 -->
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-security</artifactId>
</dependency>
<!-- DB 相关 -->
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-mybatis</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
</dependency>
<!--<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>-->
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-amqp</artifactId>
<version>2.3.12</version> <!-- 使用最新的稳定版本 -->
</dependency>
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-session</artifactId>
<!-- 版本号与数据库版本号相同 -->
<version>1.3.3</version>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.70</version>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-system-biz</artifactId>
<version>2.4.2-jdk8-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
\ No newline at end of file
package cn.gintone;
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
public class ErrorInfo {
public static ErrorCode MY_TABLE_NOT_EXISTS = new ErrorCode(1, "我的测试表不存在");
public static ErrorCode KEY_CODE_NOT_EXISTS = new ErrorCode(2, "公钥私钥管理不存在");
public static ErrorCode VISIT_NOT_EXISTS = new ErrorCode(3, "接口安全访问策略不存在");
public static ErrorCode VISIT_INFO_NOT_EXISTS = new ErrorCode(4, "访问规则配置不存在");
public static ErrorCode USER_DES_RULE_NOT_EXISTS = new ErrorCode(5, "人员脱敏规则不存在");
}
package cn.gintone.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "aes") // 前缀与 yml 中的键匹配
public class AesKeyConfig {
private String key;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
@Override
public String toString() {
return "AesKeyConfig{" +
"key='" + key + '\'' +
'}';
}
}
package cn.gintone.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "iotdb") // 前缀与 yml 中的键匹配
public class IotDbConfig {
private String ip;
private Integer port;
private String username;
private String password;
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public Integer getPort() {
return port;
}
public void setPort(Integer port) {
this.port = port;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "IotDbConfig{" +
"ip='" + ip + '\'' +
", port=" + port +
", username='" + username + '\'' +
", password='" + password + '\'' +
'}';
}
}
package cn.gintone.config;
import cn.gintone.dto.WebLogInfo;
import cn.gintone.iotdbUtils.MyIotDbUtils;
import cn.gintone.service.VisitInfoService;
import com.alibaba.fastjson.JSON;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Component;
import java.io.IOException;
/**
* 消费者类
*/
@Component
public class MyConsumer {
@Autowired
private IotDbConfig iotDbConfig;
@Autowired
private VisitInfoService visitInfoService;
/**
* 监听队列---当队列中有消息,则监听器工作,处理接受到的消息
*/
@RabbitListener(queues = "my_boot_fanout_queue1")
public void receive1(Message message) {
byte[] body = message.getBody();
System.out.printf("receive1接受到的消息" + new String(body));
}
@RabbitListener(queues = "my_boot_topic_queue")
public void receive2(Message message, Channel channel) throws IOException {
byte[] body = message.getBody();
String receivedRoutingKey = message.getMessageProperties().getReceivedRoutingKey();
if (receivedRoutingKey.contains("weblog")) {
System.out.println(iotDbConfig);
System.out.println(channel);
String jsonStr = new String(body);
WebLogInfo webLogInfo = null;
try {
webLogInfo = JSON.parseObject(JSON.parse(jsonStr).toString(), WebLogInfo.class);
MyIotDbUtils.inserOne(iotDbConfig, webLogInfo);
visitInfoService.checkWebLogInfo(webLogInfo);
} catch (Exception e) {
e.printStackTrace();
}finally {
return;
}
}
// 手动ack,告知broker要签收的消息的id(deliveryTag)
// channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
}
}
package cn.gintone.config;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 消费者的配置类
*/
@Configuration
public class MyRabbitConfig {
/*
*//**
* 不使用topic的模式
*//*
private static String EXCHANGE_NAME = "my_boot_fanout_exchange"; // 交换机
private static String QUEUE_NAME = "my_boot_fanout_queue1"; // 队列名称
*//**
* 声明交换机
*//*
@Bean
public FanoutExchange fanoutExchange() {
return new FanoutExchange(EXCHANGE_NAME, true, false); // 设置交换机,设置是持久化的,设置不自动删除
}
*//**
* 声明队列
*//*
@Bean
public Queue queue() {
return new Queue(QUEUE_NAME, true,false, false); // 队列名称,是否持久化。是否自动删除
}
*//**
* 创建绑定关系
*//*
@Bean
public Binding binding(FanoutExchange fanoutExchange, Queue queue) {
return BindingBuilder.bind(queue).to(fanoutExchange); // 把队列绑定到交换机上
}
*/
@Autowired
private IotDbConfig iotDbConfig;
/**
* 声明队列、交换机、绑定关系(routing-key)
*/
private static String QUEUE_NAME = "my_boot_topic_queue";
private static String EXCHANGE_NAME = "my_boot_topic_exchange";
/**
* 申明队列
* @return
*/
@Bean
public Queue queue() {
return new Queue(QUEUE_NAME, true,false, false); // 队列名称,是否持久化。是否自动删除
}
/**
* 申明交换机
* @return
*/
@Bean
public TopicExchange topicExchange() {
return new TopicExchange(EXCHANGE_NAME, true, false);
}
/**
* 申明绑定关系
*/
@Bean
public Binding queueBinding(Queue queue, TopicExchange topicExchange) {
return BindingBuilder.bind(queue).to(topicExchange).with("weblog.*");
}
}
package cn.gintone.controller;
import cn.gintone.controller.vo.KeyCodePageReqVO;
import cn.gintone.controller.vo.KeyCodeRespVO;
import cn.gintone.controller.vo.KeyCodeSaveReqVO;
import cn.gintone.dto.EncInfo;
import cn.gintone.entity.KeyCodeDO;
import cn.gintone.service.KeyCodeService;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.List;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
@Tag(name = "管理后台 - 公钥私钥管理")
@RestController
@RequestMapping("/admin-api/gintone/key-code")
@Validated
public class KeyCodeController {
@Resource
private KeyCodeService keyCodeService;
@PostMapping("/create")
@Operation(summary = "创建公钥私钥管理")
@PreAuthorize("@ss.hasPermission('gintone:key-code:create')")
public CommonResult<Long> createKeyCode(@Valid @RequestBody KeyCodeSaveReqVO createReqVO) {
return success(keyCodeService.createKeyCode(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新公钥私钥管理")
@PreAuthorize("@ss.hasPermission('gintone:key-code:update')")
public CommonResult<Boolean> updateKeyCode(@Valid @RequestBody KeyCodeSaveReqVO updateReqVO) {
keyCodeService.updateKeyCode(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除公钥私钥管理")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('gintone:key-code:delete')")
public CommonResult<Boolean> deleteKeyCode(@RequestParam("id") Long id) {
keyCodeService.deleteKeyCode(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得公钥私钥管理")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('gintone:key-code:query')")
public CommonResult<KeyCodeRespVO> getKeyCode(@RequestParam("id") Long id) {
KeyCodeDO keyCode = keyCodeService.getKeyCode(id);
return success(BeanUtils.toBean(keyCode, KeyCodeRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得公钥私钥管理分页")
@PreAuthorize("@ss.hasPermission('gintone:key-code:query')")
public CommonResult<PageResult<KeyCodeRespVO>> getKeyCodePage(@Valid KeyCodePageReqVO pageReqVO) {
PageResult<KeyCodeDO> pageResult = keyCodeService.getKeyCodePage(pageReqVO);
return success(BeanUtils.toBean(pageResult, KeyCodeRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出公钥私钥管理 Excel")
@PreAuthorize("@ss.hasPermission('gintone:key-code:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportKeyCodeExcel(@Valid KeyCodePageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<KeyCodeDO> list = keyCodeService.getKeyCodePage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "公钥私钥管理.xls", "数据", KeyCodeRespVO.class,
BeanUtils.toBean(list, KeyCodeRespVO.class));
}
@PostMapping("/initKey")
@Operation(summary = "初始化公钥私钥")
public CommonResult<String> initKey() {
return success(keyCodeService.initKey());
}
@PostMapping("/rasEncryption")
@Operation(summary = "RAS加密")
public CommonResult<EncInfo> rasEncryption(String info) {
EncInfo encInfo = keyCodeService.rasEncryption(info);
return success(encInfo);
}
@PostMapping("/rasDecrypt")
@Operation(summary = "RAS解密")
public CommonResult<String> rasDecrypt(@RequestBody EncInfo encInfo) {
String info = keyCodeService.rasDecrypt(encInfo);
return success(info);
}
}
\ No newline at end of file
package cn.gintone.controller;
import cn.gintone.service.MySystemService;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthPermissionInfoRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/admin-api/gintone/MySystemController")
public class MySystemController {
@Autowired
private MySystemService mySystemService;
@GetMapping("/getMenuBySysAbbre")
public CommonResult<List<AuthPermissionInfoRespVO.MenuVO>> getMenuBySysAbbre(@RequestParam("sysAbbre") String sysAbbre) {
List<AuthPermissionInfoRespVO.MenuVO> menuBySysAbbre = mySystemService.getMenuBySysAbbre(sysAbbre);
return CommonResult.success(menuBySysAbbre);
}
@GetMapping("/getRoleBySysAbbre")
public CommonResult<List<RoleDO>> getRoleBySysAbbre(@RequestParam("sysAbbre") String sysAbbre) {
List<RoleDO> roleDOList = mySystemService.getRolesBySysAbbre(sysAbbre);
return CommonResult.success(roleDOList);
}
@GetMapping("/getUserBySysAbbreAndRoleId")
public CommonResult<List<AdminUserDO>> getUserBySysAbbreAndRoleId(@RequestParam("sysAbbre") String sysAbbre, @RequestParam("roleId") String roleId) {
List<AdminUserDO> userDOList = mySystemService.getAdminUsersBySysAbbreAndRoleId(sysAbbre, roleId);
return CommonResult.success(userDOList);
}
}
package cn.gintone.controller;
import cn.gintone.controller.vo.MyTablePageReqVO;
import cn.gintone.controller.vo.MyTableRespVO;
import cn.gintone.controller.vo.MyTableSaveReqVO;
import cn.gintone.entity.MyTableDO;
import cn.gintone.service.MyTableService;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
@Tag(name = "管理后台 - 我的测试表")
@RestController
@RequestMapping("/admin-api/sec/my-table")
@Validated
public class MyTableController {
@Resource
private MyTableService myTableService;
@PostMapping("/create")
@Operation(summary = "创建我的测试表")
@PreAuthorize("@ss.hasPermission('sec:my-table:create')")
public CommonResult<Long> createMyTable(@Valid @RequestBody MyTableSaveReqVO createReqVO) {
return success(myTableService.createMyTable(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新我的测试表")
@PreAuthorize("@ss.hasPermission('sec:my-table:update')")
public CommonResult<Boolean> updateMyTable(@Valid @RequestBody MyTableSaveReqVO updateReqVO) {
myTableService.updateMyTable(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除我的测试表")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('sec:my-table:delete')")
public CommonResult<Boolean> deleteMyTable(@RequestParam("id") Long id) {
myTableService.deleteMyTable(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得我的测试表")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('sec:my-table:query')")
public CommonResult<MyTableRespVO> getMyTable(@RequestParam("id") Long id) {
MyTableDO myTable = myTableService.getMyTable(id);
return success(BeanUtils.toBean(myTable, MyTableRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得我的测试表分页")
@PreAuthorize("@ss.hasPermission('sec:my-table:query')")
public CommonResult<PageResult<MyTableRespVO>> getMyTablePage(@Valid MyTablePageReqVO pageReqVO) {
PageResult<MyTableDO> pageResult = myTableService.getMyTablePage(pageReqVO);
return success(BeanUtils.toBean(pageResult, MyTableRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出我的测试表 Excel")
@PreAuthorize("@ss.hasPermission('sec:my-table:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportMyTableExcel(@Valid MyTablePageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<MyTableDO> list = myTableService.getMyTablePage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "我的测试表.xls", "数据", MyTableRespVO.class,
BeanUtils.toBean(list, MyTableRespVO.class));
}
}
\ No newline at end of file
package cn.gintone.controller;
import cn.gintone.iotdbUtils.IotDBUtil;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/testCon")
public class TestController {
@Autowired
private RabbitTemplate rabbitTemplate;
@GetMapping("/testRabbit")
public void testRabbit() {
String message = "hellow spring boot topic message";
rabbitTemplate.convertAndSend("my_boot_fanout_exchange", "product.delete", message);
}
@GetMapping("/testIotdb")
public void testIotdb() {
IotDBUtil.select();
}
}
package cn.gintone.controller;
import cn.gintone.controller.vo.UserDesRulePageReqVO;
import cn.gintone.controller.vo.UserDesRuleRespVO;
import cn.gintone.controller.vo.UserDesRuleSaveReqVO;
import cn.gintone.dto.DesInfo;
import cn.gintone.entity.UserDesRuleDO;
import cn.gintone.service.UserDesRuleService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
@Tag(name = "管理后台 - 人员脱敏规则")
@RestController
@RequestMapping("/admin-api/sec/user-des-rule")
@Validated
public class UserDesRuleController {
@Resource
private UserDesRuleService userDesRuleService;
@PostMapping("/create")
@Operation(summary = "创建人员脱敏规则")
@PreAuthorize("@ss.hasPermission('sec:user-des-rule:create')")
public CommonResult<Long> createUserDesRule(@Valid @RequestBody UserDesRuleSaveReqVO createReqVO) {
return success(userDesRuleService.createUserDesRule(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新人员脱敏规则")
@PreAuthorize("@ss.hasPermission('sec:user-des-rule:update')")
public CommonResult<Boolean> updateUserDesRule(@Valid @RequestBody UserDesRuleSaveReqVO updateReqVO) {
userDesRuleService.updateUserDesRule(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除人员脱敏规则")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('sec:user-des-rule:delete')")
public CommonResult<Boolean> deleteUserDesRule(@RequestParam("id") Long id) {
userDesRuleService.deleteUserDesRule(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得人员脱敏规则")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('sec:user-des-rule:query')")
public CommonResult<UserDesRuleRespVO> getUserDesRule(@RequestParam("id") Long id) {
UserDesRuleDO userDesRule = userDesRuleService.getUserDesRule(id);
return success(BeanUtils.toBean(userDesRule, UserDesRuleRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得人员脱敏规则分页")
@PreAuthorize("@ss.hasPermission('sec:user-des-rule:query')")
public CommonResult<PageResult<UserDesRuleRespVO>> getUserDesRulePage(@Valid UserDesRulePageReqVO pageReqVO) {
PageResult<UserDesRuleDO> pageResult = userDesRuleService.getUserDesRulePage(pageReqVO);
return success(BeanUtils.toBean(pageResult, UserDesRuleRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出人员脱敏规则 Excel")
@PreAuthorize("@ss.hasPermission('sec:user-des-rule:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportUserDesRuleExcel(@Valid UserDesRulePageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<UserDesRuleDO> list = userDesRuleService.getUserDesRulePage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "人员脱敏规则.xls", "数据", UserDesRuleRespVO.class,
BeanUtils.toBean(list, UserDesRuleRespVO.class));
}
@GetMapping("/checkName")
@Operation(summary = "验证属性是否存在")
public CommonResult<Boolean> checkName(@RequestParam("name") String name, @RequestParam(value = "id", required = false) Long id) {
return success(userDesRuleService.checkName(name, id));
}
@PostMapping("/userRuleDes")
@Operation(summary = "人员脱敏")
public CommonResult<String> userRuleDes(@RequestBody DesInfo desInfo) {
String str = userDesRuleService.userRuleDes(desInfo.getJsonStr());
return CommonResult.success(str);
}
@PostMapping("/userRuleDesMap")
@Operation(summary = "人员脱敏")
public CommonResult<Map<String, Object>> userRuleDesMap(@RequestBody Map<String, Object> map) {
Map<String, Object> resultMap = userDesRuleService.userRuleDesMap(map);
return CommonResult.success(resultMap);
}
@PostMapping("/userRuleDesList")
@Operation(summary = "人员批量脱敏")
public CommonResult<String> userRuleDesList(@RequestBody DesInfo desInfo) {
String str = userDesRuleService.userRuleDesArr(desInfo.getJsonArrStr());
return CommonResult.success(str);
}
@PostMapping("/userRuleDesListMap")
@Operation(summary = "人员脱敏")
public CommonResult<List<Map<String, Object>>> userRuleDesListMap(@RequestBody List<Map<String, Object>> lisetMap) {
List<Map<String, Object>> resultList = userDesRuleService.userRuleDesListMap(lisetMap);
return CommonResult.success(resultList);
}
}
\ No newline at end of file
package cn.gintone.controller;
import cn.gintone.controller.vo.VisitPageReqVO;
import cn.gintone.controller.vo.VisitRespVO;
import cn.gintone.controller.vo.VisitSaveReqVO;
import cn.gintone.entity.VisitDO;
import cn.gintone.service.VisitService;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.List;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
@Tag(name = "管理后台 - 接口安全访问策略")
@RestController
@RequestMapping("/admin-api/visit/visit")
@Validated
public class VisitController {
@Resource
private VisitService visitService;
@PostMapping("/create")
@Operation(summary = "创建接口安全访问策略")
@PreAuthorize("@ss.hasPermission('visit:visit:create')")
public CommonResult<Long> createVisit(@Valid @RequestBody VisitSaveReqVO createReqVO) {
return success(visitService.createVisit(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新接口安全访问策略")
@PreAuthorize("@ss.hasPermission('visit:visit:update')")
public CommonResult<Boolean> updateVisit(@Valid @RequestBody VisitSaveReqVO updateReqVO) {
visitService.updateVisit(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除接口安全访问策略")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('visit:visit:delete')")
public CommonResult<Boolean> deleteVisit(@RequestParam("id") Long id) {
visitService.deleteVisit(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得接口安全访问策略")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('visit:visit:query')")
public CommonResult<VisitRespVO> getVisit(@RequestParam("id") Long id) {
VisitDO visit = visitService.getVisit(id);
return success(BeanUtils.toBean(visit, VisitRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得接口安全访问策略分页")
@PreAuthorize("@ss.hasPermission('visit:visit:query')")
public CommonResult<PageResult<VisitRespVO>> getVisitPage(@Valid VisitPageReqVO pageReqVO) {
PageResult<VisitDO> pageResult = visitService.getVisitPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, VisitRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出接口安全访问策略 Excel")
@PreAuthorize("@ss.hasPermission('visit:visit:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportVisitExcel(@Valid VisitPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<VisitDO> list = visitService.getVisitPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "接口安全访问策略.xls", "数据", VisitRespVO.class,
BeanUtils.toBean(list, VisitRespVO.class));
}
}
\ No newline at end of file
package cn.gintone.controller;
import cn.gintone.controller.vo.VisitInfoPageReqVO;
import cn.gintone.controller.vo.VisitInfoRespVO;
import cn.gintone.controller.vo.VisitInfoSaveReqVO;
import cn.gintone.entity.VisitInfoDO;
import cn.gintone.service.VisitInfoService;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.List;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
@Tag(name = "管理后台 - 访问规则配置")
@RestController
@RequestMapping("/admin-api/visitInfo/visit-info")
@Validated
public class VisitInfoController {
@Resource
private VisitInfoService visitInfoService;
@PostMapping("/create")
@Operation(summary = "创建访问规则配置")
public CommonResult<Long> createVisitInfo(@Valid @RequestBody VisitInfoSaveReqVO createReqVO) {
return success(visitInfoService.createVisitInfo(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新访问规则配置")
public CommonResult<Boolean> updateVisitInfo(@Valid @RequestBody VisitInfoSaveReqVO updateReqVO) {
visitInfoService.updateVisitInfo(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除访问规则配置")
@Parameter(name = "id", description = "编号", required = true)
public CommonResult<Boolean> deleteVisitInfo(@RequestParam("id") Long id) {
visitInfoService.deleteVisitInfo(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得访问规则配置")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
public CommonResult<VisitInfoRespVO> getVisitInfo(@RequestParam("id") Long id) {
VisitInfoDO visitInfo = visitInfoService.getVisitInfo(id);
return success(BeanUtils.toBean(visitInfo, VisitInfoRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得访问规则配置分页")
public CommonResult<PageResult<VisitInfoRespVO>> getVisitInfoPage(@Valid VisitInfoPageReqVO pageReqVO) {
PageResult<VisitInfoDO> pageResult = visitInfoService.getVisitInfoPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, VisitInfoRespVO.class));
}
@GetMapping("/getList")
@Operation(summary = "获得访问规则配置")
public CommonResult<List<VisitInfoDO>> getList(VisitInfoPageReqVO pageReqVO) {
List<VisitInfoDO> list = visitInfoService.getList(pageReqVO);
return success(list);
}
@GetMapping("/export-excel")
@Operation(summary = "导出访问规则配置 Excel")
@ApiAccessLog(operateType = EXPORT)
public void exportVisitInfoExcel(@Valid VisitInfoPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<VisitInfoDO> list = visitInfoService.getVisitInfoPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "访问规则配置.xls", "数据", VisitInfoRespVO.class,
BeanUtils.toBean(list, VisitInfoRespVO.class));
}
@PostMapping("/saveAllVisitInfo")
@Operation(summary = "创建访问规则配置")
public CommonResult<Boolean> saveAllVisitInfo(@Valid @RequestBody List<VisitInfoSaveReqVO> visitInfoSaveReqVOList) {
return success(visitInfoService.saveAllVisitInfo(visitInfoSaveReqVOList));
}
@DeleteMapping("/deleteByVisitId")
@Operation(summary = "根据visitId删除访问规则配置")
@Parameter(name = "id", description = "编号", required = true)
public CommonResult<Boolean> deleteByVisitId(@RequestParam("visitId") Long visitId) {
visitInfoService.deleteByVisitId(visitId);
return success(true);
}
@PutMapping("/updateAllVisitInfo")
@Operation(summary = "更新访问规则配置")
public CommonResult<Boolean> updateAllVisitInfo(@Valid @RequestBody List<VisitInfoSaveReqVO> visitInfoSaveReqVOList) {
return success(visitInfoService.updateAllVisitInfo(visitInfoSaveReqVOList));
}
}
\ No newline at end of file
package cn.gintone.controller;
import cn.gintone.config.IotDbConfig;
import cn.gintone.dto.WebIllLogInfo;
import cn.gintone.dto.WebLogInfo;
import cn.gintone.dto.WebLogInfoVo;
import cn.gintone.iotdbUtils.MyDateUtils;
import cn.gintone.iotdbUtils.MyIotDbUtils;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import com.alibaba.fastjson.JSON;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
@RestController
@RequestMapping("/admin-api/gintone/webLogInfo")
public class WebLogInfoController {
@Autowired
private RabbitTemplate rabbitTemplate;
@Autowired
private IotDbConfig iotDbConfig;
@PostMapping("/initIotDBDatabase")
@Operation(summary = "初始化数据库")
public CommonResult<String> initIotDBDatabase() {
MyIotDbUtils.createDatabase(iotDbConfig);
return CommonResult.success("初始化成功");
}
@PostMapping("/initIotDBTable")
@Operation(summary = "初始化时间序列")
public CommonResult<String> initIotDBTable() {
MyIotDbUtils.createWebLogInfoTimeseries(iotDbConfig);
return CommonResult.success("初始化成功");
}
@PostMapping("/initIllIotDBTable")
@Operation(summary = "初始化时间序列")
public CommonResult<String> initIllIotDBTable() {
MyIotDbUtils.createIllegalLogTimeseries(iotDbConfig);
return CommonResult.success("初始化成功");
}
@PostMapping("/saveWebLogInfo")
@Operation(summary = "外部性请求保存日志")
public CommonResult<String> saveWebLogInfo(@RequestBody WebLogInfo webLogInfo) {
if (null == webLogInfo.getAccessed()) {
webLogInfo.setAccessed(MyDateUtils.longToString(new Date().getTime()));
}
String webLogInfoStr = JSON.toJSONString(webLogInfo);
rabbitTemplate.convertAndSend("my_boot_topic_exchange", "weblog.save", webLogInfoStr);
return CommonResult.success("保存成功");
}
@GetMapping("/countWebLogInfo")
@Operation(summary = "统计日志条数接口")
public CommonResult<Long> countWebLogInfo(WebLogInfoVo webLogInfoVo) {
long pageCount = MyIotDbUtils.countWebInfo(iotDbConfig, webLogInfoVo);
return CommonResult.success(pageCount);
}
@GetMapping("/webLogInfoList")
@Operation(summary = "查询接口日志接口")
public CommonResult<List<WebLogInfo>> webLogInfoList(WebLogInfoVo webLogInfoVo) {
List<WebLogInfo> webLogInfoList = MyIotDbUtils.selectWebInfo(iotDbConfig, webLogInfoVo);
return CommonResult.success(webLogInfoList);
}
@GetMapping("/webLogInfoWarningList")
@Operation(summary = "查询警告接口日志接口")
public CommonResult<List<WebLogInfo>> webLogInfoWarningList(WebLogInfoVo webLogInfoVo) {
webLogInfoVo.setType("warning");
List<WebLogInfo> webLogInfoList = MyIotDbUtils.selectWebInfo(iotDbConfig, webLogInfoVo);
return CommonResult.success(webLogInfoList);
}
@GetMapping("/webLogInfoErrorList")
@Operation(summary = "查询警告接口日志接口")
public CommonResult<List<WebLogInfo>> webLogInfoErrorList(WebLogInfoVo webLogInfoVo) {
webLogInfoVo.setType("error");
List<WebLogInfo> webLogInfoList = MyIotDbUtils.selectWebInfo(iotDbConfig, webLogInfoVo);
return CommonResult.success(webLogInfoList);
}
@GetMapping("/countWebIllLogInfo")
@Operation(summary = "统计非法日志条数接口")
public CommonResult<Long> countWebIllLogInfo(WebLogInfoVo webLogInfoVo) {
long pageCount = MyIotDbUtils.countWebIllInfo(iotDbConfig, webLogInfoVo);
return CommonResult.success(pageCount);
}
@GetMapping("/webIllLogInfoList")
@Operation(summary = "查询非法日志记录")
public CommonResult<List<WebIllLogInfo>> webIllLogInfoList(WebLogInfoVo webLogInfoVo) {
List<WebIllLogInfo> webIllLogInfos = MyIotDbUtils.selectWebIllInfo(iotDbConfig, webLogInfoVo);
return CommonResult.success(webIllLogInfos);
}
}
package cn.gintone.controller.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 公钥私钥管理分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class KeyCodePageReqVO extends PageParam {
@Schema(description = "类型用户编号", example = "1")
private Integer type;
@Schema(description = "公钥用户类型")
private String publicKey;
@Schema(description = "私钥")
private String privateKey;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
@Schema(description = "跟新时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] updateTime;
}
\ No newline at end of file
package cn.gintone.controller.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
@Schema(description = "管理后台 - 公钥私钥管理 Response VO")
@Data
@ExcelIgnoreUnannotated
public class KeyCodeRespVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "4344")
@ExcelProperty("id")
private Long id;
@Schema(description = "类型用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@ExcelProperty("类型用户编号")
private Integer type;
@Schema(description = "公钥用户类型", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("公钥用户类型")
private String publicKey;
@Schema(description = "私钥", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("私钥")
private String privateKey;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
@Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("更新时间")
private LocalDateTime updateTime;
}
\ No newline at end of file
package cn.gintone.controller.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 公钥私钥管理新增/修改 Request VO")
@Data
public class KeyCodeSaveReqVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "4344")
private Long id;
@Schema(description = "类型用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "类型用户编号不能为空")
private Integer type;
@Schema(description = "公钥用户类型", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "公钥用户类型不能为空")
private String publicKey;
@Schema(description = "私钥", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "私钥不能为空")
private String privateKey;
}
\ No newline at end of file
package cn.gintone.controller.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import java.math.BigDecimal;
@Schema(description = "管理后台 - 我的测试表分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MyTablePageReqVO extends PageParam {
@Schema(description = "name", example = "李四")
private String name;
@Schema(description = "age")
private Integer age;
@Schema(description = "money")
private BigDecimal money;
}
\ No newline at end of file
package cn.gintone.controller.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.math.BigDecimal;
import com.alibaba.excel.annotation.*;
@Schema(description = "管理后台 - 我的测试表 Response VO")
@Data
@ExcelIgnoreUnannotated
public class MyTableRespVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "29789")
@ExcelProperty("id")
private Long id;
@Schema(description = "name", example = "李四")
@ExcelProperty("name")
private String name;
@Schema(description = "age")
@ExcelProperty("age")
private Integer age;
@Schema(description = "money")
@ExcelProperty("money")
private BigDecimal money;
}
\ No newline at end of file
package cn.gintone.controller.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
import java.math.BigDecimal;
@Schema(description = "管理后台 - 我的测试表新增/修改 Request VO")
@Data
public class MyTableSaveReqVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "29789")
private Long id;
@Schema(description = "name", example = "李四")
private String name;
@Schema(description = "age")
private Integer age;
@Schema(description = "money")
private BigDecimal money;
}
\ No newline at end of file
package cn.gintone.controller.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 人员脱敏规则分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class UserDesRulePageReqVO extends PageParam {
@Schema(description = "属性名称", example = "李四")
private String name;
@Schema(description = "属性描述")
private String attr;
@Schema(description = "规则")
private Integer rule;
@Schema(description = "配置项1")
private String valueOne;
@Schema(description = "配置项2")
private String valueTwo;
@Schema(description = "配置项3")
private String valueThree;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}
\ No newline at end of file
package cn.gintone.controller.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
@Schema(description = "管理后台 - 人员脱敏规则 Response VO")
@Data
@ExcelIgnoreUnannotated
public class UserDesRuleRespVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "4684")
@ExcelProperty("id")
private Long id;
@Schema(description = "属性名称", example = "李四")
@ExcelProperty("属性名称")
private String name;
@Schema(description = "属性描述")
@ExcelProperty("属性描述")
private String attr;
@Schema(description = "规则")
@ExcelProperty("规则")
private Integer rule;
@Schema(description = "配置项1")
@ExcelProperty("配置项1")
private String valueOne;
@Schema(description = "配置项2")
@ExcelProperty("配置项2")
private String valueTwo;
@Schema(description = "配置项3")
@ExcelProperty("配置项3")
private String valueThree;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}
\ No newline at end of file
package cn.gintone.controller.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 人员脱敏规则新增/修改 Request VO")
@Data
public class UserDesRuleSaveReqVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "4684")
private Long id;
@Schema(description = "属性名称", example = "李四")
private String name;
@Schema(description = "属性描述")
private String attr;
@Schema(description = "规则")
private Integer rule;
@Schema(description = "配置项1")
private String valueOne;
@Schema(description = "配置项2")
private String valueTwo;
@Schema(description = "配置项3")
private String valueThree;
}
\ No newline at end of file
package cn.gintone.controller.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 访问规则配置分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class VisitInfoPageReqVO extends PageParam {
@Schema(description = "规则表外键", example = "10305")
private Long visitId;
@Schema(description = "系统简称")
private String sysAbbre;
@Schema(description = "系统名称", example = "王五")
private String sysAbbreName;
@Schema(description = "菜单名称", example = "王五")
private String urlName;
@Schema(description = "菜单地址", example = "https://www.iocoder.cn")
private String url;
@Schema(description = "菜单地址Id", example = "https://www.iocoder.cn")
private String urlId;
@Schema(description = "角色id", example = "6818")
private String roleId;
@Schema(description = "角色名称", example = "李四")
private String roleName;
@Schema(description = "用户id", example = "31619")
private String userId;
@Schema(description = "用户名称", example = "王五")
private String userName;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}
\ No newline at end of file
package cn.gintone.controller.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
@Schema(description = "管理后台 - 访问规则配置 Response VO")
@Data
@ExcelIgnoreUnannotated
public class VisitInfoRespVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "31715")
@ExcelProperty("id")
private Long id;
@Schema(description = "规则表外键", requiredMode = Schema.RequiredMode.REQUIRED, example = "10305")
@ExcelProperty("规则表外键")
private Long visitId;
@Schema(description = "系统简称", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("系统简称")
private String sysAbbre;
@Schema(description = "系统名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
@ExcelProperty("系统名称")
private String sysAbbreName;
@Schema(description = "菜单名称", example = "王五")
@ExcelProperty("菜单名称")
private String urlName;
@Schema(description = "菜单地址", example = "https://www.iocoder.cn")
@ExcelProperty("菜单地址")
private String url;
@Schema(description = "菜单地址Id", example = "https://www.iocoder.cn")
@ExcelProperty("菜单地址Id")
private String urlId;
@Schema(description = "角色id", example = "6818")
@ExcelProperty("角色id")
private String roleId;
@Schema(description = "角色名称", example = "李四")
@ExcelProperty("角色名称")
private String roleName;
@Schema(description = "用户id", example = "31619")
@ExcelProperty("用户id")
private String userId;
@Schema(description = "用户名称", example = "王五")
@ExcelProperty("用户名称")
private String userName;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}
\ No newline at end of file
package cn.gintone.controller.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 访问规则配置新增/修改 Request VO")
@Data
public class VisitInfoSaveReqVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "31715")
private Long id;
@Schema(description = "规则表外键", requiredMode = Schema.RequiredMode.REQUIRED, example = "10305")
@NotNull(message = "规则表外键不能为空")
private Long visitId;
@Schema(description = "系统简称", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "系统简称不能为空")
private String sysAbbre;
@Schema(description = "系统名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
@NotEmpty(message = "系统名称不能为空")
private String sysAbbreName;
@Schema(description = "菜单名称", example = "王五")
private String urlName;
@Schema(description = "菜单地址", example = "https://www.iocoder.cn")
private String url;
@Schema(description = "菜单地址Id", example = "https://www.iocoder.cn")
private String urlId;
@Schema(description = "角色id", example = "6818")
private String roleId;
@Schema(description = "角色名称", example = "李四")
private String roleName;
@Schema(description = "用户id", example = "31619")
private String userId;
@Schema(description = "用户名称", example = "王五")
private String userName;
}
\ No newline at end of file
package cn.gintone.controller.vo;
import lombok.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 接口安全访问策略分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class VisitPageReqVO extends PageParam {
@Schema(description = "规则名称", example = "芋艿")
private String name;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}
\ No newline at end of file
package cn.gintone.controller.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
@Schema(description = "管理后台 - 接口安全访问策略 Response VO")
@Data
@ExcelIgnoreUnannotated
public class VisitRespVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "2361")
@ExcelProperty("id")
private Long id;
@Schema(description = "规则名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
@ExcelProperty("规则名称")
private String name;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}
\ No newline at end of file
package cn.gintone.controller.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 接口安全访问策略新增/修改 Request VO")
@Data
public class VisitSaveReqVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "2361")
private Long id;
@Schema(description = "规则名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
@NotEmpty(message = "规则名称不能为空")
private String name;
}
\ No newline at end of file
package cn.gintone.dal;
import cn.gintone.controller.vo.KeyCodePageReqVO;
import cn.gintone.entity.KeyCodeDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import org.apache.ibatis.annotations.Mapper;
/**
* 公钥私钥管理 Mapper
*
* @author 胡懿
*/
@Mapper
public interface KeyCodeMapper extends BaseMapperX<KeyCodeDO> {
default PageResult<KeyCodeDO> selectPage(KeyCodePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<KeyCodeDO>()
.eqIfPresent(KeyCodeDO::getType, reqVO.getType())
.eqIfPresent(KeyCodeDO::getPublicKey, reqVO.getPublicKey())
.eqIfPresent(KeyCodeDO::getPrivateKey, reqVO.getPrivateKey())
.betweenIfPresent(KeyCodeDO::getCreateTime, reqVO.getCreateTime())
.betweenIfPresent(KeyCodeDO::getUpdateTime, reqVO.getUpdateTime())
.orderByDesc(KeyCodeDO::getId));
}
}
\ No newline at end of file
package cn.gintone.dal;
import cn.gintone.controller.vo.MyTablePageReqVO;
import cn.gintone.entity.MyTableDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import org.apache.ibatis.annotations.Mapper;
/**
* 我的测试表 Mapper
*
* @author 胡懿
*/
@Mapper
public interface MyTableMapper extends BaseMapperX<MyTableDO> {
default PageResult<MyTableDO> selectPage(MyTablePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<MyTableDO>()
.likeIfPresent(MyTableDO::getName, reqVO.getName())
.eqIfPresent(MyTableDO::getAge, reqVO.getAge())
.eqIfPresent(MyTableDO::getMoney, reqVO.getMoney())
.orderByDesc(MyTableDO::getId));
}
}
\ No newline at end of file
package cn.gintone.dal;
import cn.gintone.controller.vo.UserDesRulePageReqVO;
import cn.gintone.entity.UserDesRuleDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import org.apache.ibatis.annotations.Mapper;
/**
* 人员脱敏规则 Mapper
*
* @author 胡懿
*/
@Mapper
public interface UserDesRuleMapper extends BaseMapperX<UserDesRuleDO> {
default PageResult<UserDesRuleDO> selectPage(UserDesRulePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<UserDesRuleDO>()
.likeIfPresent(UserDesRuleDO::getName, reqVO.getName())
.likeIfPresent(UserDesRuleDO::getAttr, reqVO.getAttr())
.betweenIfPresent(UserDesRuleDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(UserDesRuleDO::getId));
}
}
\ No newline at end of file
package cn.gintone.dal;
import cn.gintone.controller.vo.VisitInfoPageReqVO;
import cn.gintone.controller.vo.VisitInfoRespVO;
import cn.gintone.entity.VisitInfoDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 访问规则配置 Mapper
*
* @author 胡懿
*/
@Mapper
public interface VisitInfoMapper extends BaseMapperX<VisitInfoDO> {
default PageResult<VisitInfoDO> selectPage(VisitInfoPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<VisitInfoDO>()
.eqIfPresent(VisitInfoDO::getVisitId, reqVO.getVisitId())
.eqIfPresent(VisitInfoDO::getSysAbbre, reqVO.getSysAbbre())
.likeIfPresent(VisitInfoDO::getSysAbbreName, reqVO.getSysAbbreName())
.likeIfPresent(VisitInfoDO::getUrlName, reqVO.getUrlName())
.eqIfPresent(VisitInfoDO::getUrl, reqVO.getUrl())
.eqIfPresent(VisitInfoDO::getUrlId, reqVO.getUrlId())
.eqIfPresent(VisitInfoDO::getRoleId, reqVO.getRoleId())
.likeIfPresent(VisitInfoDO::getRoleName, reqVO.getRoleName())
.eqIfPresent(VisitInfoDO::getUserId, reqVO.getUserId())
.likeIfPresent(VisitInfoDO::getUserName, reqVO.getUserName())
.betweenIfPresent(VisitInfoDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(VisitInfoDO::getId));
}
default List<VisitInfoDO> selectList(VisitInfoPageReqVO reqVO) {
List<VisitInfoDO> visitInfoDOS = selectList(new LambdaQueryWrapperX<VisitInfoDO>()
.eqIfPresent(VisitInfoDO::getVisitId, reqVO.getVisitId())
.eqIfPresent(VisitInfoDO::getSysAbbre, reqVO.getSysAbbre())
.likeIfPresent(VisitInfoDO::getSysAbbreName, reqVO.getSysAbbreName())
.likeIfPresent(VisitInfoDO::getUrlName, reqVO.getUrlName())
.eqIfPresent(VisitInfoDO::getUrl, reqVO.getUrl())
.eqIfPresent(VisitInfoDO::getUrlId, reqVO.getUrlId())
.eqIfPresent(VisitInfoDO::getRoleId, reqVO.getRoleId())
.likeIfPresent(VisitInfoDO::getRoleName, reqVO.getRoleName())
.eqIfPresent(VisitInfoDO::getUserId, reqVO.getUserId())
.likeIfPresent(VisitInfoDO::getUserName, reqVO.getUserName())
.betweenIfPresent(VisitInfoDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(VisitInfoDO::getId));
return visitInfoDOS;
}
}
\ No newline at end of file
package cn.gintone.dal;
import cn.gintone.controller.vo.VisitPageReqVO;
import cn.gintone.entity.VisitDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import org.apache.ibatis.annotations.Mapper;
/**
* 接口安全访问策略 Mapper
*
* @author 胡懿
*/
@Mapper
public interface VisitMapper extends BaseMapperX<VisitDO> {
default PageResult<VisitDO> selectPage(VisitPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<VisitDO>()
.likeIfPresent(VisitDO::getName, reqVO.getName())
.betweenIfPresent(VisitDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(VisitDO::getId));
}
}
\ No newline at end of file
package cn.gintone.dto;
public class DesInfo {
private String jsonStr;
private String jsonArrStr;
public String getJsonStr() {
return jsonStr;
}
public void setJsonStr(String jsonStr) {
this.jsonStr = jsonStr;
}
public String getJsonArrStr() {
return jsonArrStr;
}
public void setJsonArrStr(String jsonArrStr) {
this.jsonArrStr = jsonArrStr;
}
}
package cn.gintone.dto;
/**
* 加密信息
*/
public class EncInfo {
private String privateKey;
private String info;
public String getPrivateKey() {
return privateKey;
}
public void setPrivateKey(String privateKey) {
this.privateKey = privateKey;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
@Override
public String toString() {
return "EncInfo{" +
"privateKey='" + privateKey + '\'' +
", info='" + info + '\'' +
'}';
}
}
package cn.gintone.dto;
public class WebIllLogInfo {
private Long timesta;
private String timestaStr;
private String userId; // 用户id
private String username; // 用户名
private String sysAbbre; // 系统简称
private String url; // 访问链接
private String accessed; // 访问时间
private String type; // 日志类型(url, info, warning, error)
private String clientIp; // 访问端ip
private String remark; // 备注
private String illType; // 非法访问类型(noRule:无访问策略配置)
public Long getTimesta() {
return timesta;
}
public void setTimesta(Long timesta) {
this.timesta = timesta;
}
public String getTimestaStr() {
return timestaStr;
}
public void setTimestaStr(String timestaStr) {
this.timestaStr = timestaStr;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getSysAbbre() {
return sysAbbre;
}
public void setSysAbbre(String sysAbbre) {
this.sysAbbre = sysAbbre;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getAccessed() {
return accessed;
}
public void setAccessed(String accessed) {
this.accessed = accessed;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getClientIp() {
return clientIp;
}
public void setClientIp(String clientIp) {
this.clientIp = clientIp;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public String getIllType() {
return illType;
}
public void setIllType(String illType) {
this.illType = illType;
}
@Override
public String toString() {
return "WebIllLogInfo{" +
"timesta=" + timesta +
", timestaStr='" + timestaStr + '\'' +
", userId='" + userId + '\'' +
", username='" + username + '\'' +
", sysAbbre='" + sysAbbre + '\'' +
", url='" + url + '\'' +
", accessed='" + accessed + '\'' +
", type='" + type + '\'' +
", clientIp='" + clientIp + '\'' +
", remark='" + remark + '\'' +
", illType='" + illType + '\'' +
'}';
}
}
package cn.gintone.dto;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
public class WebLogInfo {
private Long timesta;
private String timestaStr;
private String userId; // 用户id
private String username; // 用户名
private String sysAbbre; // 系统简称
private String url; // 访问链接
private String accessed; // 访问时间
private String type; // 日志类型(url, info, warning, error)
private String clientIp; // 访问端ip
private String remark; // 备注
public Long getTimesta() {
return timesta;
}
public void setTimesta(Long timesta) {
this.timesta = timesta;
}
public String getTimestaStr() {
return timestaStr;
}
public void setTimestaStr(String timestaStr) {
this.timestaStr = timestaStr;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getSysAbbre() {
return sysAbbre;
}
public void setSysAbbre(String sysAbbre) {
this.sysAbbre = sysAbbre;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getAccessed() {
return accessed;
}
public void setAccessed(String accessed) {
this.accessed = accessed;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getClientIp() {
return clientIp;
}
public void setClientIp(String clientIp) {
this.clientIp = clientIp;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
@Override
public String toString() {
return "WebLogInfo{" +
"timesta=" + timesta +
", timestaStr='" + timestaStr + '\'' +
", userId='" + userId + '\'' +
", username='" + username + '\'' +
", sysAbbre='" + sysAbbre + '\'' +
", url='" + url + '\'' +
", accessed='" + accessed + '\'' +
", type='" + type + '\'' +
", clientIp='" + clientIp + '\'' +
", remark='" + remark + '\'' +
'}';
}
}
package cn.gintone.dto;
/**
* WebLogInfo的查询对象
*/
public class WebLogInfoVo {
private Long beginTime;
private Long endTime;
private String type;
private String sysAbbre;
private Integer pageSize;
private Integer pageNum;
private Integer illType;
public Long getBeginTime() {
return beginTime;
}
public void setBeginTime(Long beginTime) {
this.beginTime = beginTime;
}
public Long getEndTime() {
return endTime;
}
public void setEndTime(Long endTime) {
this.endTime = endTime;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getSysAbbre() {
return sysAbbre;
}
public void setSysAbbre(String sysAbbre) {
this.sysAbbre = sysAbbre;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public Integer getPageNum() {
return pageNum;
}
public void setPageNum(Integer pageNum) {
this.pageNum = pageNum;
}
public Integer getIllType() {
return illType;
}
public void setIllType(Integer illType) {
this.illType = illType;
}
@Override
public String toString() {
return "WebLogInfoVo{" +
"beginTime=" + beginTime +
", endTime=" + endTime +
", type='" + type + '\'' +
", sysAbbre='" + sysAbbre + '\'' +
", pageSize=" + pageSize +
", pageNum=" + pageNum +
", illType=" + illType +
'}';
}
}
package cn.gintone.encryptionUtils;
import cn.hutool.json.JSONObject;
import com.alibaba.druid.util.StringUtils;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.spec.KeySpec;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
public class DataDesensitizationUtils {
// 无效化处理(从第几位到第几位)
public static String invalidatePhone(String str, int beginNum, int endNum) {
if (StringUtils.isEmpty(str)) {
return "**";
}
if (beginNum > endNum) {
return "**";
}
String score = "";
for (int i = 0; i < (endNum - beginNum); i++) {
score += "*";
}
if (endNum >= str.length()) {
return str.substring(0, beginNum) + score + str.substring(str.length() );
}
return str.substring(0, beginNum) + score + str.substring(endNum);
}
// 随机值替换
public static String randomPhone(String str) {
if (str == null || str.isEmpty()) {
return str;
}
Random random = new Random();
char[] chars = str.toCharArray();
for (int i = 0; i < chars.length; i++) {
// 生成32到126之间的随机ASCII字符(包含空格和可打印字符)
chars[i] = (char) (random.nextInt(95) + 32);
}
return new String(chars);
}
// 数据替换
public static String replaceRange(String original, String replacement, int start, int end) {
if (original == null) {
return null;
}
// 处理替换字符串为null的情况
if (replacement == null) {
replacement = "";
}
// 规范索引范围
int safeStart = Math.max(0, start);
int safeEnd = Math.min(end, original.length());
// 确保起始索引不大于结束索引
if (safeStart > safeEnd) {
int temp = safeStart;
safeStart = safeEnd;
safeEnd = temp;
}
// 构建新字符串
String prefix = original.substring(0, safeStart);
String suffix = original.substring(safeEnd);
return prefix + replacement + suffix;
}
// 对称加密(示例)
public static String encryptAES(String data, String key) throws Exception {
SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
byte[] encrypted = cipher.doFinal(data.getBytes());
return Base64.getEncoder().encodeToString(encrypted);
}
// 解密方法
public static String decryptAES(String encryptedData, String key) throws Exception {
// 1. 创建相同的密钥规范
SecretKeySpec secretKey = new SecretKeySpec(
key.getBytes(StandardCharsets.UTF_8),
"AES"
);
// 2. 获取密码器实例(参数必须与加密时完全一致)
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
// 3. 初始化密码器为解密模式
cipher.init(Cipher.DECRYPT_MODE, secretKey);
// 4. 执行解密操作
byte[] decodedData = Base64.getDecoder().decode(encryptedData);
byte[] decrypted = cipher.doFinal(decodedData);
return new String(decrypted, StandardCharsets.UTF_8);
}
/*// 偏移运算
public static int offsetAndRound(long value, int offsetRange) {
int offset = ThreadLocalRandom.current().nextInt(-offsetRange, offsetRange + 1);
return (int) Math.round(value + offset + ThreadLocalRandom.current().nextDouble());
}*/
// 偏移运算
public static String shiftString(String str, int num) {
if (str == null || str.isEmpty()) return str;
StringBuilder sb = new StringBuilder();
for (char c : str.toCharArray()) {
// 计算偏移后的字符(自动处理char越界)
sb.append((char) (c + num));
}
return sb.toString();
}
public static void main(String[] args) throws Exception {
/*System.out.println("手机号脱敏: " + invalidatePhone("13812345678", 2, 5));
System.out.println("随机替换: " + randomPhone("阿斯顿发生大法师大法师放大132123fsdasdfasdfasf"));
String str = "asdfadfasdfasdfasdfasdfasdfasdfasdfasddfasdfhdfghfdghd";
str = encryptAES(str, "sx+htIs=6a2t8qt%");
System.out.println(str);
System.out.println(decryptAES(str, "sx+htIs=6a2t8qt%"));
System.out.println(shiftString("asdfjasdfiosdj呼呼收到回复", 12));*/
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", "胡懿");
Long l = 15234609999L;
jsonObject.put("phone", l);
long idCard = 142222199514442333L;
jsonObject.put("idCard", idCard);
System.out.println(jsonObject.toString());
}
}
\ No newline at end of file
package cn.gintone.encryptionUtils;
import java.io.FileWriter;
import java.nio.charset.StandardCharsets;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
// 生成公私钥
public class PemFileGenerator {
// 生成RSA密钥对
public static KeyPair generateRSAKeyPair(int keySize) throws Exception {
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
keyPairGenerator.initialize(keySize);
return keyPairGenerator.generateKeyPair();
}
// 将公钥转换为PEM格式字符串
public static String publicKeyToPem(PublicKey publicKey) {
byte[] encoded = publicKey.getEncoded();
String base64 = Base64.getEncoder().encodeToString(encoded);
return formatPem(base64, "PUBLIC KEY");
}
// 将私钥转换为PEM格式字符串
public static String privateKeyToPem(PrivateKey privateKey) {
byte[] encoded = privateKey.getEncoded();
String base64 = Base64.getEncoder().encodeToString(encoded);
return formatPem(base64, "PRIVATE KEY");
}
// 格式化PEM内容
private static String formatPem(String base64, String keyType) {
StringBuilder pem = new StringBuilder();
pem.append("-----BEGIN ").append(keyType).append("-----\n");
// 每64个字符换行
int lineLength = 64;
for (int i = 0; i < base64.length(); i += lineLength) {
int end = Math.min(i + lineLength, base64.length());
pem.append(base64, i, end).append("\n");
}
pem.append("-----END ").append(keyType).append("-----\n");
return pem.toString();
}
// 完整生成示例
public static Map<String, String> generateAndSaveKeyPair(int keySize) throws Exception {
// 生成密钥对
KeyPair keyPair = generateRSAKeyPair(keySize);
// 转换为PEM格式
String publicPem = publicKeyToPem(keyPair.getPublic());
String privatePem = privateKeyToPem(keyPair.getPrivate());
Map<String, String> keyMap = new HashMap<String, String>();
keyMap.put("publicPem", publicPem);
keyMap.put("privatePem", privatePem);
return keyMap;
}
// 测试用例
public static void main(String[] args) throws Exception {
// 生成2048位的RSA密钥对
generateAndSaveKeyPair(
2048
);
System.out.println("密钥对已生成:");
System.out.println("公钥 -> public_key.pem");
System.out.println("私钥 -> private_key.pem");
}
}
\ No newline at end of file
package cn.gintone.encryptionUtils;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.jce.spec.ECParameterSpec;
import org.bouncycastle.jce.spec.ECPrivateKeySpec;
import org.bouncycastle.jce.spec.ECPublicKeySpec;
import org.bouncycastle.jce.interfaces.ECPrivateKey;
import org.bouncycastle.jce.interfaces.ECPublicKey;
import org.bouncycastle.jce.ECNamedCurveTable;
import org.bouncycastle.math.ec.ECPoint;
import java.security.*;
import java.security.spec.*;
import java.util.Base64;
public class SM2KeyUtils {
static {
Security.addProvider(new BouncyCastleProvider());
}
// 公钥对象转字符串 (Base64)
public static String publicKeyToString(PublicKey publicKey) {
if (publicKey == null) return null;
ECPublicKey ecPublicKey = (ECPublicKey) publicKey;
byte[] keyBytes = ecPublicKey.getQ().getEncoded(true); // 压缩格式
return Base64.getEncoder().encodeToString(keyBytes);
}
// 字符串转公钥对象
public static PublicKey stringToPublicKey(String publicKeyStr) throws Exception {
if (publicKeyStr == null || publicKeyStr.isEmpty()) return null;
byte[] keyBytes = Base64.getDecoder().decode(publicKeyStr);
ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("sm2p256v1");
ECPoint ecPoint = ecSpec.getCurve().decodePoint(keyBytes);
ECPublicKeySpec keySpec = new ECPublicKeySpec(ecPoint, ecSpec);
return KeyFactory.getInstance("EC", "BC").generatePublic(keySpec);
}
// 私钥对象转字符串 (Base64)
public static String privateKeyToString(PrivateKey privateKey) {
if (privateKey == null) return null;
ECPrivateKey ecPrivateKey = (ECPrivateKey) privateKey;
byte[] keyBytes = ecPrivateKey.getD().toByteArray(); // 大整数字节
return Base64.getEncoder().encodeToString(keyBytes);
}
// 字符串转私钥对象
public static PrivateKey stringToPrivateKey(String privateKeyStr) throws Exception {
if (privateKeyStr == null || privateKeyStr.isEmpty()) return null;
byte[] keyBytes = Base64.getDecoder().decode(privateKeyStr);
ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("sm2p256v1");
ECPrivateKeySpec keySpec = new ECPrivateKeySpec(new java.math.BigInteger(1, keyBytes), ecSpec);
return KeyFactory.getInstance("EC", "BC").generatePrivate(keySpec);
}
}
package cn.gintone.encryptionUtils;
import org.bouncycastle.jcajce.provider.asymmetric.util.ECUtil;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.jce.spec.ECParameterSpec;
import org.bouncycastle.jce.spec.ECPrivateKeySpec;
import org.bouncycastle.jce.spec.ECPublicKeySpec;
import org.bouncycastle.crypto.engines.SM2Engine;
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
import org.bouncycastle.crypto.params.ParametersWithRandom;
import org.bouncycastle.jce.ECNamedCurveTable;
import org.bouncycastle.math.ec.ECPoint;
import java.security.*;
import java.util.Base64;
public class SM2Util {
static {
Security.addProvider(new BouncyCastleProvider());
}
// SM2加密方法
public static byte[] sm2Encrypt(byte[] data, PublicKey publicKey) throws Exception {
SM2Engine engine = new SM2Engine(SM2Engine.Mode.C1C3C2);
ECPublicKeyParameters ecPublicKey = (ECPublicKeyParameters) ECUtil.generatePublicKeyParameter(publicKey);
engine.init(true, new ParametersWithRandom(ecPublicKey, new SecureRandom()));
return engine.processBlock(data, 0, data.length);
}
// SM2解密方法
public static byte[] sm2Decrypt(byte[] cipherText, PrivateKey privateKey) throws Exception {
SM2Engine engine = new SM2Engine(SM2Engine.Mode.C1C3C2);
ECPrivateKeyParameters ecPrivateKey = (ECPrivateKeyParameters) ECUtil.generatePrivateKeyParameter(privateKey);
engine.init(false, ecPrivateKey);
return engine.processBlock(cipherText, 0, cipherText.length);
}
// 生成SM2密钥对
public static KeyPair generateSm2KeyPair() throws Exception {
ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("sm2p256v1");
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("EC", "BC");
keyPairGenerator.initialize(ecSpec, new SecureRandom());
return keyPairGenerator.generateKeyPair();
}
// 将公钥转换为字节数组
public static byte[] publicKeyToBytes(PublicKey publicKey) {
return ((org.bouncycastle.jce.interfaces.ECPublicKey) publicKey).getQ().getEncoded(true);
}
// 将字节数组转换为公钥
public static PublicKey bytesToPublicKey(byte[] keyBytes) throws Exception {
ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("sm2p256v1");
ECPoint ecPoint = ecSpec.getCurve().decodePoint(keyBytes);
ECPublicKeySpec keySpec = new ECPublicKeySpec(ecPoint, ecSpec);
return KeyFactory.getInstance("EC", "BC").generatePublic(keySpec);
}
// 将私钥转换为字节数组
public static byte[] privateKeyToBytes(PrivateKey privateKey) {
return ((org.bouncycastle.jce.interfaces.ECPrivateKey) privateKey).getD().toByteArray();
}
// 将字节数组转换为私钥
public static PrivateKey bytesToPrivateKey(byte[] keyBytes) throws Exception {
ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("sm2p256v1");
ECPrivateKeySpec keySpec = new ECPrivateKeySpec(new java.math.BigInteger(1, keyBytes), ecSpec);
return KeyFactory.getInstance("EC", "BC").generatePrivate(keySpec);
}
public static void main(String[] args) throws Exception {
// 生成密钥对
KeyPair keyPair = generateSm2KeyPair();
PublicKey publicKey = keyPair.getPublic();
PrivateKey privateKey = keyPair.getPrivate();
String pubStr = SM2KeyUtils.publicKeyToString(publicKey);
String priStr = SM2KeyUtils.privateKeyToString(privateKey);
PublicKey publicKey1 = SM2KeyUtils.stringToPublicKey(pubStr);
PrivateKey privateKey1 = SM2KeyUtils.stringToPrivateKey(priStr);
// 测试数据
String originalText = "Hello, SM2加密测试!";
for (int i = 0; i < 1000; i ++) {
originalText += "加密测试加密测试加密测试加密测试加密测试加密测试sadfasdfasdfaf";
}
byte[] data = originalText.getBytes("UTF-8");
// 加密
byte[] encryptedData = sm2Encrypt(data, publicKey1);
System.out.println("加密结果 (Base64): " + Base64.getEncoder().encodeToString(encryptedData));
// 解密
byte[] decryptedData = sm2Decrypt(encryptedData, privateKey1);
String decryptedText = new String(decryptedData, "UTF-8");
System.out.println("解密结果: " + decryptedText);
}
}
package cn.gintone.encryptionUtils;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;
import java.util.Map;
public class SecureHybridDecryptor {
private static final int GCM_TAG_LENGTH = 128;
public static String decrypt(String encryptedData, PrivateKey privateKey) throws Exception {
String[] parts = encryptedData.split(":", 3);
String encryptedAESKey = parts[0];
String ivBase64 = parts[1];
String encryptedText = parts[2];
// 1. 解密AES密钥
SecretKey aesKey = decryptAESKey(encryptedAESKey, privateKey);
// 2. 解密数据
return decryptWithAES(encryptedText, aesKey, ivBase64);
}
public static Object decrypt_Object(String encryptedData, PrivateKey privateKey) throws Exception {
String[] parts = encryptedData.split(":", 3);
String encryptedAESKey = parts[0];
String ivBase64 = parts[1];
String encryptedText = parts[2];
// 1. 解密AES密钥
SecretKey aesKey = decryptAESKey(encryptedAESKey, privateKey);
// 2. 解密数据
return decryptWithAES_object(encryptedText, aesKey, ivBase64);
}
private static SecretKey decryptAESKey(String encryptedKey, PrivateKey privateKey) throws Exception {
byte[] keyBytes = Base64.getDecoder().decode(encryptedKey);
Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding");
cipher.init(Cipher.DECRYPT_MODE, privateKey);
byte[] decryptedKey = cipher.doFinal(keyBytes);
return new SecretKeySpec(decryptedKey, "AES");
}
private static String decryptWithAES(String encryptedData, SecretKey aesKey, String ivBase64) throws Exception {
byte[] iv = Base64.getDecoder().decode(ivBase64);
byte[] data = Base64.getDecoder().decode(encryptedData);
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
GCMParameterSpec spec = new GCMParameterSpec(128, iv);
cipher.init(Cipher.DECRYPT_MODE, aesKey, spec);
byte[] decrypted = cipher.doFinal(data);
return new String(decrypted, StandardCharsets.UTF_8);
}
private static Object decryptWithAES_object(String encryptedDataBase64, SecretKey aesKey, String ivBase64) throws Exception {
// 解码Base64编码的加密数据和IV
byte[] encryptedData = Base64.getDecoder().decode(encryptedDataBase64);
byte[] iv = Base64.getDecoder().decode(ivBase64);
// 使用AES/GCM/NoPadding进行解密
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
GCMParameterSpec spec = new GCMParameterSpec(GCM_TAG_LENGTH, iv);
cipher.init(Cipher.DECRYPT_MODE, aesKey, spec);
byte[] decrypted = cipher.doFinal(encryptedData);
// 将解密后的字节数组反序列化为对象
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(decrypted);
ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
Object obj = objectInputStream.readObject();
objectInputStream.close();
return obj;
}
// 解密
public static PrivateKey loadPrivateKey(String privateKey) throws Exception {
privateKey = privateKey.replace("-----BEGIN PRIVATE KEY-----", "")
.replace("-----END PRIVATE KEY-----", "")
.replaceAll("\\s", "");
byte[] keyBytes = Base64.getDecoder().decode(privateKey);
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory kf = KeyFactory.getInstance("RSA");
return kf.generatePrivate(spec);
}
// 公钥加密
public static PublicKey loadPublicKey(String publicKey) throws Exception {
publicKey = publicKey.replace("-----BEGIN PUBLIC KEY-----", "")
.replace("-----END PUBLIC KEY-----", "")
.replaceAll("\\s", ""); // 清理PEM格式
byte[] keyBytes = Base64.getDecoder().decode(publicKey);
X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
KeyFactory kf = KeyFactory.getInstance("RSA");
return kf.generatePublic(spec);
}
public static void main(String[] args) throws Exception {
String original = "这是一个需要加密的长文本数据,可以超过任意长度限制。";
for (int i = 0; i < 1000; i ++) {
original += "这是一个需要加密的长文本数据,可以超过任意长度限制。";
}
Map<String, String> keyMap = PemFileGenerator.generateAndSaveKeyPair(1024);
PublicKey publicKey = loadPublicKey(keyMap.get("publicPem"));
// 加密
String encrypted = SecureHybridEncryptor.encrypt_object(original, publicKey);
System.out.println("加密结果:" + encrypted.substring(0, 100) + "...");
PrivateKey privateKey = loadPrivateKey(keyMap.get("privatePem"));
// 解密
Object decrypted = SecureHybridDecryptor.decrypt_Object(encrypted, privateKey);
System.out.println("解密结果验证:" + decrypted);
}
}
package cn.gintone.encryptionUtils;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.GCMParameterSpec;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.nio.charset.StandardCharsets;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.util.Base64;
public class SecureHybridEncryptor {
private static final int AES_KEY_SIZE = 128;
private static final int GCM_TAG_LENGTH = 128;
private static final int GCM_IV_LENGTH = 12; // bytes
// 主加密方法
public static String encrypt(String plaintext, PublicKey publicKey) throws Exception {
// 1. 生成随机AES密钥
SecretKey aesKey = generateAESKey();
// 2. 使用AES加密原始数据
byte[] iv = generateSecureIV();
String[] aesResult = encryptWithAES(plaintext, aesKey, iv);
String encryptedData = aesResult[0];
String ivBase64 = aesResult[1];
// 3. 使用RSA加密AES密钥
String encryptedAESKey = encryptAESKey(aesKey, publicKey);
// 4. 组合加密结果
return formatFinalResult(encryptedAESKey, ivBase64, encryptedData);
}
public static String encrypt_object(Object obj, PublicKey publicKey) throws Exception {
// 1. 生成随机AES密钥
SecretKey aesKey = generateAESKey();
// 2. 使用AES加密原始数据
byte[] iv = generateSecureIV();
String[] aesResult = encryptWithAES_object(obj, aesKey, iv);
String encryptedData = aesResult[0];
String ivBase64 = aesResult[1];
// 3. 使用RSA加密AES密钥
String encryptedAESKey = encryptAESKey(aesKey, publicKey);
// 4. 组合加密结果
return formatFinalResult(encryptedAESKey, ivBase64, encryptedData);
}
private static SecretKey generateAESKey() throws Exception {
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
keyGen.init(AES_KEY_SIZE);
return keyGen.generateKey();
}
private static byte[] generateSecureIV() {
byte[] iv = new byte[GCM_IV_LENGTH];
new SecureRandom().nextBytes(iv);
return iv;
}
private static String[] encryptWithAES(String plaintext, SecretKey aesKey, byte[] iv) throws Exception {
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
GCMParameterSpec spec = new GCMParameterSpec(GCM_TAG_LENGTH, iv);
cipher.init(Cipher.ENCRYPT_MODE, aesKey, spec);
byte[] encrypted = cipher.doFinal(plaintext.getBytes(StandardCharsets.UTF_8));
return new String[] {
Base64.getEncoder().encodeToString(encrypted),
Base64.getEncoder().encodeToString(iv)
};
}
private static String[] encryptWithAES_object(Object obj, SecretKey aesKey, byte[] iv) throws Exception {
// 将对象序列化为字节数组
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(obj);
objectOutputStream.flush();
byte[] serializedObject = byteArrayOutputStream.toByteArray();
objectOutputStream.close();
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
GCMParameterSpec spec = new GCMParameterSpec(GCM_TAG_LENGTH, iv);
cipher.init(Cipher.ENCRYPT_MODE, aesKey, spec);
byte[] encrypted = cipher.doFinal(serializedObject);
return new String[] {
Base64.getEncoder().encodeToString(encrypted),
Base64.getEncoder().encodeToString(iv)
};
}
private static String encryptAESKey(SecretKey aesKey, PublicKey publicKey) throws Exception {
Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding");
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
byte[] encryptedKey = cipher.doFinal(aesKey.getEncoded());
return Base64.getEncoder().encodeToString(encryptedKey);
}
private static String formatFinalResult(String encryptedKey, String iv, String data) {
return encryptedKey + ":" + iv + ":" + data;
}
}
\ No newline at end of file
package cn.gintone.entity;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 公钥私钥管理 DO
*
* @author 胡懿
*/
@TableName("t_key_code")
@KeySequence("t_key_code_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class KeyCodeDO extends BaseDO {
/**
* id
*/
@TableId
private Long id;
/**
* 类型用户编号 1:rsa 2:sm2
*/
private Integer type;
/**
* 公钥用户类型
*/
private String publicKey;
/**
* 私钥
*/
private String privateKey;
}
\ No newline at end of file
package cn.gintone.entity;
import lombok.*;
import java.util.*;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 我的测试表 DO
*
* @author 胡懿
*/
@TableName("t_my_table")
@KeySequence("t_my_table_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MyTableDO extends BaseDO {
/**
* id
*/
@TableId
private Long id;
/**
* name
*/
private String name;
/**
* age
*/
private Integer age;
/**
* money
*/
private BigDecimal money;
}
\ No newline at end of file
package cn.gintone.entity;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 人员脱敏规则 DO
*
* @author 胡懿
*/
@TableName("t_user_des_rule")
@KeySequence("t_user_des_rule_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UserDesRuleDO extends BaseDO {
/**
* id
*/
@TableId
private Long id;
/**
* 属性名称
*/
private String name;
/**
* 属性描述
*/
private String attr;
/**
* 规则
*/
private Integer rule;
/**
* 配置项1
*/
private String valueOne;
/**
* 配置项2
*/
private String valueTwo;
/**
* 配置项3
*/
private String valueThree;
}
\ No newline at end of file
package cn.gintone.entity;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 接口安全访问策略 DO
*
* @author 胡懿
*/
@TableName("t_visit")
@KeySequence("t_visit_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class VisitDO extends BaseDO {
/**
* id
*/
@TableId
private Long id;
/**
* 规则名称
*/
private String name;
}
\ No newline at end of file
package cn.gintone.entity;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 访问规则配置 DO
*
* @author 胡懿
*/
@TableName("t_visit_info")
@KeySequence("t_visit_info_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class VisitInfoDO extends BaseDO {
/**
* id
*/
@TableId
private Long id;
/**
* 规则表外键
*/
private Long visitId;
/**
* 系统简称
*/
private String sysAbbre;
/**
* 系统名称
*/
private String sysAbbreName;
/**
* 菜单名称
*/
private String urlName;
/**
* 菜单地址
*/
private String url;
/**
* 菜单地址Id
*/
private String urlId;
/**
* 角色id
*/
private String roleId;
/**
* 角色名称
*/
private String roleName;
/**
* 用户id
*/
private String userId;
/**
* 用户名称
*/
private String userName;
}
\ No newline at end of file
package cn.gintone.iotdbUtils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class MyDateUtils {
public static long stringToLong(String timeStr){
try {
boolean hasMillis = timeStr.contains(".");
String pattern = hasMillis ? "yyyy-MM-dd HH:mm:ss.SSS" : "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
Date date = sdf.parse(timeStr);
return date.getTime();
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
public static String longToString(long timestamp) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Date date = new Date(timestamp);
return sdf.format(date);
}
}
package cn.gintone.service;
import cn.gintone.controller.vo.KeyCodePageReqVO;
import cn.gintone.controller.vo.KeyCodeSaveReqVO;
import cn.gintone.dto.EncInfo;
import cn.gintone.entity.KeyCodeDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import javax.validation.*;
/**
* 公钥私钥管理 Service 接口
*
* @author 胡懿
*/
public interface KeyCodeService {
/**
* 创建公钥私钥管理
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createKeyCode(@Valid KeyCodeSaveReqVO createReqVO);
/**
* 更新公钥私钥管理
*
* @param updateReqVO 更新信息
*/
void updateKeyCode(@Valid KeyCodeSaveReqVO updateReqVO);
/**
* 删除公钥私钥管理
*
* @param id 编号
*/
void deleteKeyCode(Long id);
/**
* 获得公钥私钥管理
*
* @param id 编号
* @return 公钥私钥管理
*/
KeyCodeDO getKeyCode(Long id);
/**
* 获得公钥私钥管理分页
*
* @param pageReqVO 分页查询
* @return 公钥私钥管理分页
*/
PageResult<KeyCodeDO> getKeyCodePage(KeyCodePageReqVO pageReqVO);
/**
* 初始化公钥私钥
* @return
*/
String initKey();
/**
* 使用ras加密
* @param info
* @return
*/
EncInfo rasEncryption(String info);
String rasDecrypt(EncInfo encInfo);
}
\ No newline at end of file
package cn.gintone.service;
import cn.gintone.ErrorInfo;
import cn.gintone.controller.vo.KeyCodePageReqVO;
import cn.gintone.controller.vo.KeyCodeSaveReqVO;
import cn.gintone.dal.KeyCodeMapper;
import cn.gintone.dto.EncInfo;
import cn.gintone.encryptionUtils.*;
import cn.gintone.entity.KeyCodeDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
/**
* 公钥私钥管理 Service 实现类
*
* @author 胡懿
*/
@Service
@Validated
public class KeyCodeServiceImpl implements KeyCodeService {
@Resource
private KeyCodeMapper keyCodeMapper;
@Override
public Long createKeyCode(KeyCodeSaveReqVO createReqVO) {
// 插入
KeyCodeDO keyCode = BeanUtils.toBean(createReqVO, KeyCodeDO.class);
keyCodeMapper.insert(keyCode);
// 返回
return keyCode.getId();
}
@Override
public void updateKeyCode(KeyCodeSaveReqVO updateReqVO) {
// 校验存在
validateKeyCodeExists(updateReqVO.getId());
// 更新
KeyCodeDO updateObj = BeanUtils.toBean(updateReqVO, KeyCodeDO.class);
keyCodeMapper.updateById(updateObj);
}
@Override
public void deleteKeyCode(Long id) {
// 校验存在
validateKeyCodeExists(id);
// 删除
keyCodeMapper.deleteById(id);
}
private void validateKeyCodeExists(Long id) {
if (keyCodeMapper.selectById(id) == null) {
throw exception(ErrorInfo.KEY_CODE_NOT_EXISTS);
}
}
@Override
public KeyCodeDO getKeyCode(Long id) {
return keyCodeMapper.selectById(id);
}
@Override
public PageResult<KeyCodeDO> getKeyCodePage(KeyCodePageReqVO pageReqVO) {
return keyCodeMapper.selectPage(pageReqVO);
}
@Override
public String initKey() {
List<KeyCodeDO> keyCodeDOS = keyCodeMapper.selectList(new QueryWrapper<KeyCodeDO>());
System.out.println("keyCodeDOS:" + keyCodeDOS.size());
if (null != keyCodeDOS && keyCodeDOS.size() > 0) {
for (KeyCodeDO keyCodeDO : keyCodeDOS){
keyCodeMapper.deleteById(keyCodeDO.getId());
}
}
try {
KeyCodeDO keyCodeDO_rsa = new KeyCodeDO();
Map<String, String> keyMap = PemFileGenerator.generateAndSaveKeyPair(1024);
String pubKey_rsa = keyMap.get("publicPem");
String priKey_rsa = keyMap.get("privatePem");
keyCodeDO_rsa.setType(1);
keyCodeDO_rsa.setPublicKey(pubKey_rsa);
keyCodeDO_rsa.setPrivateKey(priKey_rsa);
int insert = keyCodeMapper.insert(keyCodeDO_rsa);
KeyCodeDO keyCodeDo_sm2 = new KeyCodeDO();
KeyPair keyPair = SM2Util.generateSm2KeyPair();
PublicKey publicKey = keyPair.getPublic();
PrivateKey privateKey = keyPair.getPrivate();
String pubStr_sm2 = SM2KeyUtils.publicKeyToString(publicKey);
String priStr_sm2 = SM2KeyUtils.privateKeyToString(privateKey);
keyCodeDo_sm2.setType(2);
keyCodeDo_sm2.setPublicKey(pubStr_sm2);
keyCodeDo_sm2.setPrivateKey(priStr_sm2);
keyCodeMapper.insert(keyCodeDo_sm2);
} catch (Exception e) {
throw new RuntimeException(e);
}
return "初始化成功";
}
@Override
public EncInfo rasEncryption(String info) {
EncInfo encInfo = new EncInfo();
KeyCodeDO keyCodeDO = keyCodeMapper.selectOne(new QueryWrapper<KeyCodeDO>().eq("type", 1));
if (null != keyCodeDO) {
try {
encInfo.setPrivateKey(keyCodeDO.getPrivateKey());
PublicKey publicKey = SecureHybridDecryptor.loadPublicKey(keyCodeDO.getPublicKey());
String encrypt = SecureHybridEncryptor.encrypt(info, publicKey);
encInfo.setInfo(encrypt);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return encInfo;
}
@Override
public String rasDecrypt(EncInfo encInfo) {
try {
PrivateKey privateKey = SecureHybridDecryptor.loadPrivateKey(encInfo.getPrivateKey());
// 解密
String decrypted = SecureHybridDecryptor.decrypt(encInfo.getInfo(), privateKey);
return decrypted;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
\ No newline at end of file
package cn.gintone.service;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthPermissionInfoRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO;
import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import org.springframework.stereotype.Service;
import java.util.List;
public interface MySystemService {
/**
* 获取菜单树
* @param sysAbbre
* @return
*/
public List<AuthPermissionInfoRespVO.MenuVO> getMenuBySysAbbre(String sysAbbre);
public List<RoleDO> getRolesBySysAbbre(String sysAbbre);
public List<AdminUserDO> getAdminUsersBySysAbbreAndRoleId(String sysAbbre, String roleId);
}
package cn.gintone.service;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthPermissionInfoRespVO;
import cn.iocoder.yudao.module.system.convert.auth.AuthConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO;
import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
import cn.iocoder.yudao.module.system.dal.dataobject.permission.UserRoleDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.dal.mysql.permission.UserRoleMapper;
import cn.iocoder.yudao.module.system.enums.permission.MenuTypeEnum;
import cn.iocoder.yudao.module.system.service.permission.MenuService;
import cn.iocoder.yudao.module.system.service.permission.RoleService;
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
import static cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO.ID_ROOT;
@Service
public class MySystemServiceImpl implements MySystemService {
@Autowired
private MenuService menuService;
@Autowired
private RoleService roleService;
@Autowired
private AdminUserService adminUserService;
@Autowired
private UserRoleMapper userRoleMapper;
@Override
public List<AuthPermissionInfoRespVO.MenuVO> getMenuBySysAbbre(String sysAbbre) {
if ("secure".equals(sysAbbre)) {
Set<Long> menuIds = convertSet(menuService.getMenuList(), MenuDO::getId);
List<MenuDO> menuList = menuService.getMenuList(menuIds);
menuList = menuService.filterDisableMenus(menuList);
List<AuthPermissionInfoRespVO.MenuVO> menuVOS = buildMenuTree(menuList);
return menuVOS;
} else {
return CollUtil.newArrayList();
}
}
@Override
public List<RoleDO> getRolesBySysAbbre(String sysAbbre) {
if ("secure".equals(sysAbbre)) {
return roleService.getRoleList();
} else {
return CollUtil.newArrayList();
}
}
@Override
public List<AdminUserDO> getAdminUsersBySysAbbreAndRoleId(String sysAbbre, String roleId) {
List<AdminUserDO> adminUserDOList = new ArrayList<>();
if ("secure".equals(sysAbbre)) {
List<Long> roleIds = new ArrayList<>();
roleIds.add(Long.valueOf(roleId));
List<UserRoleDO> userRoleDOS = userRoleMapper.selectListByRoleIds(roleIds);
if (null != userRoleDOS && userRoleDOS.size() > 0) {
for (UserRoleDO userRoleDO : userRoleDOS) {
Long userId = userRoleDO.getUserId();
AdminUserDO user = adminUserService.getUser(userId);
adminUserDOList.add(user);
}
}
return adminUserDOList;
}
return Collections.emptyList();
}
public List<AuthPermissionInfoRespVO.MenuVO> buildMenuTree(List<MenuDO> menuList) {
if (CollUtil.isEmpty(menuList)) {
return Collections.emptyList();
}
// 移除按钮
menuList.removeIf(menu -> menu.getType().equals(MenuTypeEnum.BUTTON.getType()));
// 排序,保证菜单的有序性
menuList.sort(Comparator.comparing(MenuDO::getSort));
// 构建菜单树
// 使用 LinkedHashMap 的原因,是为了排序 。实际也可以用 Stream API ,就是太丑了。
Map<Long, AuthPermissionInfoRespVO.MenuVO> treeNodeMap = new LinkedHashMap<>();
menuList.forEach(menu -> treeNodeMap.put(menu.getId(), AuthConvert.INSTANCE.convertTreeNode(menu)));
// 处理父子关系
treeNodeMap.values().stream().filter(node -> !node.getParentId().equals(ID_ROOT)).forEach(childNode -> {
// 获得父节点
AuthPermissionInfoRespVO.MenuVO parentNode = treeNodeMap.get(childNode.getParentId());
if (parentNode == null) {
LoggerFactory.getLogger(getClass()).error("[buildRouterTree][resource({}) 找不到父资源({})]",
childNode.getId(), childNode.getParentId());
return;
}
// 将自己添加到父节点中
if (parentNode.getChildren() == null) {
parentNode.setChildren(new ArrayList<>());
}
parentNode.getChildren().add(childNode);
});
// 获得到所有的根节点
return filterList(treeNodeMap.values(), node -> ID_ROOT.equals(node.getParentId()));
}
}
package cn.gintone.service;
import cn.gintone.controller.vo.MyTablePageReqVO;
import cn.gintone.controller.vo.MyTableSaveReqVO;
import cn.gintone.entity.MyTableDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import java.util.*;
import javax.validation.*;
/**
* 我的测试表 Service 接口
*
* @author 胡懿
*/
public interface MyTableService {
/**
* 创建我的测试表
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createMyTable(@Valid MyTableSaveReqVO createReqVO);
/**
* 更新我的测试表
*
* @param updateReqVO 更新信息
*/
void updateMyTable(@Valid MyTableSaveReqVO updateReqVO);
/**
* 删除我的测试表
*
* @param id 编号
*/
void deleteMyTable(Long id);
/**
* 获得我的测试表
*
* @param id 编号
* @return 我的测试表
*/
MyTableDO getMyTable(Long id);
/**
* 获得我的测试表分页
*
* @param pageReqVO 分页查询
* @return 我的测试表分页
*/
PageResult<MyTableDO> getMyTablePage(MyTablePageReqVO pageReqVO);
}
\ No newline at end of file
package cn.gintone.service;
import cn.gintone.ErrorInfo;
import cn.gintone.controller.vo.MyTablePageReqVO;
import cn.gintone.controller.vo.MyTableSaveReqVO;
import cn.gintone.dal.MyTableMapper;
import cn.gintone.entity.MyTableDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
/**
* 我的测试表 Service 实现类
*
* @author 胡懿
*/
@Service
@Validated
public class MyTableServiceImpl implements MyTableService {
@Resource
private MyTableMapper myTableMapper;
@Override
public Long createMyTable(MyTableSaveReqVO createReqVO) {
// 插入
MyTableDO myTable = BeanUtils.toBean(createReqVO, MyTableDO.class);
myTableMapper.insert(myTable);
// 返回
return myTable.getId();
}
@Override
public void updateMyTable(MyTableSaveReqVO updateReqVO) {
// 校验存在
validateMyTableExists(updateReqVO.getId());
// 更新
MyTableDO updateObj = BeanUtils.toBean(updateReqVO, MyTableDO.class);
myTableMapper.updateById(updateObj);
}
@Override
public void deleteMyTable(Long id) {
// 校验存在
validateMyTableExists(id);
// 删除
myTableMapper.deleteById(id);
}
private void validateMyTableExists(Long id) {
if (myTableMapper.selectById(id) == null) {
throw exception(ErrorInfo.MY_TABLE_NOT_EXISTS);
}
}
@Override
public MyTableDO getMyTable(Long id) {
return myTableMapper.selectById(id);
}
@Override
public PageResult<MyTableDO> getMyTablePage(MyTablePageReqVO pageReqVO) {
return myTableMapper.selectPage(pageReqVO);
}
}
\ No newline at end of file
package cn.gintone.service;
import cn.gintone.controller.vo.UserDesRulePageReqVO;
import cn.gintone.controller.vo.UserDesRuleSaveReqVO;
import cn.gintone.entity.UserDesRuleDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import javax.validation.*;
import java.util.List;
import java.util.Map;
/**
* 人员脱敏规则 Service 接口
*
* @author 胡懿
*/
public interface UserDesRuleService {
/**
* 创建人员脱敏规则
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createUserDesRule(@Valid UserDesRuleSaveReqVO createReqVO);
/**
* 更新人员脱敏规则
*
* @param updateReqVO 更新信息
*/
void updateUserDesRule(@Valid UserDesRuleSaveReqVO updateReqVO);
/**
* 删除人员脱敏规则
*
* @param id 编号
*/
void deleteUserDesRule(Long id);
/**
* 获得人员脱敏规则
*
* @param id 编号
* @return 人员脱敏规则
*/
UserDesRuleDO getUserDesRule(Long id);
/**
* 获得人员脱敏规则分页
*
* @param pageReqVO 分页查询
* @return 人员脱敏规则分页
*/
PageResult<UserDesRuleDO> getUserDesRulePage(UserDesRulePageReqVO pageReqVO);
String userRuleDes(String userJsonStr);
String userRuleDesArr(String userJsonArrStr);
Boolean checkName(String name, Long id);
Map<String, Object> userRuleDesMap(Map<String, Object> map);
List<Map<String, Object>> userRuleDesListMap(List<Map<String, Object>> lisetMap);
}
\ No newline at end of file
package cn.gintone.service;
import cn.gintone.controller.vo.VisitInfoPageReqVO;
import cn.gintone.controller.vo.VisitInfoRespVO;
import cn.gintone.controller.vo.VisitInfoSaveReqVO;
import cn.gintone.dto.WebLogInfo;
import cn.gintone.entity.VisitInfoDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import javax.validation.*;
import java.util.List;
/**
* 访问规则配置 Service 接口
*
* @author 胡懿
*/
public interface VisitInfoService {
/**
* 创建访问规则配置
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createVisitInfo(@Valid VisitInfoSaveReqVO createReqVO);
/**
* 更新访问规则配置
*
* @param updateReqVO 更新信息
*/
void updateVisitInfo(@Valid VisitInfoSaveReqVO updateReqVO);
/**
* 删除访问规则配置
*
* @param id 编号
*/
void deleteVisitInfo(Long id);
/**
* 获得访问规则配置
*
* @param id 编号
* @return 访问规则配置
*/
VisitInfoDO getVisitInfo(Long id);
/**
* 获得访问规则配置分页
*
* @param pageReqVO 分页查询
* @return 访问规则配置分页
*/
PageResult<VisitInfoDO> getVisitInfoPage(VisitInfoPageReqVO pageReqVO);
List<VisitInfoDO> getList(VisitInfoPageReqVO reqVo);
Boolean saveAllVisitInfo(List<VisitInfoSaveReqVO> visitInfoSaveReqVOList);
void deleteByVisitId(Long visitId);
boolean updateAllVisitInfo(List<VisitInfoSaveReqVO> visitInfoSaveReqVOList);
void checkWebLogInfo(WebLogInfo webLogInfo);
}
\ No newline at end of file
package cn.gintone.service;
import cn.gintone.ErrorInfo;
import cn.gintone.config.IotDbConfig;
import cn.gintone.controller.vo.VisitInfoPageReqVO;
import cn.gintone.controller.vo.VisitInfoRespVO;
import cn.gintone.controller.vo.VisitInfoSaveReqVO;
import cn.gintone.dal.VisitInfoMapper;
import cn.gintone.dto.WebIllLogInfo;
import cn.gintone.dto.WebLogInfo;
import cn.gintone.entity.VisitInfoDO;
import cn.gintone.iotdbUtils.MyIotDbUtils;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.dal.dataobject.permission.UserRoleDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.dal.mysql.permission.RoleMapper;
import cn.iocoder.yudao.module.system.dal.mysql.permission.UserRoleMapper;
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import java.util.ArrayList;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
/**
* 访问规则配置 Service 实现类
*
* @author 胡懿
*/
@Service
@Validated
public class VisitInfoServiceImpl implements VisitInfoService {
@Resource
private VisitInfoMapper visitInfoMapper;
@Autowired
private IotDbConfig iotDbConfig;
@Autowired
private AdminUserService adminUserService;
@Autowired
private UserRoleMapper userRoleMapper;
@Autowired
private RoleMapper roleMapper;
@Override
public Long createVisitInfo(VisitInfoSaveReqVO createReqVO) {
// 插入
VisitInfoDO visitInfo = BeanUtils.toBean(createReqVO, VisitInfoDO.class);
visitInfoMapper.insert(visitInfo);
// 返回
return visitInfo.getId();
}
@Override
public void updateVisitInfo(VisitInfoSaveReqVO updateReqVO) {
// 校验存在
validateVisitInfoExists(updateReqVO.getId());
// 更新
VisitInfoDO updateObj = BeanUtils.toBean(updateReqVO, VisitInfoDO.class);
visitInfoMapper.updateById(updateObj);
}
@Override
public void deleteVisitInfo(Long id) {
// 校验存在
validateVisitInfoExists(id);
// 删除
visitInfoMapper.deleteById(id);
}
private void validateVisitInfoExists(Long id) {
if (visitInfoMapper.selectById(id) == null) {
throw exception(ErrorInfo.VISIT_INFO_NOT_EXISTS);
}
}
@Override
public VisitInfoDO getVisitInfo(Long id) {
return visitInfoMapper.selectById(id);
}
@Override
public PageResult<VisitInfoDO> getVisitInfoPage(VisitInfoPageReqVO pageReqVO) {
return visitInfoMapper.selectPage(pageReqVO);
}
public List<VisitInfoDO> getList(VisitInfoPageReqVO reqVo) {
return visitInfoMapper.selectList(reqVo);
}
@Override
public Boolean saveAllVisitInfo(List<VisitInfoSaveReqVO> visitInfoSaveReqVOList) {
if (visitInfoSaveReqVOList != null && !visitInfoSaveReqVOList.isEmpty()) {
List<VisitInfoDO> visitInfoDOList = new ArrayList<>();
for (VisitInfoSaveReqVO visitInfoSaveReqVO : visitInfoSaveReqVOList) {
VisitInfoDO visitInfo = BeanUtils.toBean(visitInfoSaveReqVO, VisitInfoDO.class);
visitInfoDOList.add(visitInfo);
}
return visitInfoMapper.insertBatch(visitInfoDOList);
}
return false;
}
@Override
public void deleteByVisitId(Long visitId) {
visitInfoMapper.delete(new QueryWrapper<VisitInfoDO>().lambda().eq(VisitInfoDO::getVisitId, visitId));
}
@Override
public boolean updateAllVisitInfo(List<VisitInfoSaveReqVO> visitInfoSaveReqVOList) {
if (visitInfoSaveReqVOList != null && !visitInfoSaveReqVOList.isEmpty()) {
VisitInfoSaveReqVO visitInfoSaveReqVO1 = visitInfoSaveReqVOList.get(0);
visitInfoMapper.delete(new QueryWrapper<VisitInfoDO>().lambda().eq(VisitInfoDO::getVisitId, visitInfoSaveReqVO1.getVisitId()));
List<VisitInfoDO> visitInfoDOList = new ArrayList<>();
for (VisitInfoSaveReqVO visitInfoSaveReqVO : visitInfoSaveReqVOList) {
VisitInfoDO visitInfo = BeanUtils.toBean(visitInfoSaveReqVO, VisitInfoDO.class);
visitInfoDOList.add(visitInfo);
}
return visitInfoMapper.insertBatch(visitInfoDOList);
}
return false;
}
@Override
public void checkWebLogInfo(WebLogInfo webLogInfo) {
String userId = webLogInfo.getUserId();
if (null == userId || "".equals(userId)) {
WebIllLogInfo webIllLogInfo = new WebIllLogInfo();
webIllLogInfo.setUserId(webLogInfo.getUserId());
webIllLogInfo.setUserId(webLogInfo.getUsername());
webIllLogInfo.setSysAbbre(webLogInfo.getSysAbbre());
webIllLogInfo.setUrl(webLogInfo.getUrl());
webIllLogInfo.setAccessed(webLogInfo.getAccessed());
webIllLogInfo.setType(webLogInfo.getType());
webIllLogInfo.setClientIp(webLogInfo.getClientIp());
webIllLogInfo.setRemark(webLogInfo.getRemark());
webIllLogInfo.setIllType("noRule");
MyIotDbUtils.inserOne_Ill(iotDbConfig, webIllLogInfo);
return;
}
// 获取用户信息和角色信息------需要调用平台的接口
List<UserRoleDO> userRoleDOS = userRoleMapper.selectListByUserId(Long.parseLong(userId));
boolean isLegal = false; // 是否合法。false:不合法,true:合法
// 先查询角色规则
if (null != userRoleDOS && !userRoleDOS.isEmpty()) {
for (UserRoleDO userRoleDO : userRoleDOS) {
List<VisitInfoDO> visitInfoDOS = visitInfoMapper.selectList(new LambdaQueryWrapper<VisitInfoDO>()
.eq(VisitInfoDO::getRoleId, userRoleDO.getRoleId())
.like(VisitInfoDO::getUrl, webLogInfo.getUrl())
);
if (null != visitInfoDOS && visitInfoDOS.size() > 0) {
isLegal = true;
}
}
}
// 查询用户规则,如果配置了用户规则,则按照用户规则走
List<VisitInfoDO> visitInfoDOS = visitInfoMapper.selectList(new LambdaQueryWrapper<VisitInfoDO>()
.like(VisitInfoDO::getUrl, webLogInfo.getUrl())
);
if (null != visitInfoDOS && visitInfoDOS.size() > 0) {
isLegal = false;
List<VisitInfoDO> visitInfoDOS2 = visitInfoMapper.selectList(new LambdaQueryWrapper<VisitInfoDO>()
.eq(VisitInfoDO::getUserId, userId)
.like(VisitInfoDO::getUrl, webLogInfo.getUrl())
);
if (null != visitInfoDOS2 && visitInfoDOS2.size() > 0) {
isLegal = true;
}
}
if (!isLegal) {
WebIllLogInfo webIllLogInfo = new WebIllLogInfo();
webIllLogInfo.setUserId(webLogInfo.getUserId());
webIllLogInfo.setUserId(webLogInfo.getUsername());
webIllLogInfo.setSysAbbre(webLogInfo.getSysAbbre());
webIllLogInfo.setUrl(webLogInfo.getUrl());
webIllLogInfo.setAccessed(webLogInfo.getAccessed());
webIllLogInfo.setType(webLogInfo.getType());
webIllLogInfo.setClientIp(webLogInfo.getClientIp());
webIllLogInfo.setRemark(webLogInfo.getRemark());
webIllLogInfo.setIllType("noRule");
MyIotDbUtils.inserOne_Ill(iotDbConfig, webIllLogInfo);
}
}
}
\ No newline at end of file
package cn.gintone.service;
import cn.gintone.controller.vo.VisitPageReqVO;
import cn.gintone.controller.vo.VisitSaveReqVO;
import cn.gintone.entity.VisitDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import javax.validation.*;
/**
* 接口安全访问策略 Service 接口
*
* @author 胡懿
*/
public interface VisitService {
/**
* 创建接口安全访问策略
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createVisit(@Valid VisitSaveReqVO createReqVO);
/**
* 更新接口安全访问策略
*
* @param updateReqVO 更新信息
*/
void updateVisit(@Valid VisitSaveReqVO updateReqVO);
/**
* 删除接口安全访问策略
*
* @param id 编号
*/
void deleteVisit(Long id);
/**
* 获得接口安全访问策略
*
* @param id 编号
* @return 接口安全访问策略
*/
VisitDO getVisit(Long id);
/**
* 获得接口安全访问策略分页
*
* @param pageReqVO 分页查询
* @return 接口安全访问策略分页
*/
PageResult<VisitDO> getVisitPage(VisitPageReqVO pageReqVO);
}
\ No newline at end of file
package cn.gintone.service;
import cn.gintone.ErrorInfo;
import cn.gintone.controller.vo.VisitPageReqVO;
import cn.gintone.controller.vo.VisitSaveReqVO;
import cn.gintone.dal.VisitMapper;
import cn.gintone.entity.VisitDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
/**
* 接口安全访问策略 Service 实现类
*
* @author 胡懿
*/
@Service
@Validated
public class VisitServiceImpl implements VisitService {
@Resource
private VisitMapper visitMapper;
@Autowired
private VisitInfoService visitInfoService;
@Override
public Long createVisit(VisitSaveReqVO createReqVO) {
// 插入
VisitDO visit = BeanUtils.toBean(createReqVO, VisitDO.class);
visitMapper.insert(visit);
// 返回
return visit.getId();
}
@Override
public void updateVisit(VisitSaveReqVO updateReqVO) {
// 校验存在
validateVisitExists(updateReqVO.getId());
// 更新
VisitDO updateObj = BeanUtils.toBean(updateReqVO, VisitDO.class);
visitMapper.updateById(updateObj);
}
@Override
public void deleteVisit(Long id) {
// 校验存在
validateVisitExists(id);
// 删除
visitMapper.deleteById(id);
visitInfoService.deleteVisitInfo(id);
}
private void validateVisitExists(Long id) {
if (visitMapper.selectById(id) == null) {
throw exception(ErrorInfo.VISIT_NOT_EXISTS);
}
}
@Override
public VisitDO getVisit(Long id) {
return visitMapper.selectById(id);
}
@Override
public PageResult<VisitDO> getVisitPage(VisitPageReqVO pageReqVO) {
return visitMapper.selectPage(pageReqVO);
}
}
\ No newline at end of file
<?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="cn.gintone.dal.KeyCodeMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>
\ No newline at end of file
<?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="cn.gintone.dal.MyTableMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>
\ No newline at end of file
<?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="cn.gintone.dal.UserDesRuleMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>
\ No newline at end of file
<?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="cn.gintone.dal.VisitInfoMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>
\ No newline at end of file
<?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="cn.gintone.dal.VisitMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao</artifactId>
<version>${revision}</version>
</parent>
<groupId>cn.gintone</groupId>
<artifactId>gt-club</artifactId>
<packaging>pom</packaging>
<modules>
<module>gt-club-biz</module>
</modules>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment