Search in sources :

Example 1 with DNSRecord

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

the class SpringBaseTest method cleanDataStore.

protected void cleanDataStore() throws Exception {
    final ApplicationContext ctx = ConfigServiceRunner.getSpringApplicationContext();
    final AddressDao addressDao = (AddressDao) ctx.getBean("addressDao");
    final TrustBundleDao trustDao = (TrustBundleDao) ctx.getBean("trustBundleDao");
    final DomainDao domainDao = (DomainDao) ctx.getBean("domainDao");
    final AnchorDao anchorDao = (AnchorDao) ctx.getBean("anchorDao");
    final CertificateDao certDao = (CertificateDao) ctx.getBean("certificateDao");
    final DNSDao dnsDao = (DNSDao) ctx.getBean("dnsDao");
    final SettingDao settingDao = (SettingDao) ctx.getBean("settingDao");
    final CertPolicyDao policyDao = (CertPolicyDao) ctx.getBean("certPolicyDao");
    // clean anchors
    final List<Anchor> anchors = anchorDao.listAll();
    if (!anchors.isEmpty()) {
        final List<Long> anchorIds = new ArrayList<Long>();
        for (Anchor anchor : anchors) anchorIds.add(anchor.getId());
        anchorDao.delete(anchorIds);
    }
    // clean domains and the trust bundle domain relationships
    final List<Domain> domains = domainDao.listDomains(null, domainDao.count());
    if (domains != null) {
        for (Domain domain : domains) {
            Collection<Address> addresses = addressDao.getByDomain(domain, null);
            if (addresses != null) {
                for (Address address : addresses) {
                    addressDao.delete(address.getEmailAddress());
                }
            }
            trustDao.disassociateTrustBundlesFromDomain(domain.getId());
            domainDao.delete(domain.getId());
        }
    }
    assertEquals(0, domainDao.count());
    //clean trust bundles
    Collection<TrustBundle> bundles = trustDao.getTrustBundles();
    for (TrustBundle bundle : bundles) trustDao.deleteTrustBundles(new long[] { bundle.getId() });
    bundles = trustDao.getTrustBundles();
    assertEquals(0, bundles.size());
    // clean certificates
    final List<Certificate> certs = certDao.list((String) null);
    if (!certs.isEmpty()) {
        for (Certificate cert : certs) {
            certDao.delete(cert.getOwner());
        }
    }
    // clean DNS records
    final Collection<DNSRecord> records = dnsDao.get(Type.ANY);
    if (!records.isEmpty()) {
        for (DNSRecord record : records) dnsDao.remove(record.getId());
    }
    // clean settings
    final Collection<Setting> settings = settingDao.getAll();
    if (!settings.isEmpty()) {
        for (Setting setting : settings) settingDao.delete(Arrays.asList(setting.getName()));
    }
    // clean policies
    final Collection<CertPolicy> policies = policyDao.getPolicies();
    if (!policies.isEmpty()) {
        for (CertPolicy policy : policies) policyDao.deletePolicies(new long[] { policy.getId() });
    }
    // clean policy groups
    final Collection<CertPolicyGroup> groups = policyDao.getPolicyGroups();
    if (!groups.isEmpty()) {
        for (CertPolicyGroup group : groups) policyDao.deletePolicyGroups(new long[] { group.getId() });
    }
}
Also used : CertificateDao(org.nhindirect.config.store.dao.CertificateDao) Address(org.nhindirect.config.store.Address) ArrayList(java.util.ArrayList) TrustBundleDao(org.nhindirect.config.store.dao.TrustBundleDao) AnchorDao(org.nhindirect.config.store.dao.AnchorDao) ApplicationContext(org.springframework.context.ApplicationContext) SettingDao(org.nhindirect.config.store.dao.SettingDao) DomainDao(org.nhindirect.config.store.dao.DomainDao) TrustBundle(org.nhindirect.config.store.TrustBundle) AddressDao(org.nhindirect.config.store.dao.AddressDao) CertPolicyDao(org.nhindirect.config.store.dao.CertPolicyDao) DNSRecord(org.nhindirect.config.store.DNSRecord) Setting(org.nhindirect.config.store.Setting) DNSDao(org.nhindirect.config.store.dao.DNSDao) Anchor(org.nhindirect.config.store.Anchor) CertPolicy(org.nhindirect.config.store.CertPolicy) CertPolicyGroup(org.nhindirect.config.store.CertPolicyGroup) Domain(org.nhindirect.config.store.Domain) Certificate(org.nhindirect.config.store.Certificate)

Example 2 with DNSRecord

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

the class DNSServiceTest method testAddDNS.

/**
     * Test the addDNS method.
     */
public void testAddDNS() {
    final DNSDao dnsDao = context.mock(DNSDao.class);
    final Collection<DNSRecord> records = Arrays.asList(DNSRecordUtils.createARecord("example.domain.com", 84000L, "10.45.84.12"));
    context.checking(new Expectations() {

        {
            oneOf(dnsDao).add(records);
        }
    });
    DNSServiceImpl service = new DNSServiceImpl();
    service.setDao(dnsDao);
    try {
        service.addDNS(records);
    } catch (Exception e) {
        fail("Exception thrown");
    }
}
Also used : Expectations(org.jmock.Expectations) DNSDao(org.nhindirect.config.store.dao.DNSDao) DNSRecord(org.nhindirect.config.store.DNSRecord) DNSServiceImpl(org.nhindirect.config.service.impl.DNSServiceImpl)

Example 3 with DNSRecord

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

the class DNSServiceTest method testRemoveDNS.

/**
     * Test the removeDNS method.
     */
public void testRemoveDNS() {
    final DNSDao dnsDao = context.mock(DNSDao.class);
    final Collection<DNSRecord> records = Arrays.asList(DNSRecordUtils.createARecord("example.domain.com", 84000L, "10.45.84.12"));
    context.checking(new Expectations() {

        {
            oneOf(dnsDao).remove(records);
        }
    });
    DNSServiceImpl service = new DNSServiceImpl();
    service.setDao(dnsDao);
    try {
        service.removeDNS(records);
    } catch (Exception e) {
        fail("Exception thrown");
    }
}
Also used : Expectations(org.jmock.Expectations) DNSDao(org.nhindirect.config.store.dao.DNSDao) DNSRecord(org.nhindirect.config.store.DNSRecord) DNSServiceImpl(org.nhindirect.config.service.impl.DNSServiceImpl)

Example 4 with DNSRecord

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

the class DNSServiceTest method testUpdateDNS.

/**
     * Test the updateDNS method.
     */
public void testUpdateDNS() {
    final DNSDao dnsDao = context.mock(DNSDao.class);
    final DNSRecord record = DNSRecordUtils.createARecord("example.domain.com", 84000L, "10.45.84.12");
    final long recId = 8387;
    context.checking(new Expectations() {

        {
            oneOf(dnsDao).update(recId, record);
        }
    });
    DNSServiceImpl service = new DNSServiceImpl();
    service.setDao(dnsDao);
    try {
        service.updateDNS(recId, record);
    } catch (Exception e) {
        fail("Exception thrown");
    }
}
Also used : Expectations(org.jmock.Expectations) DNSDao(org.nhindirect.config.store.dao.DNSDao) DNSRecord(org.nhindirect.config.store.DNSRecord) DNSServiceImpl(org.nhindirect.config.service.impl.DNSServiceImpl)

Example 5 with DNSRecord

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

the class DNSRecordUtils method fromWire.

/**
	 * Converts a raw wire transfer format of a record to a DNS record.
	 * @param data  The raw byte stream of a record in wire transfer format.
	 * @return A DNSRecord converted from the wire format.
	 * @throws IOException
	 */
public static DNSRecord fromWire(byte[] data) throws IOException {
    Record rec = Record.fromWire(data, Section.ANSWER);
    DNSRecord retVal = new DNSRecord();
    retVal.setDclass(rec.getDClass());
    retVal.setName(rec.getName().toString());
    retVal.setData(rec.rdataToWireCanonical());
    retVal.setTtl(rec.getTTL());
    retVal.setType(rec.getType());
    return retVal;
}
Also used : DNSRecord(org.nhindirect.config.store.DNSRecord) SOARecord(org.xbill.DNS.SOARecord) CERTRecord(org.xbill.DNS.CERTRecord) ARecord(org.xbill.DNS.ARecord) SRVRecord(org.xbill.DNS.SRVRecord) MXRecord(org.xbill.DNS.MXRecord) DNSRecord(org.nhindirect.config.store.DNSRecord) Record(org.xbill.DNS.Record)

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