From f1fe82755a1dbbb26e5ebe7868fef732729006c3 Mon Sep 17 00:00:00 2001 From: insanity Date: Mon, 25 Sep 2017 19:03:21 +0900 Subject: [PATCH] noauth probe accept/deny --- .../service/NoAuthProbeService.java | 70 ++++++++----------- 1 file changed, 31 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/loafle/overflow/module/noauthprobe/service/NoAuthProbeService.java b/src/main/java/com/loafle/overflow/module/noauthprobe/service/NoAuthProbeService.java index 057735f..5e05d20 100644 --- a/src/main/java/com/loafle/overflow/module/noauthprobe/service/NoAuthProbeService.java +++ b/src/main/java/com/loafle/overflow/module/noauthprobe/service/NoAuthProbeService.java @@ -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 acceptNoAuthProbes(List noAuthProbes) throws IOException { + public List acceptNoAuthProbe(NoAuthProbe noAuthProbe) throws IOException { // Todo domain injection & member injection - List probes = new ArrayList<>(); - Probe probe = null; - Map objMap = null; - Map hostMap = null; - Map 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>() {}); - hostMap = (Map)objMap.get("host"); - netMap = (Map)objMap.get("network"); + Map objMap = this.objectMapper.readValue(noAuthProbe.getDescription(), new TypeReference>() {}); + Map hostMap = (Map)objMap.get("host"); + Map netMap = (Map)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 denyNoauthProbes(List noAuthProbes) { - for (NoAuthProbe noAuth : noAuthProbes) noAuth.setStatus(new MetaNoAuthProbeStatus((short) 2)); - this.noAuthProbeDAO.save(noAuthProbes); - return this.readAllByDomain(noAuthProbes.get(0).getDomain()); + public List denyNoauthProbe(NoAuthProbe noAuthProbe) { + this.noAuthProbeDAO.save(noAuthProbe); + return this.readAllByDomain(noAuthProbe.getDomain()); } public NoAuthProbe readByTempKey(String tempKey) {