This commit is contained in:
crusader 2018-05-24 19:35:57 +09:00
parent 31fd84e984
commit 58bddae263
4 changed files with 379 additions and 363 deletions

28
.vscode/launch.test.json vendored Normal file
View 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": ""
}
]
}
}

View File

@ -51,190 +51,189 @@ import javax.transaction.Transactional;
@Service("NoAuthProbeService")
public class CentralNoAuthProbeService implements NoAuthProbeService {
@Autowired
private NoAuthProbeDAO noAuthProbeDAO;
@Autowired
private NoAuthProbeDAO noAuthProbeDAO;
@Autowired
private ApiKeyService apiKeyService;
@Autowired
private ApiKeyService apiKeyService;
@Autowired
private ProbeService probeService;
@Autowired
private ProbeService probeService;
@Autowired
private MessagePublisher messagePublisher;
@Autowired
private MessagePublisher messagePublisher;
@Autowired
private DomainMemberService domainMemberService;
@Autowired
private DomainMemberService domainMemberService;
@Autowired
private ObjectMapper objectMapper;
@Autowired
private ObjectMapper objectMapper;
@Autowired
private InfraMachineService infraMachineService;
@Autowired
private InfraOSService infraOSService;
@Autowired
private InfraHostService infraHostService;
@Autowired
private ProbeHostService probeHostService;
@Autowired
private InfraMachineService infraMachineService;
@Autowired
private InfraOSService infraOSService;
@Autowired
private InfraHostService infraHostService;
@Autowired
private ProbeHostService probeHostService;
@ProbeAPI
public NoAuthProbe regist(NoAuthProbe noAuthProbe) throws OverflowException {
@ProbeAPI
public NoAuthProbe regist(NoAuthProbe noAuthProbe) throws OverflowException {
ApiKey apiKey = apiKeyService.readByApiKey(noAuthProbe.getApiKey());
noAuthProbe.setDomain(apiKey.getDomain());
ApiKey apiKey = apiKeyService.readByApiKey(noAuthProbe.getApiKey());
noAuthProbe.setDomain(apiKey.getDomain());
noAuthProbe.setTempProbeKey(GenerateKey.getKey());
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 3));
noAuthProbe.setTempProbeKey(GenerateKey.getKey());
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) {
return this.noAuthProbeDAO.findOne(id);
}
messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Accept", probe.getProbeKey());
@WebappAPI
@Transactional
public List<NoAuthProbe> acceptNoAuthProbe(Long noAuthProbeID) throws OverflowException {
NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findOne(noAuthProbeID);
return this.readAllByDomainID(noAuthProbe.getDomain().getId());
}
NoAuthProbeDescription noAuthProbeDescription = null;
try {
noAuthProbeDescription = this.objectMapper.readValue(noAuthProbe.getDescription(), NoAuthProbeDescription.class);
} catch (IOException e) {
throw new OverflowException("json error", e);
}
private Probe newProbe(NoAuthProbe noauthprobe, NoAuthProbeDescription noAuthProbeDescription) 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);
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String encryptKey = passwordEncoder.encode(UUID.randomUUID().toString());
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 1));
this.noAuthProbeDAO.save(noAuthProbe);
ApiKey apiKey = apiKeyService.readByApiKey(noauthprobe.getApiKey());
String memberEmail = SessionMetadata.getTargetID();
DomainMember domainMember = domainMemberService.readByMemberEmail(memberEmail);
messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Accept",
probe.getProbeKey());
Probe probe = new Probe();
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();
String encryptKey = passwordEncoder.encode(UUID.randomUUID().toString());
return this.probeService.regist(probe);
}
ApiKey apiKey = apiKeyService.readByApiKey(noauthprobe.getApiKey());
String memberEmail = SessionMetadata.getTargetID();
DomainMember domainMember = domainMemberService.readByMemberEmail(memberEmail);
private InfraMachine newInfraMachine(NoAuthProbe noauthprobe) throws OverflowException {
MetaInfraType infraType = new MetaInfraType();
infraType.setId(1);
Probe probe = new Probe();
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));
InfraMachine infraMachine = new InfraMachine();
infraMachine.setMeta(noauthprobe.getDescription());
infraMachine.setInfraType(infraType);
String dispName = noAuthProbeDescription.getHost().getName();
dispName += " probe";
probe.setDisplayName(dispName);
return this.infraMachineService.regist(infraMachine);
}
String addrStr = noAuthProbeDescription.getNetwork().getAddress();
String[] addrArr = addrStr.split("\\|");
probe.setCidr(addrArr[0]);
private InfraOS newInfraOS(InfraMachine infraMachine, NoAuthProbeDescriptionHost noAuthProbeDescriptionHost) throws OverflowException {
MetaInfraType infraType = new MetaInfraType();
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 {
MetaInfraType infraType = new MetaInfraType();
infraType.setId(1);
return this.infraOSService.regist(infraOS);
}
InfraMachine infraMachine = new InfraMachine();
infraMachine.setMeta(noauthprobe.getDescription());
infraMachine.setInfraType(infraType);
private InfraHost newInfraHost(InfraOS infraOS, NoAuthProbeDescriptionNetwork noAuthProbeDescriptionNetwork) throws OverflowException {
MetaInfraType infraType = new MetaInfraType();
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 {
MetaInfraType infraType = new MetaInfraType();
infraType.setId(3);
infraHost.setIpv4(addrArr[0]);
infraHost.setMac(noAuthProbeDescriptionNetwork.getMacAddress());
infraHost.setOs(infraOS);
infraHost.setInfraType(infraType);
InfraOS infraOS = new InfraOS();
infraOS.setMachine(infraMachine);
infraOS.setInfraType(infraType);
infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(noAuthProbeDescriptionHost.getOS()));
return this.infraHostService.regist(infraHost);
}
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 {
MetaInfraType infraType = new MetaInfraType();
infraType.setId(2);
this.probeHostService.regist(probeHost);
}
InfraHost infraHost = new InfraHost();
String addrStr = noAuthProbeDescriptionNetwork.getAddress();
String[] addrArr = addrStr.split("\\|");
@WebappAPI
public List<NoAuthProbe> denyNoauthProbe(Long noAuthProbeID) throws OverflowException {
NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findOne(noAuthProbeID);
infraHost.setIpv4(addrArr[0]);
infraHost.setMac(noAuthProbeDescriptionNetwork.getMacAddress());
infraHost.setOs(infraOS);
infraHost.setInfraType(infraType);
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 2));
this.noAuthProbeDAO.save(noAuthProbe);
return this.infraHostService.regist(infraHost);
}
messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Deny");
private void newProbeHost(InfraHost infraHost, Probe probe) throws OverflowException {
ProbeHost probeHost = new ProbeHost();
probeHost.setHost(infraHost);
probeHost.setProbe(probe);
return this.readAllByDomainID(noAuthProbe.getDomain().getId());
}
this.probeHostService.regist(probeHost);
}
public NoAuthProbe readByTempProbeKey(String tempKey) throws OverflowException {
return this.noAuthProbeDAO.findByTempProbeKey(tempKey);
}
@WebappAPI
public List<NoAuthProbe> denyNoauthProbe(Long noAuthProbeID) throws OverflowException {
NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findOne(noAuthProbeID);
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);
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 2));
this.noAuthProbeDAO.save(noAuthProbe);
messagePublisher.publishToDomainMembers(noAuthProbe.getDomain().getId(), "NoAuthProbeService.onConnect", 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());
}
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);
}
messagePublisher.publishToDomainMembers(noAuthProbe.getDomain().getId(), "NoAuthProbeService.onDisconnect", noAuthProbe);
}
}

View File

@ -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.spring.AppConfigTest;
// import com.loafle.overflow.core.exception.OverflowException;
// import com.loafle.overflow.model.domain.Domain;
// import com.loafle.overflow.model.meta.MetaNoAuthProbeStatus;
// import com.loafle.overflow.model.noauthprobe.NoAuthProbe;
// import com.loafle.overflow.service.central.noauthprobe.NoAuthProbeService;
import com.loafle.overflow.central.commons.service.MessagePublisher;
import com.loafle.overflow.central.spring.AppConfigTest;
import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.domain.Domain;
import com.loafle.overflow.model.meta.MetaNoAuthProbeStatus;
import com.loafle.overflow.model.noauthprobe.NoAuthProbe;
import com.loafle.overflow.service.central.noauthprobe.NoAuthProbeService;
// import org.junit.Assert;
// import org.junit.Ignore;
// import org.junit.Test;
// import org.junit.runner.RunWith;
// import org.springframework.beans.factory.annotation.Autowired;
// import org.springframework.test.context.ContextConfiguration;
// import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
// import java.io.IOException;
// import java.util.ArrayList;
// import java.util.List;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
// /**
// * Created by snoop on 17. 6. 28.
// */
// @RunWith(SpringJUnit4ClassRunner.class)
// @ContextConfiguration(classes = {AppConfigTest.class})
// public class NoAuthProbeServiceTest {
/**
* Created by snoop on 17. 6. 28.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { AppConfigTest.class })
public class NoAuthProbeServiceTest {
// @Autowired
// private NoAuthProbeService noAuthProbeService;
@Autowired
private CentralNoAuthProbeService noAuthProbeService;
// @Autowired
// private MessagePublisher messagePublisher;
@Autowired
private MessagePublisher messagePublisher;
// @Ignore
// @Test
// public void regist() throws Exception {
@Ignore
@Test
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.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");
// noAuthProbe.setApiKey("52abd6fd57e511e7ac52080027658d13");
MetaNoAuthProbeStatus metaNoAuthProbeStatus = new MetaNoAuthProbeStatus();
metaNoAuthProbeStatus.setId((short) 3);
// MetaNoAuthProbeStatus metaNoAuthProbeStatus = new MetaNoAuthProbeStatus();
// metaNoAuthProbeStatus.setId((short)3);
noAuthProbe.setStatus(metaNoAuthProbeStatus);
noAuthProbe.setTempProbeKey("ac7f252b5bc811e784ad080027658d13");
// noAuthProbe.setStatus(metaNoAuthProbeStatus);
// noAuthProbe.setTempProbeKey("ac7f252b5bc811e784ad080027658d13");
Domain d = new Domain();
d.setId(Long.valueOf(1));
noAuthProbe.setDomain(d);
// Domain d = new Domain();
// d.setId(1);
// noAuthProbe.setDomain(d);
this.noAuthProbeService.regist(noAuthProbe);
// this.noAuthProbeService.regist(noAuthProbe);
Assert.assertNotEquals(noAuthProbe.getId().longValue(), 0);
// Assert.assertNotEquals(noAuthProbe.getId(), 0);
}
// }
@Ignore
@Test
public void registForNoAuthProbes() throws Exception {
// @Ignore
// @Test
// public void registForNoAuthProbes() throws Exception {
NoAuthProbe noAuthProbe = new NoAuthProbe();
// 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");
// // 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");
MetaNoAuthProbeStatus metaNoAuthProbeStatus = new MetaNoAuthProbeStatus();
metaNoAuthProbeStatus.setId((short) 3);
// MetaNoAuthProbeStatus metaNoAuthProbeStatus = new MetaNoAuthProbeStatus();
// metaNoAuthProbeStatus.setId((short)3);
noAuthProbe.setStatus(metaNoAuthProbeStatus);
noAuthProbe.setTempProbeKey("a1c7f252b5bc811e784ad080027658d13");
// noAuthProbe.setStatus(metaNoAuthProbeStatus);
// noAuthProbe.setTempProbeKey("a1c7f252b5bc811e784ad080027658d13");
Domain d = new Domain();
d.setId(Long.valueOf(1));
noAuthProbe.setDomain(d);
// Domain d = new Domain();
// d.setId(1);
// noAuthProbe.setDomain(d);
List<NoAuthProbe> noAuthProbes = new ArrayList<NoAuthProbe>();
// List<NoAuthProbe> noAuthProbes = new ArrayList<NoAuthProbe>();
noAuthProbes.add(noAuthProbe);
// List<NoAuthProbe> dd =
// this.noAuthProbeService.registForNoAuthProbes(noAuthProbes);
// noAuthProbes.add(noAuthProbe);
// // List<NoAuthProbe> dd = this.noAuthProbeService.registForNoAuthProbes(noAuthProbes);
// System.out.println(dd.get(0).getId());
// // 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
// @Test
// public void readAllByDomain() throws Exception {
Assert.assertNotEquals(probes.size(), 0);
// 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
// @Test
// public void read() throws Exception {
this.noAuthProbeService.acceptNoAuthProbe(Long.valueOf(1));
// 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
// @Test
// public void acceptProbe() throws IOException {
String[] sss = ss.split("\\|");
// 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
// @Test
// public void ssss() {
// String ss = "192.168.1.106/24|fe80::36c0:6c3e:6006:dd23/64";
Assert.assertNotEquals(noAuthProbe, null);
// 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
// public void readByTempKey() {
messagePublisher.publishToDomainMembers(Long.valueOf(1), "NoAuthProbeService.regist", probes);
// 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);
// }
// }
}

View File

@ -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.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.loafle.overflow.central.spring.AppConfigTest;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.loafle.overflow.central.spring.AppConfigTest;
import com.loafle.overflow.model.discovery.Host;
import com.loafle.overflow.model.probe.Probe;
import com.loafle.overflow.service.central.target.TargetDiscoveryService;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ResourceLoader;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.loafle.overflow.model.discovery.Host;
import com.loafle.overflow.model.probe.Probe;
import com.loafle.overflow.service.central.target.TargetDiscoveryService;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ResourceLoader;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Date;
import java.util.List;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
/**
* Created by snoop on 17. 6. 28.
*/
/**
* Created by snoop on 17. 6. 28.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {AppConfigTest.class})
public class TargetDiscoveryServiceTest {
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {AppConfigTest.class})
public class TargetDiscoveryServiceTest {
@Autowired
private ResourceLoader resourceLoader;
@Autowired
private ResourceLoader resourceLoader;
@Autowired
private TargetDiscoveryService targetDiscoveryService;
@Autowired
private TargetDiscoveryService targetDiscoveryService;
// @Ignore
@Test
public void saveAllTarget() throws Exception {
@Test
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();
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.setId(Long.valueOf(1));
Probe probe = new Probe();
probe.setId(Long.valueOf(1));
this.targetDiscoveryService.saveAllTarget(hosts, probe);
}
this.targetDiscoveryService.saveAllTarget(hosts, probe);
}
private String readFileAsString(String filePath) throws IOException {
StringBuffer fileData = new StringBuffer();
BufferedReader reader = new BufferedReader(
new FileReader(filePath));
char[] buf = new char[1024];
int numRead=0;
while((numRead=reader.read(buf)) != -1){
String readData = String.valueOf(buf, 0, numRead);
fileData.append(readData);
}
reader.close();
return fileData.toString();
}
private String readFileAsString(String filePath) throws IOException {
StringBuffer fileData = new StringBuffer();
BufferedReader reader = new BufferedReader(
new FileReader(filePath));
char[] buf = new char[1024];
int numRead=0;
while((numRead=reader.read(buf)) != -1){
String readData = String.valueOf(buf, 0, numRead);
fileData.append(readData);
}
reader.close();
return fileData.toString();
}
@Ignore
@Test
public void testParam() throws NoSuchMethodException {
@Ignore
@Test
public void testParam() throws NoSuchMethodException {
Method m = this.targetDiscoveryService.getClass().getMethod("saveAllTarget", List.class, Probe.class);
// Method m = TargetDiscoveryService.class.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);
Class<?> clazz = AopUtils.getTargetClass(this.targetDiscoveryService);
Method[] ms = clazz.getMethods();
Class<?> clazz = AopUtils.getTargetClass(this.targetDiscoveryService);
Method[] ms = clazz.getMethods();
Method sm = null;
for(Method mm : ms){
if ("saveAllTarget".equals(mm.getName())) {
sm = mm;
break;
}
}
Method sm = null;
for(Method mm : ms){
if ("saveAllTarget".equals(mm.getName())) {
sm = mm;
break;
}
}
if (sm != null) {
Type[] ts = sm.getGenericParameterTypes();
for(Type t : ts){
if (t instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType)t;
System.out.println(pt.getActualTypeArguments()[0].getTypeName());
}
System.out.println(t.getTypeName());
if (sm != null) {
Type[] ts = sm.getGenericParameterTypes();
for(Type t : ts){
if (t instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType)t;
System.out.println(pt.getActualTypeArguments()[0].getTypeName());
}
System.out.println(t.getTypeName());
}
}
}
}
System.out.println(m.getName());
Type[] genericParameterTypes = m.getGenericParameterTypes();
System.out.println(m.getName());
Type[] genericParameterTypes = m.getGenericParameterTypes();
for(Type genericParameterType : genericParameterTypes){
if(genericParameterType instanceof ParameterizedType){
ParameterizedType aType = (ParameterizedType) genericParameterType;
Type[] parameterArgTypes = aType.getActualTypeArguments();
for(Type parameterArgType : parameterArgTypes){
Class parameterArgClass = (Class) parameterArgType;
System.out.println("parameterArgClass = " + parameterArgClass);
}
}
}
}
for(Type genericParameterType : genericParameterTypes){
if(genericParameterType instanceof ParameterizedType){
ParameterizedType aType = (ParameterizedType) genericParameterType;
Type[] parameterArgTypes = aType.getActualTypeArguments();
for(Type parameterArgType : parameterArgTypes){
Class parameterArgClass = (Class) parameterArgType;
System.out.println("parameterArgClass = " + parameterArgClass);
}
}
}
}
@Ignore
@Test
public void testName() throws ClassNotFoundException {
@Ignore
@Test
public void testName() throws ClassNotFoundException {
Object o = this.targetDiscoveryService;
Object o = this.targetDiscoveryService;
String nnn = o.getClass().getSimpleName();
System.out.println(nnn);
String nnn = o.getClass().getSimpleName();
System.out.println(nnn);
}
}
}
}