This commit is contained in:
crusader 2018-06-11 21:24:55 +09:00
parent c03a4585a4
commit ad07199a2f
7 changed files with 52 additions and 170 deletions

View File

@ -1,55 +0,0 @@
package com.loafle.overflow.central.module.auth.service;
import com.loafle.overflow.central.module.auth.dao.AuthCrawlerDAO;
import com.loafle.overflow.central.module.infra.service.CentralInfraService;
import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.auth.AuthCrawler;
import com.loafle.overflow.model.infra.Infra;
import com.loafle.overflow.model.meta.MetaCrawler;
import com.loafle.overflow.service.central.auth.AuthCrawlerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Created by snoop on 17. 8. 30.
*/
@Service("AuthCrawlerService")
public class CentralAuthCrawlerService implements AuthCrawlerService {
@Autowired
private AuthCrawlerDAO authCrawlerDAO;
@Autowired
private CentralInfraService infraService;
public AuthCrawler regist(AuthCrawler authCrawler) {
// if (authCrawler == null) {
// return this.authCrawlerDAO.save(authCrawler);
// }
AuthCrawler dbAuthCrawler = this.authCrawlerDAO.findByMetaCrawlerIdAndTargetId(authCrawler.getMetaCrawler().getId(),
authCrawler.getTarget().getId());
dbAuthCrawler.setAuthJson(authCrawler.getAuthJson());
dbAuthCrawler.setMetaCrawler(authCrawler.getMetaCrawler());
dbAuthCrawler.setTarget(authCrawler.getTarget());
return this.authCrawlerDAO.save(dbAuthCrawler);
}
public boolean checkAuthCrawler(Long infraId, MetaCrawler metaCrawler, String authJson) throws OverflowException {
Infra infra = this.infraService.read(infraId);
// FIXME: Check Crawler on Probe
return false;
}
public AuthCrawler readByMetaCrawlerIDAndTargetID(Short metaCrawlerID, Long targetID) throws OverflowException {
return this.authCrawlerDAO.findByMetaCrawlerIdAndTargetId(metaCrawlerID, targetID);
}
}

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.generator.service;
import com.loafle.overflow.core.type.PortType;
import com.loafle.overflow.model.auth.AuthCrawler;
import com.loafle.overflow.model.infra.Infra;
import com.loafle.overflow.model.infra.InfraHost;
@ -12,7 +11,6 @@ import com.loafle.overflow.model.sensorconfig.Crawler;
import com.loafle.overflow.model.sensorconfig.Schedule;
import com.loafle.overflow.model.sensorconfig.SensorConfig;
import com.loafle.overflow.model.sensorconfig.Target;
import com.loafle.overflow.service.central.auth.AuthCrawlerService;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
@ -35,9 +33,6 @@ public class InfraHostGenerator {
@Autowired
private InfraHostWMIGenerator infraHostWMIGenerator;
@Autowired
private AuthCrawlerService authCrawlerService;
@Autowired
private ObjectMapper objectMapper;
@ -75,20 +70,20 @@ public class InfraHostGenerator {
private Target createTarget(InfraHost infraHost, Sensor dbSensor) throws Exception {
AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID(dbSensor.getMetaCrawler().getId(),
dbSensor.getTarget().getId());
// AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID(dbSensor.getMetaCrawler().getId(),
// dbSensor.getTarget().getId());
if (authCrawler == null) {
return null;
}
// if (authCrawler == null) {
// return null;
// }
Target target = new Target();
Connection connection = new Connection();
// connection.setIp(infraHost.getIpv4());
// Target target = new Target();
// Connection connection = new Connection();
// // connection.setIp(infraHost.getIpv4());
HashMap<String, String> optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(),
new TypeReference<Map<String, String>>() {
});
// HashMap<String, String> optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(),
// new TypeReference<Map<String, String>>() {
// });
// if (dbSensor.getMetaCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) {
// connection.setPort(135);
@ -105,6 +100,6 @@ public class InfraHostGenerator {
// }
return target;
return null;
}
}

View File

@ -1,6 +1,5 @@
package com.loafle.overflow.central.module.generator.service;
import com.loafle.overflow.core.type.PortType;
import com.loafle.overflow.model.auth.AuthCrawler;
import com.loafle.overflow.model.infra.Infra;
import com.loafle.overflow.model.infra.InfraService;
@ -38,9 +37,6 @@ public class InfraServiceGenerator {
@Autowired
private InfraServiceJMXGenerator infraServiceJMXGenerator;
@Autowired
private AuthCrawlerService authCrawlerService;
@Autowired
private ObjectMapper objectMapper;
@ -79,41 +75,42 @@ public class InfraServiceGenerator {
private Target createTarget(InfraService infraService, Sensor sensor) throws Exception {
AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID(sensor.getMetaCrawler().getId(),
sensor.getTarget().getId());
// AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID(sensor.getMetaCrawler().getId(),
// sensor.getTarget().getId());
if (authCrawler == null) {
return null;
}
Target target = new Target();
Connection connection = new Connection();
// connection.setIp(infraService.getInfraHost().getIpv4());
// connection.setPort(infraService.getPort());
// connection.setPortType(PortType.valueOf(infraService.getPortType()));
// connection.setSsl(infraService.isTlsType());
target.setConnection(connection);
HashMap<String, String> optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(),
new TypeReference<Map<String, String>>() {
});
Map<String, Object> auth = new HashMap<>();
// if (sensor.getMetaCrawler().getId() == MetaCrawlerEnum.MYSQL_CRAWLER.getValue()) {
// auth.put("url", "jdbc:mysql://" + infraService.getInfraHost().getIpv4() + ":" + infraService.getPort());
// auth.put("id", optionMap.get("ID")); // FIXME: Auth Info
// auth.put("pw", optionMap.get("PassWord")); // FIXME: Auth Info
// } else if (sensor.getMetaCrawler().getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) {
// auth.put("id", optionMap.get("ID")); // FIXME: Auth Info
// auth.put("pw", optionMap.get("PassWord")); // FIXME: Auth Info
// connection.setPort(9840);
// if (authCrawler == null) {
// return null;
// }
target.setAuth(auth);
// Target target = new Target();
// Connection connection = new Connection();
// // connection.setIp(infraService.getInfraHost().getIpv4());
// // connection.setPort(infraService.getPort());
// // connection.setPortType(PortType.valueOf(infraService.getPortType()));
// // connection.setSsl(infraService.isTlsType());
return target;
// target.setConnection(connection);
// HashMap<String, String> optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(),
// new TypeReference<Map<String, String>>() {
// });
// Map<String, Object> auth = new HashMap<>();
// // if (sensor.getMetaCrawler().getId() == MetaCrawlerEnum.MYSQL_CRAWLER.getValue()) {
// // auth.put("url", "jdbc:mysql://" + infraService.getInfraHost().getIpv4() + ":" + infraService.getPort());
// // auth.put("id", optionMap.get("ID")); // FIXME: Auth Info
// // auth.put("pw", optionMap.get("PassWord")); // FIXME: Auth Info
// // } else if (sensor.getMetaCrawler().getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) {
// // auth.put("id", optionMap.get("ID")); // FIXME: Auth Info
// // auth.put("pw", optionMap.get("PassWord")); // FIXME: Auth Info
// // connection.setPort(9840);
// // }
// target.setAuth(auth);
// return target;
return null;
}
}

View File

@ -9,6 +9,4 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface InfraHostDAO extends JpaRepository<InfraHost, Long> {
InfraHost findByProbeIdAndIpv4(Long probeId, String ipv4);
}

View File

@ -2,6 +2,8 @@ package com.loafle.overflow.central.module.infra.dao;
import com.loafle.overflow.model.infra.InfraService;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
@ -9,5 +11,8 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface InfraServiceDAO extends JpaRepository<InfraService, Long> {
InfraService findByInfraHostIdAndPortAndPortType(Long infraHostId, Integer port, String portType);
@Query("SELECT i from InfraService i where i.infraHostPort.infraHost.id = :infraHostId AND i.infraHostPort.metaPortType.key = :metaPortTypeKey AND i.infraHostPort.port = :port")
InfraService findByInfraHostPortInfraHostIdAndInfraHostPortMetaPortTypeKeyAndInfraHostPortPort(
@Param("infraHostId") Long infraHostId, @Param("metaPortTypeKey") String metaPortTypeKey,
@Param("port") Integer port);
}

View File

@ -838,7 +838,7 @@ INSERT INTO public.infra (id, meta_infra_type_id, probe_id) VALUES (3, 3, 1);
INSERT INTO public.infra_zone (id, meta_target_zone_type_id, network, iface, meta_ip_type_id, "address", mac) VALUES (1, 1, '192.168.1.0/24', 'enp3s0', 1, '192.168.1.101', '44:8a:5b:f1:f1:f3');
INSERT INTO public.infra_host (id, meta_target_host_type_id) VALUES (2, 127);
INSERT INTO public.infra_host (id, infra_zone_id, meta_target_host_type_id) VALUES (2, 1, 127);
INSERT INTO public.infra_host_ip (id, infra_host_id, meta_ip_type_id "address", mac) VALUES (1, 2, 1, '192.168.1.101', '44:8a:5b:f1:f1:f3');
INSERT INTO public.infra_host_port (id, infra_host_id, meta_port_type_id "address", mac) VALUES (1, 2, 1, 5432);

View File

@ -1,58 +0,0 @@
package com.loafle.overflow.central.module.auth.service;
import com.loafle.overflow.central.spring.AppConfigTest;
import com.loafle.overflow.core.exception.OverflowException;
import com.loafle.overflow.model.auth.AuthCrawler;
import com.loafle.overflow.model.meta.MetaCrawler;
import com.loafle.overflow.model.target.Target;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Created by snoop on 17. 8. 30.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {AppConfigTest.class})
public class AuthCrawlerServiceTest {
@Autowired
private CentralAuthCrawlerService authCrawlerService;
@Test
public void regist() throws Exception {
AuthCrawler authCrawler = new AuthCrawler();
Target target = new Target();
target.setId(Long.valueOf(4));
authCrawler.setTarget(target);
MetaCrawler metaCrawler = new MetaCrawler();
metaCrawler.setId((short)11);
authCrawler.setMetaCrawler(metaCrawler);
authCrawler.setAuthJson("{\"DB Name\":\"test\",\"ID\":\"docker\",\"PassWord\":\"qwer5795QWER\"}");
this.authCrawlerService.regist(authCrawler);
Assert.assertNotEquals(authCrawler.getId().longValue(), 0);
}
@Test
public void findAuth() throws OverflowException {
AuthCrawler authCrawler = this.authCrawlerService.readByMetaCrawlerIDAndTargetID((short)23, Long.valueOf(5));
Assert.assertNotEquals(authCrawler, null);
}
}