noauth probe accept/deny

This commit is contained in:
insanity 2017-09-25 19:03:21 +09:00
parent 479f70cec9
commit f1fe82755a

View File

@ -17,7 +17,10 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/** /**
* Created by snoop on 17. 6. 28. * Created by snoop on 17. 6. 28.
@ -58,60 +61,49 @@ public class NoAuthProbeService {
return this.noAuthProbeDAO.findOne(id); return this.noAuthProbeDAO.findOne(id);
} }
public List<NoAuthProbe> acceptNoAuthProbes(List<NoAuthProbe> noAuthProbes) throws IOException { public List<NoAuthProbe> acceptNoAuthProbe(NoAuthProbe noAuthProbe) throws IOException {
// Todo domain injection & member injection // Todo domain injection & member injection
List<Probe> probes = new ArrayList<>();
Probe probe = null;
Map<String, Object> objMap = null;
Map<String, String> hostMap = null;
Map<String, String> netMap = null;
for (NoAuthProbe noAuth : noAuthProbes) { BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); String encryptKey = passwordEncoder.encode(UUID.randomUUID().toString());
String encryptKey = passwordEncoder.encode(UUID.randomUUID().toString());
probe = new Probe(); Probe probe = new Probe();
probe.setEncryptionKey(encryptKey); probe.setEncryptionKey(encryptKey);
probe.setProbeKey(noAuth.getApiKey()); probe.setProbeKey(noAuthProbe.getApiKey());
probe.setDomain(new Domain(1)); probe.setDomain(new Domain(1));
probe.setAuthorizeMember(new Member(1)); probe.setAuthorizeMember(new Member(1));
probe.setStatus(new MetaProbeStatus((short)1)); probe.setStatus(new MetaProbeStatus((short)1));
probe.setTargetCount(0); probe.setTargetCount(0);
probe.setSensorCount(0); probe.setSensorCount(0);
objMap = this.objectMapper.readValue(noAuth.getDescription(), new TypeReference<HashMap<String,Object>>() {}); Map<String, Object> objMap = this.objectMapper.readValue(noAuthProbe.getDescription(), new TypeReference<HashMap<String,Object>>() {});
hostMap = (Map<String, String>)objMap.get("host"); Map<String, String> hostMap = (Map<String, String>)objMap.get("host");
netMap = (Map<String, String>)objMap.get("network"); Map<String, String> netMap = (Map<String, String>)objMap.get("network");
// String dispName = noAuth.getHostName().isEmpty() ? // String dispName = noAuth.getHostName().isEmpty() ?
// StringConvertor.intToIp(noAuth.getIpAddress()) : noAuth.getHostName(); // StringConvertor.intToIp(noAuth.getIpAddress()) : noAuth.getHostName();
String dispName = hostMap.get("name"); String dispName = hostMap.get("name");
dispName += " probe"; dispName += " probe";
probe.setDisplayName(dispName); probe.setDisplayName(dispName);
String addrStr = netMap.get("address"); String addrStr = netMap.get("address");
String[] addrArr = addrStr.split("\\|"); String[] addrArr = addrStr.split("\\|");
System.out.println(addrArr); probe.setCidr(addrArr[0]);
probe.setCidr(addrArr[0]); noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 1));
probes.add(probe); this.probeService.regist(probe);
noAuth.setStatus(new MetaNoAuthProbeStatus((short) 1)); this.noAuthProbeDAO.save(noAuthProbe);
} return this.readAllByDomain(noAuthProbe.getDomain());
this.probeService.regist(probes);
this.noAuthProbeDAO.save(noAuthProbes);
return this.readAllByDomain(noAuthProbes.get(0).getDomain());
} }
public List<NoAuthProbe> denyNoauthProbes(List<NoAuthProbe> noAuthProbes) { public List<NoAuthProbe> denyNoauthProbe(NoAuthProbe noAuthProbe) {
for (NoAuthProbe noAuth : noAuthProbes) noAuth.setStatus(new MetaNoAuthProbeStatus((short) 2)); this.noAuthProbeDAO.save(noAuthProbe);
this.noAuthProbeDAO.save(noAuthProbes); return this.readAllByDomain(noAuthProbe.getDomain());
return this.readAllByDomain(noAuthProbes.get(0).getDomain());
} }
public NoAuthProbe readByTempKey(String tempKey) { public NoAuthProbe readByTempKey(String tempKey) {