Search in sources :

Example 16 with DNSRecord

use of org.nhindirect.config.store.DNSRecord in project nhin-d by DirectProject.

the class DNSDaoImpl method get.

/**
     * {@inheritDoc}}
     */
@Override
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public Collection<DNSRecord> get(String name, int type) {
    if (log.isDebugEnabled())
        log.debug("get(String, int) Enter");
    List<DNSRecord> result = Collections.emptyList();
    Query select = null;
    if (type == Type.ANY) {
        select = entityManager.createQuery("SELECT d from DNSRecord d WHERE UPPER(d.name) = ?1");
        select.setParameter(1, name.toUpperCase(Locale.getDefault()));
    } else {
        select = entityManager.createQuery("SELECT d from DNSRecord d WHERE UPPER(d.name) = ?1 and d.type = ?2");
        select.setParameter(1, name.toUpperCase(Locale.getDefault()));
        select.setParameter(2, type);
    }
    @SuppressWarnings("rawtypes") List rs = select.getResultList();
    if (rs != null && (rs.size() != 0) && (rs.get(0) instanceof DNSRecord)) {
        result = (List<DNSRecord>) rs;
    }
    if (log.isDebugEnabled())
        log.debug("get(String, int) Exit");
    return result;
}
Also used : DNSRecord(org.nhindirect.config.store.DNSRecord) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) List(java.util.List) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with DNSRecord

use of org.nhindirect.config.store.DNSRecord 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());
//        }  
}
Also used : DNSRecord(org.nhindirect.config.store.DNSRecord) ArrayList(java.util.ArrayList) TextParseException(org.xbill.DNS.TextParseException) CertificateEncodingException(javax.security.cert.CertificateEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) X509Certificate(java.security.cert.X509Certificate) Certificate(org.nhindirect.config.store.Certificate)

Example 18 with DNSRecord

use of org.nhindirect.config.store.DNSRecord 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();
    }
}
Also used : DNSRecord(org.nhindirect.config.store.DNSRecord) ArrayList(java.util.ArrayList) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) DNSEntryForm(org.nhindirect.config.ui.form.DNSEntryForm) SOARecord(org.xbill.DNS.SOARecord) TextParseException(org.xbill.DNS.TextParseException)

Aggregations

DNSRecord (org.nhindirect.config.store.DNSRecord)18 ArrayList (java.util.ArrayList)10 Transactional (org.springframework.transaction.annotation.Transactional)6 DNSDao (org.nhindirect.config.store.dao.DNSDao)5 DNSEntryForm (org.nhindirect.config.ui.form.DNSEntryForm)4 List (java.util.List)3 Query (javax.persistence.Query)3 Expectations (org.jmock.Expectations)3 ConfigurationServiceException (org.nhindirect.config.service.ConfigurationServiceException)3 DNSServiceImpl (org.nhindirect.config.service.impl.DNSServiceImpl)3 Certificate (org.nhindirect.config.store.Certificate)3 TextParseException (org.xbill.DNS.TextParseException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 CertificateEncodingException (javax.security.cert.CertificateEncodingException)2 Address (org.nhindirect.config.store.Address)2 Anchor (org.nhindirect.config.store.Anchor)2 CertPolicy (org.nhindirect.config.store.CertPolicy)2 CertPolicyGroup (org.nhindirect.config.store.CertPolicyGroup)2 ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)2 Domain (org.nhindirect.config.store.Domain)2