【8.1.9】【security】编写更新黑白名单接口

dev-8.1.9
stylefeng 2024-07-10 21:43:53 +08:00
parent 7150244f01
commit d7a024a2d8
2 changed files with 53 additions and 0 deletions

View File

@ -15,6 +15,14 @@
<dependencies>
<!--参数校验模块-->
<!--用在控制器,参数校验-->
<dependency>
<groupId>com.javaguns.roses</groupId>
<artifactId>validator-api</artifactId>
<version>${roses.version}</version>
</dependency>
<!--安全模块的api-->
<dependency>
<groupId>com.javaguns.roses</groupId>

View File

@ -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<String> 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<String> 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<>();
}
}