From d7a024a2d8e119992420125c8e32f321e7a62e39 Mon Sep 17 00:00:00 2001 From: stylefeng Date: Wed, 10 Jul 2024 21:43:53 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=908.1.9=E3=80=91=E3=80=90security?= =?UTF-8?q?=E3=80=91=E7=BC=96=E5=86=99=E6=9B=B4=E6=96=B0=E9=BB=91=E7=99=BD?= =?UTF-8?q?=E5=90=8D=E5=8D=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security-sdk-black-white/pom.xml | 8 ++++ .../SecurityBlackWhiteController.java | 45 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/kernel-d-security/security-sdk-black-white/pom.xml b/kernel-d-security/security-sdk-black-white/pom.xml index 8aa2bd383..21d5d2703 100644 --- a/kernel-d-security/security-sdk-black-white/pom.xml +++ b/kernel-d-security/security-sdk-black-white/pom.xml @@ -15,6 +15,14 @@ + + + + com.javaguns.roses + validator-api + ${roses.version} + + com.javaguns.roses diff --git a/kernel-d-security/security-sdk-black-white/src/main/java/cn/stylefeng/roses/kernel/security/blackwhite/controller/SecurityBlackWhiteController.java b/kernel-d-security/security-sdk-black-white/src/main/java/cn/stylefeng/roses/kernel/security/blackwhite/controller/SecurityBlackWhiteController.java index 4ffec27ba..d721c8761 100644 --- a/kernel-d-security/security-sdk-black-white/src/main/java/cn/stylefeng/roses/kernel/security/blackwhite/controller/SecurityBlackWhiteController.java +++ b/kernel-d-security/security-sdk-black-white/src/main/java/cn/stylefeng/roses/kernel/security/blackwhite/controller/SecurityBlackWhiteController.java @@ -1,13 +1,16 @@ package cn.stylefeng.roses.kernel.security.blackwhite.controller; +import cn.hutool.core.util.ObjectUtil; import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData; import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData; import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource; import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource; +import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource; import cn.stylefeng.roses.kernel.security.api.constants.SecurityPermissionConstants; import cn.stylefeng.roses.kernel.security.blackwhite.BlackListService; import cn.stylefeng.roses.kernel.security.blackwhite.WhiteListService; import cn.stylefeng.roses.kernel.security.blackwhite.pojo.BlackWhiteList; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; @@ -52,5 +55,47 @@ public class SecurityBlackWhiteController { return new SuccessResponseData<>(blackWhiteList); } + /** + * 设置黑白名单列表 + * + * @author fengshuonan + * @since 2024/7/10 21:29 + */ + @PostResource(name = "设置黑白名单列表", path = "/blackWhite/updateBlackWhite") + public ResponseData updateBlackWhite(@RequestBody BlackWhiteList blackWhiteList) { + + // 清空黑名单列表 + Collection blackList = blackListService.getBlackList(); + if (ObjectUtil.isNotEmpty(blackList)) { + for (String key : blackList) { + blackListService.removeBlackItem(key); + } + } + + // 更新黑名单列表 + if (ObjectUtil.isNotEmpty(blackWhiteList.getBlackList())) { + for (String key : blackWhiteList.getBlackList()) { + blackListService.addBlackItem(key); + } + } + + // 清空白名单列表 + Collection whiteList = whiteListService.getWhiteList(); + if (ObjectUtil.isNotEmpty(whiteList)) { + for (String key : whiteList) { + whiteListService.removeWhiteItem(key); + } + } + + // 更新白名单列表 + if (ObjectUtil.isNotEmpty(blackWhiteList.getWhiteList())) { + for (String key : blackWhiteList.getWhiteList()) { + whiteListService.addWhiteItem(key); + } + } + + return new SuccessResponseData<>(); + } + }