parent
ef48a292f5
commit
7bc5f2ef1a
|
@ -30,9 +30,7 @@ import org.apache.wss4j.dom.handler.WSHandlerConstants;
|
|||
import javax.xml.ws.BindingProvider;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -51,10 +49,6 @@ public class DpTechAbilityImpl implements DisposeAbility {
|
|||
* The Protect ip v 6.
|
||||
*/
|
||||
private final List<String> protectIpV6 = new ArrayList<>();
|
||||
/**
|
||||
* The All cleanup devices.
|
||||
*/
|
||||
private final HashSet<String> allCleanupDevices = new HashSet<>();
|
||||
/**
|
||||
* The Timer cnt.
|
||||
*/
|
||||
|
@ -69,36 +63,14 @@ public class DpTechAbilityImpl implements DisposeAbility {
|
|||
private AbnormalFlowCleaningServicePortType cleanTypePort;
|
||||
|
||||
/**
|
||||
* Init cleanup devices.
|
||||
* Gets clean type port.
|
||||
*
|
||||
* @return the clean type port
|
||||
*/
|
||||
private void initCleanupDevices() {
|
||||
try {
|
||||
log.info("++++Begging DPTech Get All Detect Devices");
|
||||
String dev = cleanTypePort.getAllProtectDevices();
|
||||
log.info("----Finish DPTech Get All Detect Devices: {}", dev);
|
||||
|
||||
Collections.addAll(allCleanupDevices, dev.split(DisposeConfigValue.SPLIT_CHAR));
|
||||
} catch (Exception ex) {
|
||||
log.error("----Exception DPTech Get All Detect Devices");
|
||||
}
|
||||
public AbnormalFlowCleaningServicePortType getCleanTypePort() {
|
||||
return cleanTypePort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init protection objects.
|
||||
*/
|
||||
private void initProtectionObjects() {
|
||||
try {
|
||||
log.info("++++Begging DPTech Get All Protection Objects");
|
||||
ArrayOfProtectionObjectDataForService ret = cleanTypePort.getAllProtectionObjectFromUMC();
|
||||
|
||||
String dev = cleanTypePort.getAllProtectDevices();
|
||||
log.info("----Finish DPTech Get All Protection Objects: {}", dev);
|
||||
|
||||
Collections.addAll(allCleanupDevices, dev.split(DisposeConfigValue.SPLIT_CHAR));
|
||||
} catch (Exception ex) {
|
||||
log.error("----Exception DPTech Get All Protection Objects");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Init device env.
|
||||
|
@ -139,9 +111,6 @@ public class DpTechAbilityImpl implements DisposeAbility {
|
|||
//读取超时
|
||||
policy.setReceiveTimeout(DpTechConfigValue.SOAP_RECEIVE_TIMEOUT_SECOND);
|
||||
conduit.setClient(policy);
|
||||
|
||||
// 获取所有检测设备
|
||||
initCleanupDevices();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,17 +1,151 @@
|
|||
package com.dispose.ability.impl;
|
||||
|
||||
import com.dispose.common.DisposeConfigValue;
|
||||
import com.dispose.common.DpTechConfigValue;
|
||||
import com.dispose.common.IpAddrType;
|
||||
import com.dispose.pojo.dto.protocol.device.ability.DpProtectObject;
|
||||
import com.dptech.dispose.ArrayOfProtectionObjectDataForService;
|
||||
import com.dptech.dispose.NtcRequestResultInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* The type Dp tech bypass ability.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Slf4j
|
||||
public class DpTechBypassAbilityImpl extends DpTechAbilityImpl {
|
||||
|
||||
/**
|
||||
* The Obj prefix.
|
||||
*/
|
||||
private final String OBJ_PREFIX = "CMHI";
|
||||
/**
|
||||
* The All cleanup devices.
|
||||
*/
|
||||
private final HashSet<String> allCleanupDevices = new HashSet<>();
|
||||
|
||||
/**
|
||||
* The Umc object.
|
||||
*/
|
||||
private final Hashtable<String, DpProtectObject> umcObject = new Hashtable<>();
|
||||
/**
|
||||
* The Timer cnt.
|
||||
*/
|
||||
private long timerCnt = 0;
|
||||
|
||||
/**
|
||||
* Init cleanup devices.
|
||||
*/
|
||||
private void initCleanupDevices() {
|
||||
try {
|
||||
log.info("++++Begging DPTech Get All Protection Devices");
|
||||
String dev = getCleanTypePort().getAllProtectDevices();
|
||||
log.info("----Finish DPTech Get All Protection Devices: {}", dev);
|
||||
|
||||
Collections.addAll(allCleanupDevices, dev.split(DisposeConfigValue.SPLIT_CHAR));
|
||||
} catch (Exception ex) {
|
||||
log.error("----Exception DPTech Get All Protection Devices: {}", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Init device env.
|
||||
*
|
||||
* @param urlPath the url path
|
||||
* @param username the username
|
||||
* @param password the password
|
||||
*/
|
||||
@Override
|
||||
public void initDeviceEnv(String urlPath, String username, String password) {
|
||||
super.initDeviceEnv(urlPath, username, password);
|
||||
|
||||
// 获取所有检测设备
|
||||
initCleanupDevices();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets dispose device protect object.
|
||||
* 防护对象命名规则 前缀_对象唯一名称_IP地址类型
|
||||
* CMHI_xxxx_V4
|
||||
* CMHI_XXXX_V6
|
||||
*/
|
||||
@Override
|
||||
public void getDisposeDeviceProtectObject() {
|
||||
try {
|
||||
log.info("++++Begging DPTech Get All Protection Objects");
|
||||
ArrayOfProtectionObjectDataForService ret = getCleanTypePort().getAllProtectionObjectFromUMC();
|
||||
|
||||
if (ret == null) {
|
||||
log.error("----Finish DPTech Get All Protection Objects error");
|
||||
return;
|
||||
}
|
||||
|
||||
ret.getProtectionObjectDataForService().forEach(k -> {
|
||||
String objName = k.getProtectionName().getValue();
|
||||
// 删除非法的防护对象
|
||||
if (!objName.startsWith(OBJ_PREFIX)) {
|
||||
log.error("!!!!Found Unexpect Protection Object [{}, {}], Deleted it.",
|
||||
objName,
|
||||
k.getIpSegment().getValue());
|
||||
|
||||
NtcRequestResultInfo rsp = getCleanTypePort().deleteProtectionObjectForUMC(objName);
|
||||
|
||||
if (rsp.getResultRetVal() == 0) {
|
||||
log.warn("!!!!Remove Protection Object {} Succeed", objName);
|
||||
} else {
|
||||
log.error("!!!!Remove Protection Object {} Error: {}", objName, rsp.getResultInfo().getValue());
|
||||
}
|
||||
} else {
|
||||
// 缓存所有防护对象
|
||||
DpProtectObject obj = DpProtectObject.builder()
|
||||
.cleanupDevices(k.getCleaningDevices().getValue())
|
||||
.protectName(objName)
|
||||
.detectionDevices(k.getDetectionDevices().getValue())
|
||||
.ipType(k.getIpType() == 0 ? IpAddrType.IPV4 : IpAddrType.IPV6)
|
||||
.ipSegment(new Hashtable<>())
|
||||
.build();
|
||||
|
||||
String ipSeg = k.getIpSegment().getValue();
|
||||
log.debug("DpTech response type: {}, value: {}", k.getIpType(), ipSeg);
|
||||
// 分割IP段
|
||||
Arrays.stream(StringUtils.deleteWhitespace(ipSeg).split(",")).forEach(v -> {
|
||||
String ipValue = v.replaceAll("\\d+_", "");
|
||||
String key = v.replace(ipValue, "").replace("_", "");
|
||||
// 添加到缓存
|
||||
obj.getIpSegment().put(key, ipValue);
|
||||
});
|
||||
|
||||
// 添加到缓存
|
||||
umcObject.put(objName, obj);
|
||||
}
|
||||
});
|
||||
|
||||
log.info("----Finish DPTech Get All Protection Objects: {}", ret.getProtectionObjectDataForService()
|
||||
.size());
|
||||
} catch (Exception ex) {
|
||||
log.error("----Exception DPTech Get All Protection Objects: {}", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Period task runtime.
|
||||
*/
|
||||
@Override
|
||||
public void periodTaskRuntime() {
|
||||
synchronized (this) {
|
||||
super.periodTaskRuntime();
|
||||
|
||||
if (timerCnt++ % DpTechConfigValue.PROTECTION_UPGRADE_PERIOD == 0) {
|
||||
// 定时检测防护对象
|
||||
getDisposeDeviceProtectObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,4 +21,9 @@ public class DpTechConfigValue {
|
|||
* The constant SOAP_RECEIVE_TIMEOUT_SECOND.
|
||||
*/
|
||||
public static volatile long SOAP_RECEIVE_TIMEOUT_SECOND = 60;
|
||||
|
||||
/**
|
||||
* The Protection upgrade period.
|
||||
*/
|
||||
public static final long PROTECTION_UPGRADE_PERIOD = 10;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.dispose.pojo.dto.protocol.device.ability;
|
||||
|
||||
import com.dispose.common.IpAddrType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
@ -14,6 +16,7 @@ import java.util.Hashtable;
|
|||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class DpProtectObject {
|
||||
/**
|
||||
* The Protect name.
|
||||
|
@ -31,7 +34,12 @@ public class DpProtectObject {
|
|||
private String cleanupDevices;
|
||||
|
||||
/**
|
||||
* The Ip segment v 4.
|
||||
* The Ip type.
|
||||
*/
|
||||
private IpAddrType ipType;
|
||||
|
||||
/**
|
||||
* The Ip segment.
|
||||
*/
|
||||
private Hashtable<String, String> ipSegment;
|
||||
}
|
||||
|
|
|
@ -607,4 +607,22 @@ public class demo {
|
|||
@Test
|
||||
public void codeDebug() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dpIpSegmentTest() {
|
||||
String ipSegmentString = "1_192.168.10.1-192.168.10.12,2_192.168.1.2-192.168.1.20,3_-";
|
||||
|
||||
Arrays.stream(ipSegmentString.split(",")).forEach(
|
||||
k -> {
|
||||
String value = k.replaceAll("\\d+_", "");
|
||||
String key = k.replace(value, "").replace("_", "");
|
||||
|
||||
if (Pattern.matches(ConstValue.ipAddrSegmentReg(), value)) {
|
||||
log.info("Result: {}, {}", key, value);
|
||||
} else {
|
||||
log.error("Result: {}, {} error", key, value);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue