This commit is contained in:
crusader 2018-03-16 16:32:43 +09:00
parent 963ac0c068
commit 3f9d6c05c2
16 changed files with 435 additions and 321 deletions

View File

@ -6,10 +6,10 @@ import io.grpc.Metadata;
import static io.grpc.Metadata.ASCII_STRING_MARSHALLER; import static io.grpc.Metadata.ASCII_STRING_MARSHALLER;
public class SessionMetadata { public class SessionMetadata {
public static final Context.Key<String> CTX_EMAIL_KEY = Context.key("email"); public static final Context.Key<String> CTX_SESSION_ID_KEY = Context.key("SESSION_ID");
public static final Metadata.Key<String> METADATA_EMAIL_KEY = Metadata.Key.of("email", ASCII_STRING_MARSHALLER); public static final Metadata.Key<String> METADATA_SESSION_ID_KEY = Metadata.Key.of("SESSION_ID", ASCII_STRING_MARSHALLER);
public static String getEmail() { public static String getSessionID() {
return CTX_EMAIL_KEY.get(); return CTX_SESSION_ID_KEY.get();
} }
} }

View File

@ -0,0 +1,11 @@
package com.loafle.overflow.commons.stereotype;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface ProbeAPI {
}

View File

@ -0,0 +1,11 @@
package com.loafle.overflow.commons.stereotype;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface WebappAPI {
}

View File

@ -0,0 +1,52 @@
package com.loafle.overflow.module.discovery.model;
import java.util.List;
public class DiscoveryHost {
private String firstScanRange;
private String lastScanRange;
private List<String> excludeHosts;
private List<String> includeHosts;
private DiscoveryPort discoveryPort;
public String getFirstScanRange() {
return firstScanRange;
}
public void setFirstScanRange(String firstScanRange) {
this.firstScanRange = firstScanRange;
}
public String getLastScanRange() {
return lastScanRange;
}
public void setLastScanRange(String lastScanRange) {
this.lastScanRange = lastScanRange;
}
public List<String> getExcludeHosts() {
return excludeHosts;
}
public void setExcludeHosts(List<String> excludeHosts) {
this.excludeHosts = excludeHosts;
}
public List<String> getIncludeHosts() {
return includeHosts;
}
public void setIncludeHosts(List<String> includeHosts) {
this.includeHosts = includeHosts;
}
public DiscoveryPort getDiscoveryPort() {
return discoveryPort;
}
public void setDiscoveryPort(DiscoveryPort discoveryPort) {
this.discoveryPort = discoveryPort;
}
}

View File

@ -0,0 +1,61 @@
package com.loafle.overflow.module.discovery.model;
import java.util.List;
public class DiscoveryPort {
private int firstScanRange;
private int lastScanRange;
private List<Integer> excludePorts;
private boolean includeTCP;
private boolean includeUDP;
private DiscoveryService discoveryService;
public int getFirstScanRange() {
return firstScanRange;
}
public void setFirstScanRange(int firstScanRange) {
this.firstScanRange = firstScanRange;
}
public int getLastScanRange() {
return lastScanRange;
}
public void setLastScanRange(int lastScanRange) {
this.lastScanRange = lastScanRange;
}
public List<Integer> getExcludePorts() {
return excludePorts;
}
public void setExcludePorts(List<Integer> excludePorts) {
this.excludePorts = excludePorts;
}
public boolean isIncludeTCP() {
return includeTCP;
}
public void setIncludeTCP(boolean includeTCP) {
this.includeTCP = includeTCP;
}
public boolean isIncludeUDP() {
return includeUDP;
}
public void setIncludeUDP(boolean includeUDP) {
this.includeUDP = includeUDP;
}
public DiscoveryService getDiscoveryService() {
return discoveryService;
}
public void setDiscoveryService(DiscoveryService discoveryService) {
this.discoveryService = discoveryService;
}
}

View File

@ -0,0 +1,15 @@
package com.loafle.overflow.module.discovery.model;
import java.util.List;
public class DiscoveryService {
private List<String> includeServices;
public List<String> getIncludeServices() {
return includeServices;
}
public void setIncludeServices(List<String> includeServices) {
this.includeServices = includeServices;
}
}

View File

@ -0,0 +1,25 @@
package com.loafle.overflow.module.discovery.model;
import java.util.List;
public class DiscoveryZone {
private List<String> excludePatterns;
private DiscoveryHost discoveryHost;
public List<String> getExcludePatterns() {
return excludePatterns;
}
public void setExcludePatterns(List<String> excludePatterns) {
this.excludePatterns = excludePatterns;
}
public DiscoveryHost getDiscoveryHost() {
return discoveryHost;
}
public void setDiscoveryHost(DiscoveryHost discoveryHost) {
this.discoveryHost = discoveryHost;
}
}

View File

@ -1,39 +1,19 @@
package com.loafle.overflow.module.discovery.model; package com.loafle.overflow.module.discovery.model;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
* Created by root on 17. 6. 4. * Created by root on 17. 6. 4.
*/ */
public class Host { public class Host {
private long id; private long id;
private long ip; private long ip;
private long mac; private long mac;
private Date createDate;
private Date updateDate;
private String os; private String os;
private boolean target; private Date discoveredDate;
private List<Port> ports;
public List<Port> getPorts() {
return ports;
}
public void setPorts(List<Port> ports) {
this.ports = ports;
}
private Zone zone;
public Host(){} public Host(){}
@ -66,22 +46,6 @@ public class Host {
this.mac = mac; this.mac = mac;
} }
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
public String getOs() { public String getOs() {
return os; return os;
} }
@ -90,11 +54,19 @@ public class Host {
this.os = os; this.os = os;
} }
public boolean isTarget() { public Date getDiscoveredDate() {
return target; return discoveredDate;
} }
public void setTarget(boolean target) { public void setDiscoveredDate(Date discoveredDate) {
this.target = target; this.discoveredDate = discoveredDate;
}
public Zone getZone() {
return zone;
}
public void setZone(Zone zone) {
this.zone = zone;
} }
} }

View File

@ -8,7 +8,6 @@ package com.loafle.overflow.module.discovery.model;
import com.loafle.overflow.module.discovery.type.PortType; import com.loafle.overflow.module.discovery.type.PortType;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
* Created by root on 17. 6. 4. * Created by root on 17. 6. 4.
@ -18,54 +17,14 @@ public class Port {
private long id; private long id;
private PortType portType;
private int portNumber;
private Date discoveredDate;
private Host host; private Host host;
public Host getHost() {
return host;
}
public void setHost(Host host) {
this.host = host;
}
private PortType portType;
private int portNumber;
private List<Service> services;
public List<Service> getServices() {
return services;
}
public void setServices(List<Service> services) {
this.services = services;
}
private Date createDate;
private Date updateDate;
public Port() {} public Port() {}
public Port(PortType type, int portNumber) {
this.portType = type;
this.portNumber = portNumber;
}
public Port(Host host, PortType type, int portNumber) {
this.host = host;
this.portType = type;
this.portNumber = portNumber;
}
public long getId() { public long getId() {
return id; return id;
} }
@ -90,33 +49,20 @@ public class Port {
this.portNumber = portNumber; this.portNumber = portNumber;
} }
public Date getDiscoveredDate() {
return discoveredDate;
public Date getCreateDate() {
return createDate;
} }
public void setCreateDate(Date createDate) { public void setDiscoveredDate(Date discoveredDate) {
this.createDate = createDate; this.discoveredDate = discoveredDate;
} }
public Date getUpdateDate() { public Host getHost() {
return updateDate; return host;
} }
public void setUpdateDate(Date updateDate) { public void setHost(Host host) {
this.updateDate = updateDate; this.host = host;
} }
public void mappingChildren(Host discoveryHost) {
this.setHost(discoveryHost);
List<Service> discoveryServices = this.getServices();
if (discoveryServices != null) {
for (int z = 0 ; z < discoveryServices.size() ; ++z) {
discoveryServices.get(z).setPort(this);
}
}
}
} }

View File

@ -1,8 +1,5 @@
package com.loafle.overflow.module.discovery.model; package com.loafle.overflow.module.discovery.model;
import com.loafle.overflow.module.discovery.type.PortType;
import java.util.Date; import java.util.Date;
/** /**
@ -10,48 +7,29 @@ import java.util.Date;
*/ */
public class Service { public class Service {
private long id; private long id;
private String cryptoType;
private String serviceName;
private Date discoveredDate;
private Port port; private Port port;
public Port getPort() {
return port;
}
public void setPort(Port port) {
this.port = port;
}
private PortType portType;
private String serviceName;
private Date createDate;
private Date updateDate;
private boolean target;
public Service() {} public Service() {}
public Service(Port port, PortType t, String serviceName) { public long getId() {
this.port = port; return id;
this.portType = t;
this.serviceName = serviceName;
} }
public PortType getPortType() { public void setId(long id) {
return portType; this.id = id;
} }
public void setPortType(PortType portType) { public String getCryptoType() {
this.portType = portType; return cryptoType;
}
public void setCryptoType(String cryptoType) {
this.cryptoType = cryptoType;
} }
public String getServiceName() { public String getServiceName() {
@ -62,36 +40,21 @@ public class Service {
this.serviceName = serviceName; this.serviceName = serviceName;
} }
public long getId() { public Date getDiscoveredDate() {
return id; return discoveredDate;
} }
public void setId(long id) { public void setDiscoveredDate(Date discoveredDate) {
this.id = id; this.discoveredDate = discoveredDate;
}
public Port getPort() {
return port;
}
public void setPort(Port port) {
this.port = port;
} }
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
public boolean isTarget() {
return target;
}
public void setTarget(boolean target) {
this.target = target;
}
} }

View File

@ -1,5 +1,7 @@
package com.loafle.overflow.module.discovery.model; package com.loafle.overflow.module.discovery.model;
import java.util.Date;
/** /**
* Created by snoop on 17. 10. 31. * Created by snoop on 17. 10. 31.
*/ */
@ -9,8 +11,7 @@ public class Zone {
private String ip; private String ip;
private String iface; private String iface;
private String mac; private String mac;
private long firstScanRange; private Date discoveredDate;
private long lastScanRange;
public long getId() { public long getId() {
return id; return id;
@ -52,19 +53,11 @@ public class Zone {
this.mac = mac; this.mac = mac;
} }
public long getFirstScanRange() { public Date getDiscoveredDate() {
return firstScanRange; return discoveredDate;
} }
public void setFirstScanRange(long firstScanRange) { public void setDiscoveredDate(Date discoveredDate) {
this.firstScanRange = firstScanRange; this.discoveredDate = discoveredDate;
}
public long getLastScanRange() {
return lastScanRange;
}
public void setLastScanRange(long lastScanRange) {
this.lastScanRange = lastScanRange;
} }
} }

View File

@ -1,7 +1,16 @@
package com.loafle.overflow.module.discovery.service; package com.loafle.overflow.module.discovery.service;
import com.loafle.overflow.commons.model.SessionMetadata;
import com.loafle.overflow.commons.service.MessagePublisher; import com.loafle.overflow.commons.service.MessagePublisher;
import com.loafle.overflow.commons.stereotype.ProbeAPI;
import com.loafle.overflow.commons.stereotype.WebappAPI;
import com.loafle.overflow.module.discovery.model.DiscoveryHost;
import com.loafle.overflow.module.discovery.model.DiscoveryPort;
import com.loafle.overflow.module.discovery.model.DiscoveryStartInfo; import com.loafle.overflow.module.discovery.model.DiscoveryStartInfo;
import com.loafle.overflow.module.discovery.model.DiscoveryZone;
import com.loafle.overflow.module.discovery.model.Host;
import com.loafle.overflow.module.discovery.model.Port;
import com.loafle.overflow.module.discovery.model.Zone;
import com.loafle.overflow.module.domain.model.Domain; import com.loafle.overflow.module.domain.model.Domain;
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -49,5 +58,55 @@ public class DiscoveryService {
return true; return true;
} }
}
@WebappAPI
public void discoverZone(String probeID, DiscoveryZone discoveryZone) {
String requestMemberEmail = SessionMetadata.getSessionID();
messagePublisher.publishToProbe("/probe", probeID, "DiscoveryService.DiscoverZone", requestMemberEmail, discoveryZone);
}
@WebappAPI
public void discoverHost(String probeID, Zone zone, DiscoveryHost discoveryHost) {
String requestMemberEmail = SessionMetadata.getSessionID();
messagePublisher.publishToProbe("/probe", probeID, "DiscoveryService.DiscoverHost", requestMemberEmail, zone, discoveryHost);
}
@WebappAPI
public void discoverPort(String probeID, Host host, DiscoveryPort discoveryPort) {
String requestMemberEmail = SessionMetadata.getSessionID();
messagePublisher.publishToProbe("/probe", probeID, "DiscoveryService.DiscoverPort", requestMemberEmail, host, discoveryPort);
}
@WebappAPI
public void discoverService(String probeID, Port port, com.loafle.overflow.module.discovery.model.DiscoveryService discoveryService) {
String requestMemberEmail = SessionMetadata.getSessionID();
messagePublisher.publishToProbe("/probe", probeID, "DiscoveryService.DiscoverService", requestMemberEmail, port, discoveryService);
}
@ProbeAPI
public void discoveredZone(String requestMemberEmail, Zone zone) {
messagePublisher.publishToMember("/webapp", requestMemberEmail, "DiscoveryService.discoveredZone", zone);
}
@ProbeAPI
public void discoveredHost(String requestMemberEmail, Host host) {
messagePublisher.publishToMember("/webapp", requestMemberEmail, "DiscoveryService.discoveredHost", host);
}
@ProbeAPI
public void discoveredPort(String requestMemberEmail, Port port) {
messagePublisher.publishToMember("/webapp", requestMemberEmail, "DiscoveryService.discoveredPort", port);
}
@ProbeAPI
public void discoveredService(String requestMemberEmail, com.loafle.overflow.module.discovery.model.Service service) {
messagePublisher.publishToMember("/webapp", requestMemberEmail, "DiscoveryService.discoveredService", service);
}
}

View File

@ -1,6 +1,7 @@
package com.loafle.overflow.module.member.service; package com.loafle.overflow.module.member.service;
import com.loafle.overflow.commons.model.SessionMetadata; import com.loafle.overflow.commons.model.SessionMetadata;
import com.loafle.overflow.commons.stereotype.WebappAPI;
import com.loafle.overflow.commons.utils.EmailSender; import com.loafle.overflow.commons.utils.EmailSender;
import com.loafle.overflow.module.apikey.model.ApiKey; import com.loafle.overflow.module.apikey.model.ApiKey;
import com.loafle.overflow.module.apikey.service.ApiKeyService; import com.loafle.overflow.module.apikey.service.ApiKeyService;
@ -21,7 +22,6 @@ import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -113,7 +113,6 @@ public class MemberService {
e.printStackTrace(); e.printStackTrace();
} }
return resMember; return resMember;
} }
@ -161,8 +160,9 @@ public class MemberService {
// Todo websocket session remove // Todo websocket session remove
} }
@WebappAPI
public Member modify(Member member, String pw) { public Member modify(Member member, String pw) {
String email = SessionMetadata.getEmail(); String email = SessionMetadata.getSessionID();
Member preMember = this.memberDAO.findByEmail(member.getEmail()); Member preMember = this.memberDAO.findByEmail(member.getEmail());
if (null != pw && !pw.equals("")) { if (null != pw && !pw.equals("")) {
@ -227,8 +227,9 @@ public class MemberService {
return resMember; return resMember;
} }
@WebappAPI
public void withdrawal(Member member) { public void withdrawal(Member member) {
String email = SessionMetadata.getEmail(); String email = SessionMetadata.getSessionID();
// Todo DB delete? // Todo DB delete?
} }

View File

@ -1,6 +1,8 @@
package com.loafle.overflow.module.noauthprobe.service; package com.loafle.overflow.module.noauthprobe.service;
import com.loafle.overflow.commons.service.MessagePublisher; import com.loafle.overflow.commons.service.MessagePublisher;
import com.loafle.overflow.commons.stereotype.ProbeAPI;
import com.loafle.overflow.commons.stereotype.WebappAPI;
import com.loafle.overflow.module.apikey.model.ApiKey; import com.loafle.overflow.module.apikey.model.ApiKey;
import com.loafle.overflow.module.apikey.service.ApiKeyService; import com.loafle.overflow.module.apikey.service.ApiKeyService;
import com.loafle.overflow.module.domain.model.Domain; import com.loafle.overflow.module.domain.model.Domain;
@ -44,6 +46,7 @@ public class NoAuthProbeService {
@Autowired @Autowired
private MessagePublisher messagePublisher; private MessagePublisher messagePublisher;
@ProbeAPI
public NoAuthProbe regist(NoAuthProbe noAuthProbe) { public NoAuthProbe regist(NoAuthProbe noAuthProbe) {
noAuthProbe.setTempProbeKey(UUID.randomUUID().toString()); noAuthProbe.setTempProbeKey(UUID.randomUUID().toString());
@ -67,6 +70,7 @@ public class NoAuthProbeService {
return this.noAuthProbeDAO.findOne(id); return this.noAuthProbeDAO.findOne(id);
} }
@WebappAPI
public List<NoAuthProbe> acceptNoAuthProbe(NoAuthProbe noAuthProbe) throws IOException { public List<NoAuthProbe> acceptNoAuthProbe(NoAuthProbe noAuthProbe) throws IOException {
// Todo domain injection & member injection // Todo domain injection & member injection
@ -108,6 +112,7 @@ public class NoAuthProbeService {
return this.readAllByDomain(noAuthProbe.getDomain()); return this.readAllByDomain(noAuthProbe.getDomain());
} }
@WebappAPI
public List<NoAuthProbe> denyNoauthProbe(NoAuthProbe noAuthProbe) { public List<NoAuthProbe> denyNoauthProbe(NoAuthProbe noAuthProbe) {
this.noAuthProbeDAO.save(noAuthProbe); this.noAuthProbeDAO.save(noAuthProbe);

View File

@ -44,177 +44,177 @@ public class TargetDiscoveryService {
@Autowired @Autowired
private InfraServiceService infraServiceService; private InfraServiceService infraServiceService;
@Transactional // @Transactional
public boolean saveAllTarget(List<Host> hosts, Probe probe) { // public boolean saveAllTarget(List<Host> hosts, Probe probe) {
InfraHost infraHost = null; // InfraHost infraHost = null;
for(Host host : hosts) { // for(Host host : hosts) {
infraHost = this.createAndReadHost(host, probe); // infraHost = this.createAndReadHost(host, probe);
this.createPort(infraHost, host, probe); // this.createPort(infraHost, host, probe);
} // }
return true; // return true;
} // }
private void createService(InfraHost infraHost, Port port, Probe probe) { // private void createService(InfraHost infraHost, Port port, Probe probe) {
if(port.getServices() == null) { // if(port.getServices() == null) {
return; // return;
} // }
MetaInfraType typeService = new MetaInfraType(); // MetaInfraType typeService = new MetaInfraType();
typeService.setId(7); // typeService.setId(7);
String portType = "UDP"; // String portType = "UDP";
if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) { // if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) {
portType = "TCP"; // portType = "TCP";
} // }
for(com.loafle.overflow.module.discovery.model.Service service : port.getServices()) { // for(com.loafle.overflow.module.discovery.model.Service service : port.getServices()) {
InfraService dbInfraService = this.infraServiceService.readByService(infraHost.getId(), port.getPortNumber(), portType); // InfraService dbInfraService = this.infraServiceService.readByService(infraHost.getId(), port.getPortNumber(), portType);
if(dbInfraService != null) { // if(dbInfraService != null) {
if(service.isTarget() && dbInfraService.getTarget() == null) { // if(service.isTarget() && dbInfraService.getTarget() == null) {
Target targetService = new Target(); // Target targetService = new Target();
targetService.setDisplayName(service.getServiceName() + "-Service"); // targetService.setDisplayName(service.getServiceName() + "-Service");
this.targetService.regist(targetService); // this.targetService.regist(targetService);
dbInfraService.setTarget(targetService); // dbInfraService.setTarget(targetService);
this.infraServiceService.regist(dbInfraService); // this.infraServiceService.regist(dbInfraService);
} // }
continue; // continue;
} // }
InfraService infraService = new InfraService(); // InfraService infraService = new InfraService();
infraService.setHost(infraHost); // infraService.setHost(infraHost);
infraService.setPort(port.getPortNumber()); // infraService.setPort(port.getPortNumber());
infraService.setPortType(portType); // infraService.setPortType(portType);
infraService.setInfraType(typeService); // infraService.setInfraType(typeService);
infraService.setProbe(probe); // infraService.setProbe(probe);
if (port.getPortType() == PortType.TLS) { // if (port.getPortType() == PortType.TLS) {
infraService.setTlsType(true); // infraService.setTlsType(true);
} // }
infraService.setVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName())); // infraService.setVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName()));
if(service.isTarget()) { // if(service.isTarget()) {
Target targetService = new Target(); // Target targetService = new Target();
targetService.setDisplayName(service.getServiceName() + "-Service"); // targetService.setDisplayName(service.getServiceName() + "-Service");
this.targetService.regist(targetService); // this.targetService.regist(targetService);
infraService.setTarget(targetService); // infraService.setTarget(targetService);
} // }
this.infraServiceService.regist(infraService); // this.infraServiceService.regist(infraService);
} // }
} // }
private void createPort(InfraHost infraHost, Host host, Probe probe) { // private void createPort(InfraHost infraHost, Host host, Probe probe) {
if(host.getPorts() == null) { // if(host.getPorts() == null) {
return; // return;
} // }
String portType = "UDP"; // String portType = "UDP";
MetaInfraType typePort = new MetaInfraType(); // MetaInfraType typePort = new MetaInfraType();
typePort.setId(6); // typePort.setId(6);
InfraOS infraOS = infraHost.getOs(); // InfraOS infraOS = infraHost.getOs();
for(Port port : host.getPorts()) { // for(Port port : host.getPorts()) {
if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) { // if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) {
portType = "TCP"; // portType = "TCP";
} // }
InfraOSPort dbInfraOSPort = this.infraOSPortService.readByPort(infraOS.getId(), port.getPortNumber(), portType); // InfraOSPort dbInfraOSPort = this.infraOSPortService.readByPort(infraOS.getId(), port.getPortNumber(), portType);
if(dbInfraOSPort == null) { // if(dbInfraOSPort == null) {
InfraOSPort infraOSPort = new InfraOSPort(); // InfraOSPort infraOSPort = new InfraOSPort();
infraOSPort.setOs(infraOS); // infraOSPort.setOs(infraOS);
infraOSPort.setPort(port.getPortNumber()); // infraOSPort.setPort(port.getPortNumber());
infraOSPort.setPortType(portType); // infraOSPort.setPortType(portType);
infraOSPort.setProbe(probe); // infraOSPort.setProbe(probe);
infraOSPort.setInfraType(typePort); // infraOSPort.setInfraType(typePort);
if (port.getPortType() == PortType.TLS) { // if (port.getPortType() == PortType.TLS) {
infraOSPort.setTlsType(true); // infraOSPort.setTlsType(true);
} // }
infraOSPort.setVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber())); // infraOSPort.setVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber()));
this.infraOSPortService.regist(infraOSPort); // this.infraOSPortService.regist(infraOSPort);
} // }
this.createService(infraHost, port, probe); // this.createService(infraHost, port, probe);
} // }
} // }
private InfraHost createAndReadHost(Host host, Probe probe) { // private InfraHost createAndReadHost(Host host, Probe probe) {
InfraHost infraHost = this.infraHostService.readByIp(host.getIp()); // InfraHost infraHost = this.infraHostService.readByIp(host.getIp());
if(infraHost != null) { // if(infraHost != null) {
if(host.isTarget() && infraHost.getTarget() == null) { // if(host.isTarget() && infraHost.getTarget() == null) {
Target target = new Target(); // Target target = new Target();
target.setDisplayName(String.valueOf(host.getIp()) + "-Host"); // target.setDisplayName(String.valueOf(host.getIp()) + "-Host");
this.targetService.regist(target); // this.targetService.regist(target);
infraHost.setTarget(target); // infraHost.setTarget(target);
this.infraHostService.regist(infraHost); // this.infraHostService.regist(infraHost);
} // }
return infraHost; // return infraHost;
} else { // } else {
MetaInfraType typeMachine = new MetaInfraType(); // MetaInfraType typeMachine = new MetaInfraType();
typeMachine.setId(1); // 1 = Machine; // typeMachine.setId(1); // 1 = Machine;
MetaInfraType typeOS = new MetaInfraType(); // MetaInfraType typeOS = new MetaInfraType();
typeOS.setId(3); // 3 = Os // typeOS.setId(3); // 3 = Os
MetaInfraType typeHost = new MetaInfraType(); // MetaInfraType typeHost = new MetaInfraType();
typeHost.setId(2); // 2 = Host // typeHost.setId(2); // 2 = Host
InfraMachine infraMachine = new InfraMachine(); // InfraMachine infraMachine = new InfraMachine();
infraMachine.setProbe(probe); // infraMachine.setProbe(probe);
infraMachine.setInfraType(typeMachine); // infraMachine.setInfraType(typeMachine);
infraMachine.setMeta(StringConvertor.intToIp(host.getIp())+"-MACHINE"); // infraMachine.setMeta(StringConvertor.intToIp(host.getIp())+"-MACHINE");
this.infraMachineService.regist(infraMachine); // this.infraMachineService.regist(infraMachine);
InfraOS infraOS = new InfraOS(); // InfraOS infraOS = new InfraOS();
infraOS.setMachine(infraMachine); // infraOS.setMachine(infraMachine);
infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs())); // infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs()));
infraOS.setInfraType(typeOS); // infraOS.setInfraType(typeOS);
infraOS.setProbe(probe); // infraOS.setProbe(probe);
infraOS.setMeta(StringConvertor.intToIp(host.getIp())+"-OS"); // infraOS.setMeta(StringConvertor.intToIp(host.getIp())+"-OS");
this.infraOSService.regist(infraOS); // this.infraOSService.regist(infraOS);
InfraHost newInfraHost = new InfraHost(); // InfraHost newInfraHost = new InfraHost();
newInfraHost.setIp(host.getIp()); // newInfraHost.setIp(host.getIp());
newInfraHost.setMac(host.getMac()); // newInfraHost.setMac(host.getMac());
newInfraHost.setOs(infraOS); // newInfraHost.setOs(infraOS);
newInfraHost.setInfraType(typeHost); // newInfraHost.setInfraType(typeHost);
newInfraHost.setProbe(probe); // newInfraHost.setProbe(probe);
if(host.isTarget()) { // if(host.isTarget()) {
Target target = new Target(); // Target target = new Target();
target.setDisplayName(StringConvertor.intToIp(host.getIp()) + "-Host"); // target.setDisplayName(StringConvertor.intToIp(host.getIp()) + "-Host");
this.targetService.regist(target); // this.targetService.regist(target);
newInfraHost.setTarget(target); // newInfraHost.setTarget(target);
} // }
this.infraHostService.regist(newInfraHost); // this.infraHostService.regist(newInfraHost);
infraHost = newInfraHost; // infraHost = newInfraHost;
} // }
return infraHost; // return infraHost;
} // }

View File

@ -7,8 +7,8 @@ public class ProxyServerInterceptor implements ServerInterceptor {
@Override @Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) { public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
String email = headers.get(SessionMetadata.METADATA_EMAIL_KEY); String sessionID = headers.get(SessionMetadata.METADATA_SESSION_ID_KEY);
Context ctx = Context.current().withValue(SessionMetadata.CTX_EMAIL_KEY, email); Context ctx = Context.current().withValue(SessionMetadata.CTX_SESSION_ID_KEY, sessionID);
return Contexts.interceptCall(ctx, call, headers, next); return Contexts.interceptCall(ctx, call, headers, next);
} }