应用增加白名单
This commit is contained in:
@@ -25,6 +25,12 @@ public class AppSave {
|
||||
*/
|
||||
@NotEmpty(message = "密码服务不能为空")
|
||||
private List<Long> serviceIds;
|
||||
|
||||
/**
|
||||
* 应用白名单
|
||||
*/
|
||||
private List<String> whiteIps;
|
||||
|
||||
@Size(max = 500, message = "备注长度在1-500之间")
|
||||
private String remark;
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ public class AppView {
|
||||
private String statusText;
|
||||
private String appKey;
|
||||
private String appSecret;
|
||||
private List<String> whiteIps;
|
||||
|
||||
private String remark;
|
||||
private LocalDateTime createTime;
|
||||
|
||||
+41
@@ -11,10 +11,13 @@ import com.sunyard.chsm.enums.EnableStatus;
|
||||
import com.sunyard.chsm.mapper.AppServiceMapper;
|
||||
import com.sunyard.chsm.mapper.ApplicationMapper;
|
||||
import com.sunyard.chsm.mapper.CryptoServiceMapper;
|
||||
import com.sunyard.chsm.mapper.IpWhitelisttMapper;
|
||||
import com.sunyard.chsm.model.entity.AppService;
|
||||
import com.sunyard.chsm.model.entity.Application;
|
||||
import com.sunyard.chsm.model.entity.CryptoService;
|
||||
import com.sunyard.chsm.model.entity.IpWhitelist;
|
||||
import com.sunyard.chsm.service.ApplicationService;
|
||||
import com.sunyard.ssp.utils.SecurityUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -46,6 +49,10 @@ public class ApplicationServiceImpl implements ApplicationService {
|
||||
private AppServiceMapper appServiceMapper;
|
||||
@Resource
|
||||
private CryptoServiceMapper cryptoServiceMapper;
|
||||
@Resource
|
||||
private IpWhitelisttMapper ipWhitelisttMapper;
|
||||
@Resource
|
||||
private SecurityUtil securityUtil;
|
||||
|
||||
@Override
|
||||
public Page<AppView> selectPageList(AppQuery query) {
|
||||
@@ -68,12 +75,17 @@ public class ApplicationServiceImpl implements ApplicationService {
|
||||
List<CryptoService> services = cryptoServiceMapper.selectBatchIds(appServices.stream().map(AppService::getServiceId).collect(Collectors.toList()));
|
||||
Map<Long, String> snMap = services.stream().collect(Collectors.toMap(CryptoService::getId, CryptoService::getName));
|
||||
|
||||
List<IpWhitelist> appWhiteIps = ipWhitelisttMapper.selectByAppIds(appIds);
|
||||
Map<Long, List<String>> appIpMap = appWhiteIps.stream()
|
||||
.collect(Collectors.groupingBy(IpWhitelist::getAppId, Collectors.mapping(IpWhitelist::getIp, Collectors.toList())));
|
||||
|
||||
List<AppView> viewList = records.stream()
|
||||
.map(it -> {
|
||||
AppView view = new AppView();
|
||||
BeanUtils.copyProperties(it, view);
|
||||
List<Long> sIds = appServiceMap.getOrDefault(it.getId(), Collections.emptyList());
|
||||
view.setServiceIds(sIds.stream().map(String::valueOf).collect(Collectors.toList()));
|
||||
view.setWhiteIps(appIpMap.get(it.getId()));
|
||||
String sn = sIds.stream()
|
||||
.map(snMap::get)
|
||||
.filter(Objects::nonNull)
|
||||
@@ -111,9 +123,24 @@ public class ApplicationServiceImpl implements ApplicationService {
|
||||
as.setCreateTime(now);
|
||||
appServiceMapper.insert(as);
|
||||
}
|
||||
|
||||
if (!CollectionUtils.isEmpty(save.getWhiteIps())) {
|
||||
for (String ip : save.getWhiteIps()) {
|
||||
IpWhitelist whitelist = new IpWhitelist();
|
||||
whitelist.setId(IdWorker.getId());
|
||||
whitelist.setAppId(app.getId());
|
||||
whitelist.setIp(ip);
|
||||
whitelist.setScope("app");
|
||||
whitelist.setStatus(EnableStatus.ENABLED.getCode());
|
||||
whitelist.setCreator(securityUtil.getCurrUser().getRealname());
|
||||
whitelist.setCreateTime(LocalDateTime.now());
|
||||
ipWhitelisttMapper.insert(whitelist);
|
||||
}
|
||||
}
|
||||
return app.getId();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(AppSave update) {
|
||||
Assert.notNull(update.getId(), "id不能为空");
|
||||
@@ -141,6 +168,20 @@ public class ApplicationServiceImpl implements ApplicationService {
|
||||
as.setCreateTime(now);
|
||||
appServiceMapper.insert(as);
|
||||
}
|
||||
ipWhitelisttMapper.deleteByAppId(update.getId());
|
||||
if (!CollectionUtils.isEmpty(update.getWhiteIps())) {
|
||||
for (String ip : update.getWhiteIps()) {
|
||||
IpWhitelist whitelist = new IpWhitelist();
|
||||
whitelist.setId(IdWorker.getId());
|
||||
whitelist.setAppId(exist.getId());
|
||||
whitelist.setIp(ip);
|
||||
whitelist.setScope("app");
|
||||
whitelist.setStatus(EnableStatus.ENABLED.getCode());
|
||||
whitelist.setCreator(securityUtil.getCurrUser().getRealname());
|
||||
whitelist.setCreateTime(LocalDateTime.now());
|
||||
ipWhitelisttMapper.insert(whitelist);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user