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 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.
@ -58,60 +61,49 @@ public class NoAuthProbeService {
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
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();
String encryptKey = passwordEncoder.encode(UUID.randomUUID().toString());
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String encryptKey = passwordEncoder.encode(UUID.randomUUID().toString());
probe = new Probe();
probe.setEncryptionKey(encryptKey);
probe.setProbeKey(noAuth.getApiKey());
probe.setDomain(new Domain(1));
probe.setAuthorizeMember(new Member(1));
probe.setStatus(new MetaProbeStatus((short)1));
probe.setTargetCount(0);
probe.setSensorCount(0);
Probe probe = new Probe();
probe.setEncryptionKey(encryptKey);
probe.setProbeKey(noAuthProbe.getApiKey());
probe.setDomain(new Domain(1));
probe.setAuthorizeMember(new Member(1));
probe.setStatus(new MetaProbeStatus((short)1));
probe.setTargetCount(0);
probe.setSensorCount(0);
objMap = this.objectMapper.readValue(noAuth.getDescription(), new TypeReference<HashMap<String,Object>>() {});
hostMap = (Map<String, String>)objMap.get("host");
netMap = (Map<String, String>)objMap.get("network");
Map<String, Object> objMap = this.objectMapper.readValue(noAuthProbe.getDescription(), new TypeReference<HashMap<String,Object>>() {});
Map<String, String> hostMap = (Map<String, String>)objMap.get("host");
Map<String, String> netMap = (Map<String, String>)objMap.get("network");
// String dispName = noAuth.getHostName().isEmpty() ?
// StringConvertor.intToIp(noAuth.getIpAddress()) : noAuth.getHostName();
String dispName = hostMap.get("name");
dispName += " probe";
probe.setDisplayName(dispName);
String dispName = hostMap.get("name");
dispName += " probe";
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);
noAuth.setStatus(new MetaNoAuthProbeStatus((short) 1));
}
this.probeService.regist(probes);
this.noAuthProbeDAO.save(noAuthProbes);
return this.readAllByDomain(noAuthProbes.get(0).getDomain());
this.probeService.regist(probe);
this.noAuthProbeDAO.save(noAuthProbe);
return this.readAllByDomain(noAuthProbe.getDomain());
}
public List<NoAuthProbe> denyNoauthProbes(List<NoAuthProbe> noAuthProbes) {
for (NoAuthProbe noAuth : noAuthProbes) noAuth.setStatus(new MetaNoAuthProbeStatus((short) 2));
this.noAuthProbeDAO.save(noAuthProbes);
return this.readAllByDomain(noAuthProbes.get(0).getDomain());
public List<NoAuthProbe> denyNoauthProbe(NoAuthProbe noAuthProbe) {
this.noAuthProbeDAO.save(noAuthProbe);
return this.readAllByDomain(noAuthProbe.getDomain());
}
public NoAuthProbe readByTempKey(String tempKey) {