use of org.nhindirect.config.service.ConfigurationServiceException in project nhin-d by DirectProject.
the class DNSController method removeAnchors.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/removesettings", method = RequestMethod.POST)
public ModelAndView removeAnchors(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, @ModelAttribute("AdnsForm") DNSEntryForm AdnsForm, @ModelAttribute("NSdnsForm") DNSEntryForm NSdnsForm, @ModelAttribute("AAdnsForm") DNSEntryForm AAdnsForm, @ModelAttribute("CdnsForm") DNSEntryForm CdnsForm, @ModelAttribute("CertdnsForm") DNSEntryForm CertdnsForm, @ModelAttribute("SrvdnsForm") DNSEntryForm SrvdnsForm, @ModelAttribute("SoadnsForm") DNSEntryForm SoadnsForm, @ModelAttribute("MXdnsForm") DNSEntryForm MXdnsForm, HttpSession session, Model model, @RequestParam(value = "submitType") String actionPath) {
if (log.isDebugEnabled())
log.debug("Enter domain/removesettings");
// A records
try {
Collection<DNSRecord> arecords = null;
if (dnsService != null && AdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteADnsEntries") || actionPath.equalsIgnoreCase("Remove Selected As")) && AdnsForm.getRemove() != null) {
int cnt = AdnsForm.getRemove().size();
arecords = dnsService.getDNSRecord(DNSType.A.getValue(), "");
for (int x = 0; x < cnt; x++) {
String removeid = AdnsForm.getRemove().get(x);
Long remid = Long.parseLong(removeid);
for (Iterator<DNSRecord> iter = arecords.iterator(); iter.hasNext(); ) {
DNSRecord t = (DNSRecord) iter.next();
if (t.getId() == remid) {
dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
}
}
}
}
} catch (ServiceException e1) {
}
// A4 records
try {
Collection<DNSRecord> a4records = null;
if (dnsService != null && AAdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteA4DnsEntries") || actionPath.equalsIgnoreCase("Remove Selected A4s")) && AAdnsForm.getRemove() != null) {
int cnt = AAdnsForm.getRemove().size();
a4records = dnsService.getDNSRecord(DNSType.AAAA.getValue(), "");
for (int x = 0; x < cnt; x++) {
String removeid = AAdnsForm.getRemove().get(x);
Long remid = Long.parseLong(removeid);
for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
DNSRecord t = (DNSRecord) iter.next();
if (t.getId() == remid) {
dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
}
}
}
}
} catch (ServiceException e1) {
}
// CNAME records
try {
Collection<DNSRecord> a4records = null;
if (dnsService != null && CdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteCNAMEDnsEntries") || actionPath.equalsIgnoreCase("Remove Selected CNAMEs")) && CdnsForm.getRemove() != null) {
int cnt = AAdnsForm.getRemove().size();
a4records = dnsService.getDNSRecord(DNSType.CNAME.getValue(), "");
for (int x = 0; x < cnt; x++) {
String removeid = CdnsForm.getRemove().get(x);
Long remid = Long.parseLong(removeid);
for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
DNSRecord t = (DNSRecord) iter.next();
if (t.getId() == remid) {
dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
}
}
}
}
} catch (ServiceException e1) {
}
// MX records
try {
Collection<DNSRecord> a4records = null;
if (dnsService != null && MXdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteMXDnsEntries") || actionPath.equalsIgnoreCase("Remove Selected MXs")) && MXdnsForm.getRemove() != null) {
int cnt = MXdnsForm.getRemove().size();
a4records = dnsService.getDNSRecord(DNSType.MX.getValue(), "");
for (int x = 0; x < cnt; x++) {
String removeid = MXdnsForm.getRemove().get(x);
Long remid = Long.parseLong(removeid);
for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
DNSRecord t = (DNSRecord) iter.next();
if (t.getId() == remid) {
dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
}
}
}
}
} catch (ServiceException e1) {
}
// CERT records
try {
Collection<DNSRecord> a4records = null;
if (dnsService != null && CertdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteCERTDnsEntries") || actionPath.equalsIgnoreCase("Remove Selected CERTs")) && CertdnsForm.getRemove() != null) {
int cnt = CertdnsForm.getRemove().size();
a4records = dnsService.getDNSRecord(DNSType.CERT.getValue(), "");
for (int x = 0; x < cnt; x++) {
String removeid = CertdnsForm.getRemove().get(x);
Long remid = Long.parseLong(removeid);
for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
DNSRecord t = (DNSRecord) iter.next();
if (t.getId() == remid) {
dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
}
}
}
}
} catch (ServiceException e1) {
}
// SRV records
try {
Collection<DNSRecord> a4records = null;
if (dnsService != null && SrvdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteSRVDnsEntries") || actionPath.equalsIgnoreCase("Remove Selected SRVs")) && SrvdnsForm.getRemove() != null) {
int cnt = SrvdnsForm.getRemove().size();
a4records = dnsService.getDNSRecord(DNSType.SRV.getValue(), "");
for (int x = 0; x < cnt; x++) {
String removeid = SrvdnsForm.getRemove().get(x);
Long remid = Long.parseLong(removeid);
for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
DNSRecord t = (DNSRecord) iter.next();
if (t.getId() == remid) {
dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
}
}
}
}
} catch (ServiceException e1) {
}
// SOA records
try {
Collection<DNSRecord> soarecords = null;
if (dnsService != null && SoadnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteSOADnsEntries") || actionPath.equalsIgnoreCase("Remove Selected SOAs")) && SoadnsForm.getRemove() != null) {
int cnt = SoadnsForm.getRemove().size();
soarecords = dnsService.getDNSRecord(DNSType.SOA.getValue(), "");
for (int x = 0; x < cnt; x++) {
String removeid = SoadnsForm.getRemove().get(x);
Long remid = Long.parseLong(removeid);
for (Iterator<DNSRecord> iter = soarecords.iterator(); iter.hasNext(); ) {
DNSRecord t = (DNSRecord) iter.next();
if (t.getId() == remid) {
dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
}
}
}
}
} catch (ServiceException e1) {
}
// NS records
try {
Collection<DNSRecord> nsrecords = null;
if (dnsService != null && NSdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteNSDnsEntries") || actionPath.equalsIgnoreCase("Remove Selected NSs")) && NSdnsForm.getRemove() != null) {
int cnt = NSdnsForm.getRemove().size();
nsrecords = dnsService.getDNSRecord(DNSType.NS.getValue(), "");
for (int x = 0; x < cnt; x++) {
String removeid = NSdnsForm.getRemove().get(x);
Long remid = Long.parseLong(removeid);
for (Iterator<DNSRecord> iter = nsrecords.iterator(); iter.hasNext(); ) {
DNSRecord t = (DNSRecord) iter.next();
if (t.getId() == remid) {
dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
}
}
}
}
} catch (ServiceException e1) {
}
// additional post clean up to redisplay
ModelAndView mav = new ModelAndView("dns");
if (AdnsForm.getRemove() != null) {
if (log.isDebugEnabled())
log.debug("the list of checkboxes checked or not is: " + AdnsForm.getRemove().toString());
}
/*
* if (configSvc != null && simpleForm != null && actionPath != null &&
* actionPath.equalsIgnoreCase("delete") && simpleForm.getRemove() !=
* null) { int cnt = simpleForm.getRemove().size(); try{
* Collection<String> settingstoberemovedlist = simpleForm.getRemove();
* if (log.isDebugEnabled())
* log.debug(" Trying to remove settings from database");
* configSvc.deleteSetting(settingstoberemovedlist); if
* (log.isDebugEnabled())
* log.debug(" SUCCESS Trying to remove settings"); } catch
* (ConfigurationServiceException e) { if (log.isDebugEnabled())
* log.error(e); } }
*/
refreshModelFromService(model);
model.addAttribute("dnsEntryForm", new DNSEntryForm());
model.addAttribute("AdnsForm", new DNSEntryForm());
model.addAttribute("AAdnsForm", new DNSEntryForm());
model.addAttribute("CdnsForm", new DNSEntryForm());
model.addAttribute("MXdnsForm", new DNSEntryForm());
model.addAttribute("CertdnsForm", new DNSEntryForm());
model.addAttribute("SrvdnsForm", new DNSEntryForm());
return mav;
}
use of org.nhindirect.config.service.ConfigurationServiceException in project nhin-d by DirectProject.
the class ServiceTest method testDNSService.
// @Test
// public void testDomainService()
// {
// try
// {
// int count = configSvc. getDomainCount();
// log.info(""+count + " Domains exist in the database");
// }
// catch (ConfigurationServiceException e)
// {
// e.printStackTrace();
// fail(e.getMessage());
// }
// }
// @Test
public void testDNSService() {
// try
// {
//configSvc.getDNSCount();
int count = 0;
// log.info(""+count + " DNS records exist in the database");
// System.out.println(""+count + " DNS records exist in the database");
// configSvc.removeDomain("pjpassoc.com");
Collection<DNSRecord> records = new ArrayList<DNSRecord>();
// records.add(DNSRecordUtils.createARecord("pjpassoc.com", 3600L, "192.168.1.1"));
// records.add(DNSRecordUtils.createMXRecord("pjpassoc.com", "mail.pjpassoc.com", 3600L, 0));
byte[] certData = null;
try {
// certData = loadPkcs12FromCertAndKey("gm2552.der", "gm2552Key.der");
certData = loadCertificateData("gm2552.der");
if (certData != null) {
// get the owner from the certificate information
// first transform into a certificate
CertContainer cont = toCertContainer(certData);
if (cont != null && cont.getCert() != null) {
Certificate cert2 = new Certificate();
cert2.setData(certData);
System.out.println(getThumbPrint(cont.getCert()));
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// records.add(DNSEntryForm.createCertRecord("yahoo.com", 3600L, 0,0,0,certData));
// configSvc.addDNS(records);
// assertEquals(2, configSvc.getDNSCount());
// }
// catch (ConfigurationServiceException e)
// {
// e.printStackTrace();
// fail(e.getMessage());
// }
}
use of org.nhindirect.config.service.ConfigurationServiceException in project nhin-d by DirectProject.
the class ServiceTest method testSOA.
// @Test
public void testSOA() {
DNSEntryForm SoadnsForm = new DNSEntryForm();
SoadnsForm.setName("savvy");
SoadnsForm.setTtl(84555L);
SoadnsForm.setAdmin("ns.savvy.com");
SoadnsForm.setDomain("ns2.savvy.com");
SoadnsForm.setSerial(4L);
SoadnsForm.setRefresh(6L);
SoadnsForm.setRetry(8L);
SoadnsForm.setExpire(66L);
SoadnsForm.setMinimum(22L);
Collection<DNSRecord> records = new ArrayList<DNSRecord>();
records.add(DNSRecordUtils.createSOARecord(SoadnsForm.getName(), SoadnsForm.getTtl(), SoadnsForm.getDomain(), SoadnsForm.getAdmin(), (int) SoadnsForm.getSerial(), SoadnsForm.getRefresh(), SoadnsForm.getRetry(), SoadnsForm.getExpire(), SoadnsForm.getMinimum()));
try {
configSvc.addDNS(records);
Collection<DNSRecord> arecords = configSvc.getDNSByType(DNSType.SOA.getValue());
for (Iterator<DNSRecord> iter = arecords.iterator(); iter.hasNext(); ) {
DNSRecord arec = iter.next();
SOARecord newrec = (SOARecord) Record.newRecord(Name.fromString(arec.getName()), arec.getType(), arec.getDclass(), arec.getTtl(), arec.getData());
System.out.println("A admin: " + newrec.getAdmin());
System.out.println("A name: " + newrec.getName());
}
} catch (ConfigurationServiceException e) {
e.printStackTrace();
} catch (TextParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.nhindirect.config.service.ConfigurationServiceException in project nhin-d by DirectProject.
the class ServiceTest method toCertContainer.
public CertContainer toCertContainer(byte[] data) throws Exception {
CertContainer certContainer = null;
try {
ByteArrayInputStream bais = new ByteArrayInputStream(data);
// lets try this a as a PKCS12 data stream first
try {
KeyStore localKeyStore = KeyStore.getInstance("PKCS12", Certificate.getJCEProviderName());
localKeyStore.load(bais, "".toCharArray());
Enumeration<String> aliases = localKeyStore.aliases();
// we are really expecting only one alias
if (aliases.hasMoreElements()) {
String alias = aliases.nextElement();
X509Certificate cert = (X509Certificate) localKeyStore.getCertificate(alias);
// check if there is private key
Key key = localKeyStore.getKey(alias, "".toCharArray());
if (key != null && key instanceof PrivateKey) {
certContainer = new CertContainer(cert, key);
}
}
} catch (Exception e) {
// must not be a PKCS12 stream, go on to next step
}
if (certContainer == null) {
//try X509 certificate factory next
bais.reset();
bais = new ByteArrayInputStream(data);
X509Certificate cert = (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(bais);
certContainer = new CertContainer(cert, null);
}
bais.close();
} catch (Exception e) {
throw new ConfigurationServiceException("Data cannot be converted to a valid X.509 Certificate", e);
}
return certContainer;
}
Aggregations