Skip to content

Commit

Permalink
V1_1:测试代码安全
Browse files Browse the repository at this point in the history
  • Loading branch information
xuelei.yang committed Nov 19, 2024
1 parent 1b5c0e6 commit 0ff4cba
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
<artifactId>spring-boot-autoconfigure</artifactId>
<version>2.7.14</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

</dependencies>
<dependencyManagement>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/example/demo/controller/DemoController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.demo.controller;

import com.example.demo.utils.DemoUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

Expand All @@ -15,6 +16,7 @@
@RestController
@RequestMapping("/demo")
@Validated
@Slf4j
public class DemoController {

@PostMapping("/create")
Expand Down Expand Up @@ -43,6 +45,8 @@ public List<String> createMapPlatformPatent5(@RequestParam(value = "scope", requ
List<String> scopes = DemoUtil.buildScopes(scope);
DemoUtil.checkPnIsPublication("SDFF");
DemoUtil.dealApplyNumber("SDFF");
DemoUtil.createTempFile();
log.info("[initLocalCache][缓存敏感词,数量为:{}]", scopes);
return DemoUtil.buildScopes(scope);
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/example/demo/utils/DemoUtil.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.example.demo.utils;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import lombok.SneakyThrows;
import org.springframework.validation.annotation.Validated;

import java.io.File;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -35,4 +38,13 @@ public static String dealApplyNumber(String applyNumber) {
return applyNumber;
}
}

@SneakyThrows
public static File createTempFile() {
// 创建文件,通过 UUID 保证唯一
File file = File.createTempFile(IdUtil.simpleUUID(), null);
// 标记 JVM 退出时,自动删除
file.deleteOnExit();
return file;
}
}

0 comments on commit 0ff4cba

Please sign in to comment.