noauthprobe authorization with infras
This commit is contained in:
parent
548ed630b9
commit
8693503077
|
@ -7,20 +7,34 @@ import com.loafle.overflow.central.commons.stereotype.ProbeAPI;
|
||||||
import com.loafle.overflow.central.commons.stereotype.WebappAPI;
|
import com.loafle.overflow.central.commons.stereotype.WebappAPI;
|
||||||
import com.loafle.overflow.central.commons.utils.GenerateKey;
|
import com.loafle.overflow.central.commons.utils.GenerateKey;
|
||||||
import com.loafle.overflow.central.commons.utils.SessionMetadata;
|
import com.loafle.overflow.central.commons.utils.SessionMetadata;
|
||||||
|
import com.loafle.overflow.central.commons.utils.StringConvertor;
|
||||||
|
import com.loafle.overflow.central.module.infra.service.CentralInfraMachineService;
|
||||||
|
import com.loafle.overflow.central.module.infra.service.CentralInfraOSService;
|
||||||
import com.loafle.overflow.central.module.noauthprobe.dao.NoAuthProbeDAO;
|
import com.loafle.overflow.central.module.noauthprobe.dao.NoAuthProbeDAO;
|
||||||
import com.loafle.overflow.core.exception.OverflowException;
|
import com.loafle.overflow.core.exception.OverflowException;
|
||||||
import com.loafle.overflow.model.apikey.ApiKey;
|
import com.loafle.overflow.model.apikey.ApiKey;
|
||||||
import com.loafle.overflow.model.domain.Domain;
|
import com.loafle.overflow.model.domain.Domain;
|
||||||
import com.loafle.overflow.model.domain.DomainMember;
|
import com.loafle.overflow.model.domain.DomainMember;
|
||||||
|
import com.loafle.overflow.model.infra.InfraHost;
|
||||||
|
import com.loafle.overflow.model.infra.InfraMachine;
|
||||||
|
import com.loafle.overflow.model.infra.InfraOS;
|
||||||
import com.loafle.overflow.model.member.Member;
|
import com.loafle.overflow.model.member.Member;
|
||||||
|
import com.loafle.overflow.model.meta.MetaInfraType;
|
||||||
|
import com.loafle.overflow.model.meta.MetaInfraVendor;
|
||||||
import com.loafle.overflow.model.meta.MetaNoAuthProbeStatus;
|
import com.loafle.overflow.model.meta.MetaNoAuthProbeStatus;
|
||||||
import com.loafle.overflow.model.meta.MetaProbeStatus;
|
import com.loafle.overflow.model.meta.MetaProbeStatus;
|
||||||
import com.loafle.overflow.model.noauthprobe.NoAuthProbe;
|
import com.loafle.overflow.model.noauthprobe.NoAuthProbe;
|
||||||
import com.loafle.overflow.model.probe.Probe;
|
import com.loafle.overflow.model.probe.Probe;
|
||||||
|
import com.loafle.overflow.model.probe.ProbeHost;
|
||||||
import com.loafle.overflow.service.central.apikey.ApiKeyService;
|
import com.loafle.overflow.service.central.apikey.ApiKeyService;
|
||||||
import com.loafle.overflow.service.central.domain.DomainMemberService;
|
import com.loafle.overflow.service.central.domain.DomainMemberService;
|
||||||
|
import com.loafle.overflow.service.central.infra.InfraHostService;
|
||||||
|
import com.loafle.overflow.service.central.infra.InfraMachineService;
|
||||||
|
import com.loafle.overflow.service.central.infra.InfraOSService;
|
||||||
import com.loafle.overflow.service.central.noauthprobe.NoAuthProbeService;
|
import com.loafle.overflow.service.central.noauthprobe.NoAuthProbeService;
|
||||||
|
import com.loafle.overflow.service.central.probe.ProbeHostService;
|
||||||
import com.loafle.overflow.service.central.probe.ProbeService;
|
import com.loafle.overflow.service.central.probe.ProbeService;
|
||||||
|
import com.sun.jna.platform.win32.Variant.VARIANT._VARIANT.__VARIANT;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
@ -31,11 +45,13 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by snoop on 17. 6. 28.
|
* Created by snoop on 17. 6. 28.
|
||||||
*/
|
*/
|
||||||
@Service("NoAuthProbeService")
|
@Service("NoAuthProbeService")
|
||||||
public class CentralNoAuthProbeService implements NoAuthProbeService{
|
public class CentralNoAuthProbeService implements NoAuthProbeService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private NoAuthProbeDAO noAuthProbeDAO;
|
private NoAuthProbeDAO noAuthProbeDAO;
|
||||||
|
@ -54,22 +70,30 @@ public class CentralNoAuthProbeService implements NoAuthProbeService{
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private Gson gson;
|
private Gson gson;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private InfraMachineService infraMachineService;
|
||||||
|
@Autowired
|
||||||
|
private InfraOSService infraOSService;
|
||||||
|
@Autowired
|
||||||
|
private InfraHostService infraHostService;
|
||||||
|
@Autowired
|
||||||
|
private ProbeHostService probeHostService;
|
||||||
|
|
||||||
@ProbeAPI
|
@ProbeAPI
|
||||||
public NoAuthProbe regist(NoAuthProbe noAuthProbe) throws OverflowException{
|
public NoAuthProbe regist(NoAuthProbe noAuthProbe) throws OverflowException {
|
||||||
|
|
||||||
ApiKey apiKey = apiKeyService.readByApiKey(noAuthProbe.getApiKey());
|
ApiKey apiKey = apiKeyService.readByApiKey(noAuthProbe.getApiKey());
|
||||||
noAuthProbe.setDomain(apiKey.getDomain());
|
noAuthProbe.setDomain(apiKey.getDomain());
|
||||||
|
|
||||||
noAuthProbe.setTempProbeKey(GenerateKey.getKey());
|
noAuthProbe.setTempProbeKey(GenerateKey.getKey());
|
||||||
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short)3));
|
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> readAllByDomain(Domain domain) throws OverflowException {
|
public List<NoAuthProbe> readAllByDomain(Domain domain) throws OverflowException {
|
||||||
|
|
||||||
return this.noAuthProbeDAO.findAllByDomain(domain);
|
return this.noAuthProbeDAO.findAllByDomain(domain);
|
||||||
|
@ -80,47 +104,101 @@ public class CentralNoAuthProbeService implements NoAuthProbeService{
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebappAPI
|
@WebappAPI
|
||||||
|
@Transactional
|
||||||
public List<NoAuthProbe> acceptNoAuthProbe(NoAuthProbe noAuthProbe) throws OverflowException {
|
public List<NoAuthProbe> acceptNoAuthProbe(NoAuthProbe noAuthProbe) throws OverflowException {
|
||||||
String memberEmail = SessionMetadata.getTargetID();
|
|
||||||
|
|
||||||
// Todo domain injection & member injection
|
HashMap<String, Object> objMap = this.gson.fromJson(noAuthProbe.getDescription(),
|
||||||
|
TypeToken.getParameterized(HashMap.class, String.class, Object.class).getType());
|
||||||
|
Map<String, String> hostMap = (Map<String, String>) objMap.get("host");
|
||||||
|
Map<String, String> netMap = (Map<String, String>) objMap.get("network");
|
||||||
|
|
||||||
|
Probe probe = this.newProbe(noAuthProbe, hostMap, netMap);
|
||||||
|
InfraMachine machine = this.newInfraMachine(noAuthProbe);
|
||||||
|
InfraOS os = this.newInfraOS(machine, hostMap);
|
||||||
|
InfraHost host = this.newInfraHost(os, netMap);
|
||||||
|
this.newProbeHost(host, probe);
|
||||||
|
|
||||||
|
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 1));
|
||||||
|
this.noAuthProbeDAO.save(noAuthProbe);
|
||||||
|
|
||||||
|
messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Accept",
|
||||||
|
probe.getProbeKey());
|
||||||
|
|
||||||
|
return this.readAllByDomain(noAuthProbe.getDomain());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Probe newProbe(NoAuthProbe noauthprobe, Map<String, String> hostMap, Map<String, String> netMap) throws OverflowException {
|
||||||
|
|
||||||
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||||
String encryptKey = passwordEncoder.encode(UUID.randomUUID().toString());
|
String encryptKey = passwordEncoder.encode(UUID.randomUUID().toString());
|
||||||
|
|
||||||
ApiKey apiKey = apiKeyService.readByApiKey(noAuthProbe.getApiKey());
|
ApiKey apiKey = apiKeyService.readByApiKey(noauthprobe.getApiKey());
|
||||||
|
String memberEmail = SessionMetadata.getTargetID();
|
||||||
DomainMember domainMember = domainMemberService.readByMemberEmail(memberEmail);
|
DomainMember domainMember = domainMemberService.readByMemberEmail(memberEmail);
|
||||||
|
|
||||||
Probe probe = new Probe();
|
Probe probe = new Probe();
|
||||||
probe.setEncryptionKey(encryptKey);
|
probe.setEncryptionKey(encryptKey);
|
||||||
probe.setProbeKey(GenerateKey.getKey());
|
probe.setProbeKey(GenerateKey.getKey());
|
||||||
|
|
||||||
probe.setDomain(new Domain(apiKey.getDomain().getId()));
|
probe.setDomain(new Domain(apiKey.getDomain().getId()));
|
||||||
probe.setAuthorizeMember(new Member(domainMember.getMember().getId()));
|
probe.setAuthorizeMember(new Member(domainMember.getMember().getId()));
|
||||||
probe.setStatus(new MetaProbeStatus((short)1));
|
probe.setStatus(new MetaProbeStatus((short) 1));
|
||||||
|
|
||||||
HashMap<String, Object> objMap = this.gson.fromJson(noAuthProbe.getDescription(), TypeToken.getParameterized(HashMap.class, String.class, Object.class).getType());
|
|
||||||
Map<String, String> hostMap = (Map<String, String>) objMap.get("host");
|
|
||||||
Map<String, String> netMap = (Map<String, String>) objMap.get("network");
|
|
||||||
|
|
||||||
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("\\|");
|
||||||
|
|
||||||
probe.setCidr(addrArr[0]);
|
probe.setCidr(addrArr[0]);
|
||||||
|
|
||||||
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 1));
|
return this.probeService.regist(probe);
|
||||||
|
}
|
||||||
|
|
||||||
this.probeService.regist(probe);
|
private InfraMachine newInfraMachine(NoAuthProbe noauthprobe) throws OverflowException {
|
||||||
this.noAuthProbeDAO.save(noAuthProbe);
|
MetaInfraType infraType = new MetaInfraType();
|
||||||
|
infraType.setId(1);
|
||||||
|
|
||||||
messagePublisher.publishToNoAuthProbe(noAuthProbe.getTempProbeKey(), "NoAuthProbeService.Accept", probe.getProbeKey());
|
InfraMachine infraMachine = new InfraMachine();
|
||||||
|
infraMachine.setMeta(noauthprobe.getDescription());
|
||||||
|
infraMachine.setInfraType(infraType);
|
||||||
|
|
||||||
return this.readAllByDomain(noAuthProbe.getDomain());
|
return this.infraMachineService.regist(infraMachine);
|
||||||
|
}
|
||||||
|
|
||||||
|
private InfraOS newInfraOS(InfraMachine infraMachine, Map<String, String> hostMap) throws OverflowException {
|
||||||
|
MetaInfraType infraType = new MetaInfraType();
|
||||||
|
infraType.setId(3);
|
||||||
|
|
||||||
|
InfraOS infraOS = new InfraOS();
|
||||||
|
infraOS.setMachine(infraMachine);
|
||||||
|
infraOS.setInfraType(infraType);
|
||||||
|
infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(hostMap.get("os")));
|
||||||
|
|
||||||
|
return this.infraOSService.regist(infraOS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private InfraHost newInfraHost(InfraOS infraOS, Map<String, String> netMap) throws OverflowException {
|
||||||
|
MetaInfraType infraType = new MetaInfraType();
|
||||||
|
infraType.setId(2);
|
||||||
|
|
||||||
|
InfraHost infraHost = new InfraHost();
|
||||||
|
String addrStr = netMap.get("address");
|
||||||
|
String[] addrArr = addrStr.split("\\|");
|
||||||
|
|
||||||
|
infraHost.setIp(StringConvertor.ipToLong(addrArr[1]));
|
||||||
|
infraHost.setMac(StringConvertor.macStrToLong(netMap.get("macAddress")));
|
||||||
|
infraHost.setOs(infraOS);
|
||||||
|
infraHost.setInfraType(infraType);
|
||||||
|
|
||||||
|
return this.infraHostService.regist(infraHost);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void newProbeHost(InfraHost infraHost, Probe probe) throws OverflowException {
|
||||||
|
ProbeHost probeHost = new ProbeHost();
|
||||||
|
probeHost.setHost(infraHost);
|
||||||
|
probeHost.setProbe(probe);
|
||||||
|
|
||||||
|
this.probeHostService.regist(probeHost);
|
||||||
}
|
}
|
||||||
|
|
||||||
@WebappAPI
|
@WebappAPI
|
||||||
|
|
Loading…
Reference in New Issue
Block a user