From 42842489f25a4753c229340d989bf40e5caf0057 Mon Sep 17 00:00:00 2001 From: insanity Date: Wed, 23 Aug 2017 10:40:46 +0900 Subject: [PATCH] probe service --- .../noauthprobe/service/NoAuthProbeService.java | 17 ++++++++++++----- .../module/probe/service/ProbeService.java | 5 ++++- 2 files changed, 16 insertions(+), 6 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 f8b391a..1fe3a87 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 @@ -9,9 +9,12 @@ import com.loafle.overflow.module.noauthprobe.model.NoAuthProbe; import com.loafle.overflow.module.probe.model.Probe; import com.loafle.overflow.module.probe.service.ProbeService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; +import java.util.UUID; /** * Created by snoop on 17. 6. 28. @@ -30,6 +33,7 @@ public class NoAuthProbeService { return this.noAuthProbeDAO.save(noAuthProbe); } + public List readAllByDomain(Domain domain) { return this.noAuthProbeDAO.findAllByDomain(domain); @@ -41,13 +45,15 @@ public class NoAuthProbeService { public List acceptNoAuthProbes(List noAuthProbes) { - // Todo encryption key generation & probe key generation - // Todo domain injection & member injection -// List resProbe = new ArrayList<>(); + List probes = new ArrayList<>(); Probe probe = null; for (NoAuthProbe noAuth : noAuthProbes) { + BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); + String key = passwordEncoder.encode(UUID.randomUUID().toString()); + probe = new Probe(); + probe.setEncryptionKey(key); probe.setProbeKey(noAuth.getApiKey()); probe.setDomain(new Domain(1)); probe.setAuthorizeMember(new Member(1)); @@ -57,11 +63,12 @@ public class NoAuthProbeService { probe.setEncryptionKey("111"); probe.setDisplayName(noAuth.getHostName()+"'s probe"); -// resprobe.add(probe); - this.probeService.regist(probe); + probes.add(probe); noAuth.setStatus(new MetaNoAuthProbeStatus((short) 1)); } + + this.probeService.regist(probes); this.noAuthProbeDAO.save(noAuthProbes); return this.readAllByDomain(noAuthProbes.get(0).getDomain()); } diff --git a/src/main/java/com/loafle/overflow/module/probe/service/ProbeService.java b/src/main/java/com/loafle/overflow/module/probe/service/ProbeService.java index 96ca37c..7954d18 100644 --- a/src/main/java/com/loafle/overflow/module/probe/service/ProbeService.java +++ b/src/main/java/com/loafle/overflow/module/probe/service/ProbeService.java @@ -21,8 +21,11 @@ public class ProbeService { return this.probeDAO.save(probe); } - public List readAllByDomain(Domain domain) { + public List regist(List probes) { + return this.probeDAO.save(probes); + } + public List readAllByDomain(Domain domain) { return this.probeDAO.findAllByDomainOrderByIdDesc(domain); }