Search in sources :

Example 11 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("addressDaoImpl");
    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("DNSDaoImpl");
    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 12 with DNSRecord

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

the class ClientProxyDNSTest method addDNSRecord.

@Test
public void addDNSRecord() throws Exception {
    cleanDNSRecords();
    DNSRecord rec = DNSRecordUtils.createARecord("example.domain.com", 86400L, "127.0.0.1");
    DnsRecord recToAdd = new DnsRecord();
    recToAdd.setData(rec.getData());
    recToAdd.setDclass(rec.getDclass());
    recToAdd.setName(rec.getName());
    recToAdd.setTtl(rec.getTtl());
    recToAdd.setType(rec.getType());
    proxy.addDNS(new DnsRecord[] { recToAdd });
    assertEquals(1, proxy.getDNSCount());
    DnsRecord[] recs = proxy.getDNSByNameAndType(recToAdd.getName(), recToAdd.getType());
    assertNotNull(recs);
    assertEquals(1, recs.length);
    assertEquals(rec.getName(), recs[0].getName());
}
Also used : DNSRecord(org.nhindirect.config.store.DNSRecord) DnsRecord(org.nhind.config.DnsRecord) Test(org.junit.Test)

Example 13 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(long[] recordIds) {
    if (log.isDebugEnabled())
        log.debug("get(long[]) Enter");
    List<DNSRecord> result = Collections.emptyList();
    if (recordIds != null && recordIds.length > 0) {
        Query select = null;
        StringBuffer idList = new StringBuffer("(");
        for (long id : recordIds) {
            if (idList.length() > 1) {
                idList.append(", ");
            }
            idList.append(id);
        }
        idList.append(")");
        String query = "SELECT d from DNSRecord d WHERE d.id IN " + idList.toString();
        select = entityManager.createQuery(query);
        @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(long[]) 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 14 with DNSRecord

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

the class DNSDaoImpl method remove.

/**
     * {@inheritDoc}}
     */
@Override
@Transactional(readOnly = false)
public void remove(Collection<DNSRecord> records) {
    if (log.isDebugEnabled())
        log.debug("remove(Collection<DNSRecord>) Enter");
    if (records != null && records.size() > 0) {
        Collection<DNSRecord> toDelete = new ArrayList<DNSRecord>();
        // get the records out of the DAO
        for (DNSRecord record : records) toDelete.addAll(get(record.getName(), record.getType()));
        // delete all qualifying records
        if (toDelete.size() > 0)
            for (DNSRecord record : toDelete) entityManager.remove(record);
        if (log.isDebugEnabled()) {
            if (toDelete.size() == 0)
                log.debug("No DNS records qualified for deletion.");
            else
                log.debug(toDelete.size() + " DNS records deleted");
        }
        entityManager.flush();
    }
    if (log.isDebugEnabled())
        log.debug("remove(Collection<DNSRecord>) Exit");
}
Also used : DNSRecord(org.nhindirect.config.store.DNSRecord) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 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(int type) {
    if (log.isDebugEnabled())
        log.debug("get(int) Enter");
    List<DNSRecord> result = Collections.emptyList();
    Query select = null;
    if (type != Type.ANY) {
        select = entityManager.createQuery("SELECT d from DNSRecord d WHERE d.type = ?1");
        select.setParameter(1, type);
    } else
        select = entityManager.createQuery("SELECT d from DNSRecord d");
    @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(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)

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