ing
This commit is contained in:
parent
31fd84e984
commit
58bddae263
28
.vscode/launch.test.json
vendored
Normal file
28
.vscode/launch.test.json
vendored
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
{
|
||||||
|
"run": {
|
||||||
|
"default": "",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"name": "central",
|
||||||
|
"projectName": "central",
|
||||||
|
"workingDirectory": "/project/loafle/overflow/central",
|
||||||
|
"args": [],
|
||||||
|
"vmargs": [],
|
||||||
|
"preLaunchTask": ""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"debug": {
|
||||||
|
"default": "",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"name": "central",
|
||||||
|
"projectName": "central",
|
||||||
|
"workingDirectory": "/project/loafle/overflow/central",
|
||||||
|
"args": [],
|
||||||
|
"vmargs": [],
|
||||||
|
"preLaunchTask": ""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -51,190 +51,189 @@ import javax.transaction.Transactional;
|
||||||
@Service("NoAuthProbeService")
|
@Service("NoAuthProbeService")
|
||||||
public class CentralNoAuthProbeService implements NoAuthProbeService {
|
public class CentralNoAuthProbeService implements NoAuthProbeService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private NoAuthProbeDAO noAuthProbeDAO;
|
private NoAuthProbeDAO noAuthProbeDAO;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApiKeyService apiKeyService;
|
private ApiKeyService apiKeyService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ProbeService probeService;
|
private ProbeService probeService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MessagePublisher messagePublisher;
|
private MessagePublisher messagePublisher;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DomainMemberService domainMemberService;
|
private DomainMemberService domainMemberService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ObjectMapper objectMapper;
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private InfraMachineService infraMachineService;
|
private InfraMachineService infraMachineService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private InfraOSService infraOSService;
|
private InfraOSService infraOSService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private InfraHostService infraHostService;
|
private InfraHostService infraHostService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ProbeHostService probeHostService;
|
private ProbeHostService probeHostService;
|
||||||
|
|
||||||
@ProbeAPI
|
@ProbeAPI
|
||||||
public NoAuthProbe regist(NoAuthProbe noAuthProbe) throws OverflowException {
|
public NoAuthProbe regist(NoAuthProbe noAuthProbe) throws OverflowException {
|
||||||
|
|
||||||
ApiKey apiKey = apiKeyService.readByApiKey(noAuthProbe.getApiKey());
|
ApiKey apiKey = apiKeyService.readByApiKey(noAuthProbe.getApiKey());
|
||||||
noAuthProbe.setDomain(apiKey.getDomain());
|
noAuthProbe.setDomain(apiKey.getDomain());
|
||||||
|
|
||||||
noAuthProbe.setTempProbeKey(GenerateKey.getKey());
|
noAuthProbe.setTempProbeKey(GenerateKey.getKey());
|
||||||
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 3));
|
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 3));
|
||||||
|
|
||||||
messagePublisher.publishToDomainMembers(apiKey.getDomain().getId(), "NoAuthProbeService.regist", noAuthProbe);
|
messagePublisher.publishToDomainMembers(apiKey.getDomain().getId(), "NoAuthProbeService.regist", noAuthProbe);
|
||||||
|
|
||||||
return this.noAuthProbeDAO.save(noAuthProbe);
|
return this.noAuthProbeDAO.save(noAuthProbe);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<NoAuthProbe> readAllByDomainID(Long domainID) throws OverflowException {
|
||||||
|
|
||||||
|
return this.noAuthProbeDAO.findAllByDomainId(domainID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NoAuthProbe read(Long id) {
|
||||||
|
return this.noAuthProbeDAO.findOne(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@WebappAPI
|
||||||
|
@Transactional
|
||||||
|
public List<NoAuthProbe> acceptNoAuthProbe(Long noAuthProbeID) throws OverflowException {
|
||||||
|
NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findOne(noAuthProbeID);
|
||||||
|
|
||||||
|
NoAuthProbeDescription noAuthProbeDescription = null;
|
||||||
|
try {
|
||||||
|
noAuthProbeDescription = this.objectMapper.readValue(noAuthProbe.getDescription(), NoAuthProbeDescription.class);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new OverflowException("json error", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<NoAuthProbe> readAllByDomainID(Long domainID) throws OverflowException {
|
Probe probe = this.newProbe(noAuthProbe, noAuthProbeDescription);
|
||||||
|
InfraMachine machine = this.newInfraMachine(noAuthProbe);
|
||||||
|
InfraOS os = this.newInfraOS(machine, noAuthProbeDescription.getHost());
|
||||||
|
InfraHost host = this.newInfraHost(os, noAuthProbeDescription.getNetwork());
|
||||||
|
this.newProbeHost(host, probe);
|
||||||
|
|
||||||
return this.noAuthProbeDAO.findAllByDomainId(domainID);
|
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 1));
|
||||||
}
|
this.noAuthProbeDAO.save(noAuthProbe);
|
||||||
|
|
||||||
public NoAuthProbe read(Long id) {
|
messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Accept", probe.getProbeKey());
|
||||||
return this.noAuthProbeDAO.findOne(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@WebappAPI
|
return this.readAllByDomainID(noAuthProbe.getDomain().getId());
|
||||||
@Transactional
|
}
|
||||||
public List<NoAuthProbe> acceptNoAuthProbe(Long noAuthProbeID) throws OverflowException {
|
|
||||||
NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findOne(noAuthProbeID);
|
|
||||||
|
|
||||||
NoAuthProbeDescription noAuthProbeDescription = null;
|
private Probe newProbe(NoAuthProbe noauthprobe, NoAuthProbeDescription noAuthProbeDescription) throws OverflowException {
|
||||||
try {
|
|
||||||
noAuthProbeDescription = this.objectMapper.readValue(noAuthProbe.getDescription(), NoAuthProbeDescription.class);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new OverflowException("json error", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
Probe probe = this.newProbe(noAuthProbe, noAuthProbeDescription);
|
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||||
InfraMachine machine = this.newInfraMachine(noAuthProbe);
|
String encryptKey = passwordEncoder.encode(UUID.randomUUID().toString());
|
||||||
InfraOS os = this.newInfraOS(machine, noAuthProbeDescription.getHost());
|
|
||||||
InfraHost host = this.newInfraHost(os, noAuthProbeDescription.getNetwork());
|
|
||||||
this.newProbeHost(host, probe);
|
|
||||||
|
|
||||||
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 1));
|
ApiKey apiKey = apiKeyService.readByApiKey(noauthprobe.getApiKey());
|
||||||
this.noAuthProbeDAO.save(noAuthProbe);
|
String memberEmail = SessionMetadata.getTargetID();
|
||||||
|
DomainMember domainMember = domainMemberService.readByMemberEmail(memberEmail);
|
||||||
|
|
||||||
messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Accept",
|
Probe probe = new Probe();
|
||||||
probe.getProbeKey());
|
probe.setEncryptionKey(encryptKey);
|
||||||
|
probe.setProbeKey(GenerateKey.getKey());
|
||||||
|
probe.setDomain(new Domain(apiKey.getDomain().getId()));
|
||||||
|
probe.setAuthorizeMember(new Member(domainMember.getMember().getId()));
|
||||||
|
probe.setTargetCount(0);
|
||||||
|
probe.setStatus(new MetaProbeStatus((short) 1));
|
||||||
|
|
||||||
return this.readAllByDomainID(noAuthProbe.getDomain().getId());
|
String dispName = noAuthProbeDescription.getHost().getName();
|
||||||
}
|
dispName += " probe";
|
||||||
|
probe.setDisplayName(dispName);
|
||||||
|
|
||||||
private Probe newProbe(NoAuthProbe noauthprobe, NoAuthProbeDescription noAuthProbeDescription) throws OverflowException {
|
String addrStr = noAuthProbeDescription.getNetwork().getAddress();
|
||||||
|
String[] addrArr = addrStr.split("\\|");
|
||||||
|
probe.setCidr(addrArr[0]);
|
||||||
|
|
||||||
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
return this.probeService.regist(probe);
|
||||||
String encryptKey = passwordEncoder.encode(UUID.randomUUID().toString());
|
}
|
||||||
|
|
||||||
ApiKey apiKey = apiKeyService.readByApiKey(noauthprobe.getApiKey());
|
private InfraMachine newInfraMachine(NoAuthProbe noauthprobe) throws OverflowException {
|
||||||
String memberEmail = SessionMetadata.getTargetID();
|
MetaInfraType infraType = new MetaInfraType();
|
||||||
DomainMember domainMember = domainMemberService.readByMemberEmail(memberEmail);
|
infraType.setId(1);
|
||||||
|
|
||||||
Probe probe = new Probe();
|
InfraMachine infraMachine = new InfraMachine();
|
||||||
probe.setEncryptionKey(encryptKey);
|
infraMachine.setMeta(noauthprobe.getDescription());
|
||||||
probe.setProbeKey(GenerateKey.getKey());
|
infraMachine.setInfraType(infraType);
|
||||||
probe.setDomain(new Domain(apiKey.getDomain().getId()));
|
|
||||||
probe.setAuthorizeMember(new Member(domainMember.getMember().getId()));
|
|
||||||
probe.setTargetCount(0);
|
|
||||||
probe.setStatus(new MetaProbeStatus((short) 1));
|
|
||||||
|
|
||||||
String dispName = noAuthProbeDescription.getHost().getName();
|
return this.infraMachineService.regist(infraMachine);
|
||||||
dispName += " probe";
|
}
|
||||||
probe.setDisplayName(dispName);
|
|
||||||
|
|
||||||
String addrStr = noAuthProbeDescription.getNetwork().getAddress();
|
private InfraOS newInfraOS(InfraMachine infraMachine, NoAuthProbeDescriptionHost noAuthProbeDescriptionHost) throws OverflowException {
|
||||||
String[] addrArr = addrStr.split("\\|");
|
MetaInfraType infraType = new MetaInfraType();
|
||||||
probe.setCidr(addrArr[0]);
|
infraType.setId(3);
|
||||||
|
|
||||||
return this.probeService.regist(probe);
|
InfraOS infraOS = new InfraOS();
|
||||||
}
|
infraOS.setMachine(infraMachine);
|
||||||
|
infraOS.setInfraType(infraType);
|
||||||
|
infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(noAuthProbeDescriptionHost.getOS()));
|
||||||
|
|
||||||
private InfraMachine newInfraMachine(NoAuthProbe noauthprobe) throws OverflowException {
|
return this.infraOSService.regist(infraOS);
|
||||||
MetaInfraType infraType = new MetaInfraType();
|
}
|
||||||
infraType.setId(1);
|
|
||||||
|
|
||||||
InfraMachine infraMachine = new InfraMachine();
|
private InfraHost newInfraHost(InfraOS infraOS, NoAuthProbeDescriptionNetwork noAuthProbeDescriptionNetwork) throws OverflowException {
|
||||||
infraMachine.setMeta(noauthprobe.getDescription());
|
MetaInfraType infraType = new MetaInfraType();
|
||||||
infraMachine.setInfraType(infraType);
|
infraType.setId(2);
|
||||||
|
|
||||||
return this.infraMachineService.regist(infraMachine);
|
InfraHost infraHost = new InfraHost();
|
||||||
}
|
String addrStr = noAuthProbeDescriptionNetwork.getAddress();
|
||||||
|
String[] addrArr = addrStr.split("\\|");
|
||||||
|
|
||||||
private InfraOS newInfraOS(InfraMachine infraMachine, NoAuthProbeDescriptionHost noAuthProbeDescriptionHost) throws OverflowException {
|
infraHost.setIpv4(addrArr[0]);
|
||||||
MetaInfraType infraType = new MetaInfraType();
|
infraHost.setMac(noAuthProbeDescriptionNetwork.getMacAddress());
|
||||||
infraType.setId(3);
|
infraHost.setOs(infraOS);
|
||||||
|
infraHost.setInfraType(infraType);
|
||||||
|
|
||||||
InfraOS infraOS = new InfraOS();
|
return this.infraHostService.regist(infraHost);
|
||||||
infraOS.setMachine(infraMachine);
|
}
|
||||||
infraOS.setInfraType(infraType);
|
|
||||||
infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(noAuthProbeDescriptionHost.getOS()));
|
|
||||||
|
|
||||||
return this.infraOSService.regist(infraOS);
|
private void newProbeHost(InfraHost infraHost, Probe probe) throws OverflowException {
|
||||||
}
|
ProbeHost probeHost = new ProbeHost();
|
||||||
|
probeHost.setHost(infraHost);
|
||||||
|
probeHost.setProbe(probe);
|
||||||
|
|
||||||
private InfraHost newInfraHost(InfraOS infraOS, NoAuthProbeDescriptionNetwork noAuthProbeDescriptionNetwork) throws OverflowException {
|
this.probeHostService.regist(probeHost);
|
||||||
MetaInfraType infraType = new MetaInfraType();
|
}
|
||||||
infraType.setId(2);
|
|
||||||
|
|
||||||
InfraHost infraHost = new InfraHost();
|
@WebappAPI
|
||||||
String addrStr = noAuthProbeDescriptionNetwork.getAddress();
|
public List<NoAuthProbe> denyNoauthProbe(Long noAuthProbeID) throws OverflowException {
|
||||||
String[] addrArr = addrStr.split("\\|");
|
NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findOne(noAuthProbeID);
|
||||||
|
|
||||||
infraHost.setIpv4(addrArr[0]);
|
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 2));
|
||||||
infraHost.setMac(noAuthProbeDescriptionNetwork.getMacAddress());
|
this.noAuthProbeDAO.save(noAuthProbe);
|
||||||
infraHost.setOs(infraOS);
|
|
||||||
infraHost.setInfraType(infraType);
|
|
||||||
|
|
||||||
return this.infraHostService.regist(infraHost);
|
messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Deny");
|
||||||
}
|
|
||||||
|
|
||||||
private void newProbeHost(InfraHost infraHost, Probe probe) throws OverflowException {
|
return this.readAllByDomainID(noAuthProbe.getDomain().getId());
|
||||||
ProbeHost probeHost = new ProbeHost();
|
}
|
||||||
probeHost.setHost(infraHost);
|
|
||||||
probeHost.setProbe(probe);
|
|
||||||
|
|
||||||
this.probeHostService.regist(probeHost);
|
public NoAuthProbe readByTempProbeKey(String tempKey) throws OverflowException {
|
||||||
}
|
return this.noAuthProbeDAO.findByTempProbeKey(tempKey);
|
||||||
|
}
|
||||||
|
|
||||||
@WebappAPI
|
public void onConnect(String tempKey, String connectAddress) throws OverflowException {
|
||||||
public List<NoAuthProbe> denyNoauthProbe(Long noAuthProbeID) throws OverflowException {
|
NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findByTempProbeKey(tempKey);
|
||||||
NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findOne(noAuthProbeID);
|
noAuthProbe.setConnectDate(new Date());
|
||||||
|
noAuthProbe.setConnectAddress(connectAddress);
|
||||||
|
noAuthProbe = this.noAuthProbeDAO.save(noAuthProbe);
|
||||||
|
|
||||||
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 2));
|
messagePublisher.publishToDomainMembers(noAuthProbe.getDomain().getId(), "NoAuthProbeService.onConnect", noAuthProbe);
|
||||||
this.noAuthProbeDAO.save(noAuthProbe);
|
}
|
||||||
|
|
||||||
messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Deny");
|
public void onDisconnect(String tempKey) throws OverflowException {
|
||||||
|
NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findByTempProbeKey(tempKey);
|
||||||
|
noAuthProbe.setConnectDate(null);
|
||||||
|
noAuthProbe.setConnectAddress(null);
|
||||||
|
noAuthProbe = this.noAuthProbeDAO.save(noAuthProbe);
|
||||||
|
|
||||||
return this.readAllByDomainID(noAuthProbe.getDomain().getId());
|
messagePublisher.publishToDomainMembers(noAuthProbe.getDomain().getId(), "NoAuthProbeService.onDisconnect", noAuthProbe);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NoAuthProbe readByTempProbeKey(String tempKey) throws OverflowException {
|
|
||||||
return this.noAuthProbeDAO.findByTempProbeKey(tempKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onConnect(String tempKey, String connectAddress) throws OverflowException {
|
|
||||||
NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findByTempProbeKey(tempKey);
|
|
||||||
noAuthProbe.setConnectDate(new Date());
|
|
||||||
noAuthProbe.setConnectAddress(connectAddress);
|
|
||||||
noAuthProbe = this.noAuthProbeDAO.save(noAuthProbe);
|
|
||||||
|
|
||||||
messagePublisher.publishToDomainMembers(noAuthProbe.getDomain().getId(), "NoAuthProbeService.onConnect", noAuthProbe);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onDisconnect(String tempKey) throws OverflowException {
|
|
||||||
NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findByTempProbeKey(tempKey);
|
|
||||||
noAuthProbe.setConnectDate(null);
|
|
||||||
noAuthProbe.setConnectAddress(null);
|
|
||||||
noAuthProbe = this.noAuthProbeDAO.save(noAuthProbe);
|
|
||||||
|
|
||||||
messagePublisher.publishToDomainMembers(noAuthProbe.getDomain().getId(), "NoAuthProbeService.onDisconnect", noAuthProbe);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,164 +1,154 @@
|
||||||
// package com.loafle.overflow.central.module.noauthprobe.service;
|
package com.loafle.overflow.central.module.noauthprobe.service;
|
||||||
|
|
||||||
// import com.loafle.overflow.central.commons.service.MessagePublisher;
|
import com.loafle.overflow.central.commons.service.MessagePublisher;
|
||||||
// import com.loafle.overflow.central.spring.AppConfigTest;
|
import com.loafle.overflow.central.spring.AppConfigTest;
|
||||||
// import com.loafle.overflow.core.exception.OverflowException;
|
import com.loafle.overflow.core.exception.OverflowException;
|
||||||
// import com.loafle.overflow.model.domain.Domain;
|
import com.loafle.overflow.model.domain.Domain;
|
||||||
// import com.loafle.overflow.model.meta.MetaNoAuthProbeStatus;
|
import com.loafle.overflow.model.meta.MetaNoAuthProbeStatus;
|
||||||
// import com.loafle.overflow.model.noauthprobe.NoAuthProbe;
|
import com.loafle.overflow.model.noauthprobe.NoAuthProbe;
|
||||||
// import com.loafle.overflow.service.central.noauthprobe.NoAuthProbeService;
|
import com.loafle.overflow.service.central.noauthprobe.NoAuthProbeService;
|
||||||
|
|
||||||
// import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
// import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
// import org.junit.Test;
|
import org.junit.Test;
|
||||||
// import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
// import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
// import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
// import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
// import java.io.IOException;
|
import java.io.IOException;
|
||||||
// import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
// import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Created by snoop on 17. 6. 28.
|
* Created by snoop on 17. 6. 28.
|
||||||
// */
|
*/
|
||||||
// @RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
// @ContextConfiguration(classes = {AppConfigTest.class})
|
@ContextConfiguration(classes = { AppConfigTest.class })
|
||||||
// public class NoAuthProbeServiceTest {
|
public class NoAuthProbeServiceTest {
|
||||||
|
|
||||||
// @Autowired
|
@Autowired
|
||||||
// private NoAuthProbeService noAuthProbeService;
|
private CentralNoAuthProbeService noAuthProbeService;
|
||||||
|
|
||||||
// @Autowired
|
@Autowired
|
||||||
// private MessagePublisher messagePublisher;
|
private MessagePublisher messagePublisher;
|
||||||
|
|
||||||
// @Ignore
|
@Ignore
|
||||||
// @Test
|
@Test
|
||||||
// public void regist() throws Exception {
|
public void regist() throws Exception {
|
||||||
|
|
||||||
// NoAuthProbe noAuthProbe = new NoAuthProbe();
|
NoAuthProbe noAuthProbe = new NoAuthProbe();
|
||||||
|
|
||||||
|
// noAuthProbe.setHostName("snoop");
|
||||||
|
// noAuthProbe.setIpAddress(3232235980L);
|
||||||
|
// noAuthProbe.setMacAddress(8796753988883L);
|
||||||
|
noAuthProbe.setDescription(
|
||||||
|
"{\"host\":{\"name\":\"snoop-ubuntu\",\"os\":\"linux\",\"paltform\":\"ubuntu\",\"platformFamily\":\"debian\",\"platformVersion\":\"\",\"kernelVersion\":\"4.4.0-93-generic\",\"hostID\":\"DE60E4C3-347A-4D38-AEAB-1760471665EA\"},\"network\":{\"name\":\"enp3s0\",\"address\":\"192.168.1.106/24|fe80::36c0:6c3e:6006:dd23/64\",\"gateway\":\"192.168.1.254\",\"macAddress\":\"44:8a:5b:f1:f1:f3\"}}");
|
||||||
|
|
||||||
// // noAuthProbe.setHostName("snoop");
|
noAuthProbe.setApiKey("52abd6fd57e511e7ac52080027658d13");
|
||||||
// // noAuthProbe.setIpAddress(3232235980L);
|
|
||||||
// // noAuthProbe.setMacAddress(8796753988883L);
|
|
||||||
// noAuthProbe.setDescription("{\"host\":{\"name\":\"snoop-ubuntu\",\"os\":\"linux\",\"paltform\":\"ubuntu\",\"platformFamily\":\"debian\",\"platformVersion\":\"\",\"kernelVersion\":\"4.4.0-93-generic\",\"hostID\":\"DE60E4C3-347A-4D38-AEAB-1760471665EA\"},\"network\":{\"name\":\"enp3s0\",\"address\":\"192.168.1.106/24|fe80::36c0:6c3e:6006:dd23/64\",\"gateway\":\"192.168.1.254\",\"macAddress\":\"44:8a:5b:f1:f1:f3\"}}");
|
|
||||||
|
|
||||||
// noAuthProbe.setApiKey("52abd6fd57e511e7ac52080027658d13");
|
MetaNoAuthProbeStatus metaNoAuthProbeStatus = new MetaNoAuthProbeStatus();
|
||||||
|
metaNoAuthProbeStatus.setId((short) 3);
|
||||||
|
|
||||||
// MetaNoAuthProbeStatus metaNoAuthProbeStatus = new MetaNoAuthProbeStatus();
|
noAuthProbe.setStatus(metaNoAuthProbeStatus);
|
||||||
// metaNoAuthProbeStatus.setId((short)3);
|
noAuthProbe.setTempProbeKey("ac7f252b5bc811e784ad080027658d13");
|
||||||
|
|
||||||
// noAuthProbe.setStatus(metaNoAuthProbeStatus);
|
Domain d = new Domain();
|
||||||
// noAuthProbe.setTempProbeKey("ac7f252b5bc811e784ad080027658d13");
|
d.setId(Long.valueOf(1));
|
||||||
|
noAuthProbe.setDomain(d);
|
||||||
|
|
||||||
// Domain d = new Domain();
|
this.noAuthProbeService.regist(noAuthProbe);
|
||||||
// d.setId(1);
|
|
||||||
// noAuthProbe.setDomain(d);
|
|
||||||
|
|
||||||
// this.noAuthProbeService.regist(noAuthProbe);
|
Assert.assertNotEquals(noAuthProbe.getId().longValue(), 0);
|
||||||
|
|
||||||
// Assert.assertNotEquals(noAuthProbe.getId(), 0);
|
}
|
||||||
|
|
||||||
// }
|
@Ignore
|
||||||
|
@Test
|
||||||
|
public void registForNoAuthProbes() throws Exception {
|
||||||
|
|
||||||
// @Ignore
|
NoAuthProbe noAuthProbe = new NoAuthProbe();
|
||||||
// @Test
|
|
||||||
// public void registForNoAuthProbes() throws Exception {
|
|
||||||
|
|
||||||
// NoAuthProbe noAuthProbe = new NoAuthProbe();
|
// noAuthProbe.setHostName("geek");
|
||||||
|
// noAuthProbe.setIpAddress(3232235980L);
|
||||||
|
// noAuthProbe.setMacAddress(8796753988883L);
|
||||||
|
noAuthProbe.setDescription(
|
||||||
|
"{\"host\":{\"name\":\"geek-ubuntu\",\"os\":\"linux\",\"paltform\":\"ubuntu\",\"platformFamily\":\"debian\",\"platformVersion\":\"\",\"kernelVersion\":\"4.4.0-93-generic\",\"hostID\":\"03000200-0400-0500-0006-000700080009\"},\"network\":{\"name\":\"enp3s0\",\"address\":\"192.168.1.103/24|fe80::36c0:6c3e:6006:dd23/64\",\"gateway\":\"192.168.1.254\",\"macAddress\":\"44:8a:5b:f1:f1:f3\"}}");
|
||||||
|
noAuthProbe.setApiKey("521abd6fd57e511e7ac52080027658d13");
|
||||||
|
|
||||||
// // noAuthProbe.setHostName("geek");
|
MetaNoAuthProbeStatus metaNoAuthProbeStatus = new MetaNoAuthProbeStatus();
|
||||||
// // noAuthProbe.setIpAddress(3232235980L);
|
metaNoAuthProbeStatus.setId((short) 3);
|
||||||
// // noAuthProbe.setMacAddress(8796753988883L);
|
|
||||||
// noAuthProbe.setDescription("{\"host\":{\"name\":\"geek-ubuntu\",\"os\":\"linux\",\"paltform\":\"ubuntu\",\"platformFamily\":\"debian\",\"platformVersion\":\"\",\"kernelVersion\":\"4.4.0-93-generic\",\"hostID\":\"03000200-0400-0500-0006-000700080009\"},\"network\":{\"name\":\"enp3s0\",\"address\":\"192.168.1.103/24|fe80::36c0:6c3e:6006:dd23/64\",\"gateway\":\"192.168.1.254\",\"macAddress\":\"44:8a:5b:f1:f1:f3\"}}");
|
|
||||||
// noAuthProbe.setApiKey("521abd6fd57e511e7ac52080027658d13");
|
|
||||||
|
|
||||||
// MetaNoAuthProbeStatus metaNoAuthProbeStatus = new MetaNoAuthProbeStatus();
|
noAuthProbe.setStatus(metaNoAuthProbeStatus);
|
||||||
// metaNoAuthProbeStatus.setId((short)3);
|
noAuthProbe.setTempProbeKey("a1c7f252b5bc811e784ad080027658d13");
|
||||||
|
|
||||||
// noAuthProbe.setStatus(metaNoAuthProbeStatus);
|
Domain d = new Domain();
|
||||||
// noAuthProbe.setTempProbeKey("a1c7f252b5bc811e784ad080027658d13");
|
d.setId(Long.valueOf(1));
|
||||||
|
noAuthProbe.setDomain(d);
|
||||||
|
|
||||||
// Domain d = new Domain();
|
List<NoAuthProbe> noAuthProbes = new ArrayList<NoAuthProbe>();
|
||||||
// d.setId(1);
|
|
||||||
// noAuthProbe.setDomain(d);
|
|
||||||
|
|
||||||
// List<NoAuthProbe> noAuthProbes = new ArrayList<NoAuthProbe>();
|
noAuthProbes.add(noAuthProbe);
|
||||||
|
// List<NoAuthProbe> dd =
|
||||||
|
// this.noAuthProbeService.registForNoAuthProbes(noAuthProbes);
|
||||||
|
|
||||||
// noAuthProbes.add(noAuthProbe);
|
// System.out.println(dd.get(0).getId());
|
||||||
// // List<NoAuthProbe> dd = this.noAuthProbeService.registForNoAuthProbes(noAuthProbes);
|
|
||||||
|
|
||||||
// // System.out.println(dd.get(0).getId());
|
Assert.assertNotEquals(noAuthProbes.size(), 2);
|
||||||
|
|
||||||
// Assert.assertNotEquals(noAuthProbes.size(), 2);
|
}
|
||||||
|
|
||||||
// }
|
@Ignore
|
||||||
|
@Test
|
||||||
|
public void readAllByDomainID() throws Exception {
|
||||||
|
List<NoAuthProbe> probes = this.noAuthProbeService.readAllByDomainID(Long.valueOf(1));
|
||||||
|
|
||||||
// @Ignore
|
Assert.assertNotEquals(probes.size(), 0);
|
||||||
// @Test
|
|
||||||
// public void readAllByDomain() throws Exception {
|
|
||||||
|
|
||||||
// Domain domain = new Domain();
|
}
|
||||||
// domain.setId(1);
|
|
||||||
|
|
||||||
// List<NoAuthProbe> probes = this.noAuthProbeService.readAllByDomain(domain);
|
@Ignore
|
||||||
|
@Test
|
||||||
|
public void read() throws Exception {
|
||||||
|
NoAuthProbe noAuthProbe = this.noAuthProbeService.read(Long.valueOf(1));
|
||||||
|
|
||||||
// Assert.assertNotEquals(probes.size(), 0);
|
Assert.assertNotEquals(noAuthProbe, null);
|
||||||
|
}
|
||||||
|
|
||||||
// }
|
@Ignore
|
||||||
|
@Test
|
||||||
|
public void acceptProbe() throws Exception {
|
||||||
|
|
||||||
// @Ignore
|
this.noAuthProbeService.acceptNoAuthProbe(Long.valueOf(1));
|
||||||
// @Test
|
|
||||||
// public void read() throws Exception {
|
|
||||||
|
|
||||||
// NoAuthProbe noAuthProbe = this.noAuthProbeService.read(1);
|
}
|
||||||
|
|
||||||
// Assert.assertNotEquals(noAuthProbe, null);
|
@Ignore
|
||||||
// }
|
@Test
|
||||||
|
public void ssss() {
|
||||||
|
String ss = "192.168.1.106/24|fe80::36c0:6c3e:6006:dd23/64";
|
||||||
|
|
||||||
// @Ignore
|
String[] sss = ss.split("\\|");
|
||||||
// @Test
|
|
||||||
// public void acceptProbe() throws IOException {
|
|
||||||
|
|
||||||
// NoAuthProbe noAuthProbe = this.noAuthProbeService.read(1);
|
System.out.println(sss[0]);
|
||||||
|
}
|
||||||
|
|
||||||
// this.noAuthProbeService.acceptNoAuthProbe(noAuthProbe);
|
@Test
|
||||||
|
public void readByTempKey() throws Exception {
|
||||||
|
|
||||||
// }
|
NoAuthProbe noAuthProbe = this.noAuthProbeService.readByTempProbeKey("1cf2555c57d511e79714080027658d15");
|
||||||
|
|
||||||
// @Ignore
|
Assert.assertNotEquals(noAuthProbe, null);
|
||||||
// @Test
|
|
||||||
// public void ssss() {
|
|
||||||
// String ss = "192.168.1.106/24|fe80::36c0:6c3e:6006:dd23/64";
|
|
||||||
|
|
||||||
// String[] sss = ss.split("\\|");
|
}
|
||||||
|
|
||||||
// System.out.println(sss[0]);
|
@Test
|
||||||
// }
|
@Ignore
|
||||||
|
public void sendWeb() throws OverflowException {
|
||||||
|
List<NoAuthProbe> probes = this.noAuthProbeService.readAllByDomainID(Long.valueOf(1));
|
||||||
|
|
||||||
// @Test
|
messagePublisher.publishToDomainMembers(Long.valueOf(1), "NoAuthProbeService.regist", probes);
|
||||||
// public void readByTempKey() {
|
|
||||||
|
|
||||||
// NoAuthProbe noAuthProbe = this.noAuthProbeService.readByTempKey("1cf2555c57d511e79714080027658d15");
|
}
|
||||||
|
|
||||||
// Assert.assertNotEquals(noAuthProbe, null);
|
}
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
// @Ignore
|
|
||||||
// public void sendWeb() throws OverflowException {
|
|
||||||
|
|
||||||
// Domain domain = new Domain();
|
|
||||||
// domain.setId(1);
|
|
||||||
|
|
||||||
// List<NoAuthProbe> probes = this.noAuthProbeService.readAllByDomain(domain);
|
|
||||||
|
|
||||||
// messagePublisher.publishToDomainMembers(domain.getId(), "NoAuthProbeService.regist", probes);
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// }
|
|
|
@ -1,146 +1,145 @@
|
||||||
package com.loafle.overflow.central.module.target.service;
|
package com.loafle.overflow.central.module.target.service;
|
||||||
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import com.loafle.overflow.central.spring.AppConfigTest;
|
import com.loafle.overflow.central.spring.AppConfigTest;
|
||||||
|
|
||||||
import com.loafle.overflow.model.discovery.Host;
|
import com.loafle.overflow.model.discovery.Host;
|
||||||
import com.loafle.overflow.model.probe.Probe;
|
import com.loafle.overflow.model.probe.Probe;
|
||||||
import com.loafle.overflow.service.central.target.TargetDiscoveryService;
|
import com.loafle.overflow.service.central.target.TargetDiscoveryService;
|
||||||
import org.codehaus.jackson.map.DeserializationConfig;
|
import org.codehaus.jackson.map.DeserializationConfig;
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.aop.support.AopUtils;
|
import org.springframework.aop.support.AopUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.io.ResourceLoader;
|
import org.springframework.core.io.ResourceLoader;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.Date;
|
import java.util.List;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by snoop on 17. 6. 28.
|
* Created by snoop on 17. 6. 28.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes = {AppConfigTest.class})
|
@ContextConfiguration(classes = {AppConfigTest.class})
|
||||||
public class TargetDiscoveryServiceTest {
|
public class TargetDiscoveryServiceTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ResourceLoader resourceLoader;
|
private ResourceLoader resourceLoader;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TargetDiscoveryService targetDiscoveryService;
|
private TargetDiscoveryService targetDiscoveryService;
|
||||||
|
|
||||||
// @Ignore
|
// @Ignore
|
||||||
@Test
|
@Test
|
||||||
public void saveAllTarget() throws Exception {
|
public void saveAllTarget() throws Exception {
|
||||||
|
|
||||||
String json = readFileAsString(resourceLoader.getResource("classpath:2018-04-25-tds.json").getURI().getPath());
|
String json = readFileAsString(resourceLoader.getResource("classpath:2018-04-25-tds.json").getURI().getPath());
|
||||||
|
|
||||||
// Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonDateDeserializer()).create();
|
// Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonDateDeserializer()).create();
|
||||||
|
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
|
||||||
List<Host> hosts = mapper.readValue(json, mapper.getTypeFactory().constructCollectionType(List.class, Host.class));
|
List<Host> hosts = mapper.readValue(json, mapper.getTypeFactory().constructCollectionType(List.class, Host.class));
|
||||||
|
|
||||||
|
|
||||||
Probe probe = new Probe();
|
Probe probe = new Probe();
|
||||||
probe.setId(Long.valueOf(1));
|
probe.setId(Long.valueOf(1));
|
||||||
|
|
||||||
this.targetDiscoveryService.saveAllTarget(hosts, probe);
|
this.targetDiscoveryService.saveAllTarget(hosts, probe);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String readFileAsString(String filePath) throws IOException {
|
private String readFileAsString(String filePath) throws IOException {
|
||||||
StringBuffer fileData = new StringBuffer();
|
StringBuffer fileData = new StringBuffer();
|
||||||
BufferedReader reader = new BufferedReader(
|
BufferedReader reader = new BufferedReader(
|
||||||
new FileReader(filePath));
|
new FileReader(filePath));
|
||||||
char[] buf = new char[1024];
|
char[] buf = new char[1024];
|
||||||
int numRead=0;
|
int numRead=0;
|
||||||
while((numRead=reader.read(buf)) != -1){
|
while((numRead=reader.read(buf)) != -1){
|
||||||
String readData = String.valueOf(buf, 0, numRead);
|
String readData = String.valueOf(buf, 0, numRead);
|
||||||
fileData.append(readData);
|
fileData.append(readData);
|
||||||
}
|
}
|
||||||
reader.close();
|
reader.close();
|
||||||
return fileData.toString();
|
return fileData.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
public void testParam() throws NoSuchMethodException {
|
public void testParam() throws NoSuchMethodException {
|
||||||
|
|
||||||
Method m = this.targetDiscoveryService.getClass().getMethod("saveAllTarget", List.class, Probe.class);
|
Method m = this.targetDiscoveryService.getClass().getMethod("saveAllTarget", List.class, Probe.class);
|
||||||
// Method m = TargetDiscoveryService.class.getMethod("saveAllTarget", List.class, Probe.class);
|
// Method m = TargetDiscoveryService.class.getMethod("saveAllTarget", List.class, Probe.class);
|
||||||
|
|
||||||
Class<?> clazz = AopUtils.getTargetClass(this.targetDiscoveryService);
|
Class<?> clazz = AopUtils.getTargetClass(this.targetDiscoveryService);
|
||||||
Method[] ms = clazz.getMethods();
|
Method[] ms = clazz.getMethods();
|
||||||
|
|
||||||
Method sm = null;
|
Method sm = null;
|
||||||
for(Method mm : ms){
|
for(Method mm : ms){
|
||||||
if ("saveAllTarget".equals(mm.getName())) {
|
if ("saveAllTarget".equals(mm.getName())) {
|
||||||
sm = mm;
|
sm = mm;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sm != null) {
|
if (sm != null) {
|
||||||
Type[] ts = sm.getGenericParameterTypes();
|
Type[] ts = sm.getGenericParameterTypes();
|
||||||
for(Type t : ts){
|
for(Type t : ts){
|
||||||
if (t instanceof ParameterizedType) {
|
if (t instanceof ParameterizedType) {
|
||||||
ParameterizedType pt = (ParameterizedType)t;
|
ParameterizedType pt = (ParameterizedType)t;
|
||||||
System.out.println(pt.getActualTypeArguments()[0].getTypeName());
|
System.out.println(pt.getActualTypeArguments()[0].getTypeName());
|
||||||
}
|
}
|
||||||
System.out.println(t.getTypeName());
|
System.out.println(t.getTypeName());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
System.out.println(m.getName());
|
System.out.println(m.getName());
|
||||||
Type[] genericParameterTypes = m.getGenericParameterTypes();
|
Type[] genericParameterTypes = m.getGenericParameterTypes();
|
||||||
|
|
||||||
for(Type genericParameterType : genericParameterTypes){
|
for(Type genericParameterType : genericParameterTypes){
|
||||||
if(genericParameterType instanceof ParameterizedType){
|
if(genericParameterType instanceof ParameterizedType){
|
||||||
ParameterizedType aType = (ParameterizedType) genericParameterType;
|
ParameterizedType aType = (ParameterizedType) genericParameterType;
|
||||||
Type[] parameterArgTypes = aType.getActualTypeArguments();
|
Type[] parameterArgTypes = aType.getActualTypeArguments();
|
||||||
for(Type parameterArgType : parameterArgTypes){
|
for(Type parameterArgType : parameterArgTypes){
|
||||||
Class parameterArgClass = (Class) parameterArgType;
|
Class parameterArgClass = (Class) parameterArgType;
|
||||||
System.out.println("parameterArgClass = " + parameterArgClass);
|
System.out.println("parameterArgClass = " + parameterArgClass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
public void testName() throws ClassNotFoundException {
|
public void testName() throws ClassNotFoundException {
|
||||||
|
|
||||||
Object o = this.targetDiscoveryService;
|
Object o = this.targetDiscoveryService;
|
||||||
|
|
||||||
String nnn = o.getClass().getSimpleName();
|
String nnn = o.getClass().getSimpleName();
|
||||||
System.out.println(nnn);
|
System.out.println(nnn);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user