Search in sources :

Example 16 with DnsRecord

use of org.nhind.config.DnsRecord in project nhin-d by DirectProject.

the class DNSRecordCommands method loadAndVerifyDnsRecordFromBin.

/*
	 * Loads a record from a file.  Records are stored in raw wire format.
	 */
private DnsRecord loadAndVerifyDnsRecordFromBin(String path) {
    File recFile = new File(path);
    if (!recFile.exists())
        throw new IllegalArgumentException("Record file " + recFile.getAbsolutePath() + " not found");
    Record rec = null;
    try {
        byte[] wire = FileUtils.readFileToByteArray(recFile);
        rec = Record.fromWire(wire, Section.ANSWER);
    } catch (Exception e) {
        throw new RuntimeException("Error reading file " + recFile.getAbsolutePath() + " : " + e.getMessage(), e);
    }
    return (rec != null) ? fromRecord(rec) : null;
}
Also used : DnsRecord(org.nhind.config.DnsRecord) Record(org.xbill.DNS.Record) File(java.io.File) RemoteException(java.rmi.RemoteException)

Example 17 with DnsRecord

use of org.nhind.config.DnsRecord in project nhin-d by DirectProject.

the class DNSRecordCommands_removeRecords_Test method testRemoveAllExceptARecords_AssertAllExceptARecordRemoved.

public void testRemoveAllExceptARecords_AssertAllExceptARecordRemoved() throws Exception {
    new TestPlan() {

        private List<Record> recordsToAdd;

        private List<Record> expectedRemainingRecords;

        @Override
        protected List<Record> getRecordsToAdd() throws Exception {
            recordsToAdd = new ArrayList<Record>();
            recordsToAdd.add(new ARecord(Name.fromString("example.domain.com."), DClass.IN, 3600, InetAddress.getByName("127.0.0.1")));
            recordsToAdd.add(new ARecord(Name.fromString("example.domain.com."), DClass.IN, 3600, InetAddress.getByName("127.0.0.2")));
            recordsToAdd.add(new MXRecord(Name.fromString("example.domain.com."), DClass.IN, 3600, 1, Name.fromString("mail1.example.domain.com.")));
            recordsToAdd.add(new MXRecord(Name.fromString("example2.domain.com."), DClass.IN, 3600, 1, Name.fromString("mail2.exampl2.domain.com.")));
            recordsToAdd.add(new SOARecord(Name.fromString("example.domain.com."), DClass.IN, 3600, Name.fromString("ns1.example.domain.com."), Name.fromString("gm2552.example.domain.com."), 1, 3600, 60, 60, 3600));
            return recordsToAdd;
        }

        @Override
        protected List<DnsRecord> getRecordsToRemove(List<DnsRecord> addedRecords) throws Exception {
            List<DnsRecord> retVal = new ArrayList<DnsRecord>();
            expectedRemainingRecords = new ArrayList<Record>();
            for (DnsRecord addedRecord : addedRecords) {
                if (addedRecord.getType() != Type.A)
                    retVal.add(addedRecord);
                else
                    expectedRemainingRecords.add(toRecord(addedRecord));
            }
            return retVal;
        }

        @Override
        protected void doAssertions(List<Record> remainingRecords) throws Exception {
            assertNotNull(remainingRecords);
            assertEquals(2, remainingRecords.size());
            for (Record expectedRemaining : expectedRemainingRecords) {
                int index = remainingRecords.indexOf(expectedRemaining);
                assertTrue(index >= 0);
                Record checkRecord = remainingRecords.get(index);
                assertTrue(checkRecord.getType() == Type.A);
                assertEquals(checkRecord, expectedRemaining);
            }
        }
    }.perform();
}
Also used : BaseTestPlan(org.nhindirect.dns.util.BaseTestPlan) ArrayList(java.util.ArrayList) SOARecord(org.xbill.DNS.SOARecord) ARecord(org.xbill.DNS.ARecord) MXRecord(org.xbill.DNS.MXRecord) DnsRecord(org.nhind.config.DnsRecord) SOARecord(org.xbill.DNS.SOARecord) ARecord(org.xbill.DNS.ARecord) MXRecord(org.xbill.DNS.MXRecord) Record(org.xbill.DNS.Record) ArrayList(java.util.ArrayList) List(java.util.List) SOARecord(org.xbill.DNS.SOARecord) DnsRecord(org.nhind.config.DnsRecord)

Example 18 with DnsRecord

use of org.nhind.config.DnsRecord in project nhin-d by DirectProject.

the class ConfigServiceDNSStore method processGenericANYRecordRequest.

protected Collection<Record> processGenericANYRecordRequest(String name) throws DNSException {
    DnsRecord[] records;
    try {
        records = proxy.getDNSByNameAndType(name, Type.ANY);
    } catch (Exception e) {
        throw new DNSException(DNSError.newError(Rcode.SERVFAIL), "DNS service proxy call for DNS records failed: " + e.getMessage(), e);
    }
    if (records == null || records.length == 0)
        return null;
    Collection<Record> retVal = new ArrayList<Record>();
    try {
        for (DnsRecord record : records) {
            Record rec = Record.newRecord(Name.fromString(record.getName()), record.getType(), record.getDclass(), record.getTtl(), record.getData());
            retVal.add(rec);
        }
    } catch (Exception e) {
        throw new DNSException(DNSError.newError(Rcode.SERVFAIL), "Failure while parsing generic record data: " + e.getMessage(), e);
    }
    return retVal;
}
Also used : ArrayList(java.util.ArrayList) CERTRecord(org.xbill.DNS.CERTRecord) Record(org.xbill.DNS.Record) DnsRecord(org.nhind.config.DnsRecord) DnsRecord(org.nhind.config.DnsRecord) CertificateConversionException(org.nhindirect.config.model.exceptions.CertificateConversionException)

Example 19 with DnsRecord

use of org.nhind.config.DnsRecord in project nhin-d by DirectProject.

the class ConfigServiceDNSStore method checkForSoaRecord.

/*
     * Look for SOA records corresponding to the request
     * TODO: Add cache coherency to SOA records?
     */
protected synchronized Record checkForSoaRecord(String questionName) {
    if (!questionName.endsWith("."))
        questionName += ".";
    if (soaRecords == null) {
        DnsRecord[] getRecs = null;
        // load all SOA records...
        try {
            getRecs = proxy.getDNSByType(Type.SOA);
            if (getRecs == null || getRecs.length == 0)
                soaRecords = Collections.emptyMap();
            else {
                soaRecords = new HashMap<String, Record>();
                for (DnsRecord rec : getRecs) {
                    Record newRec = Record.newRecord(Name.fromString(rec.getName()), Type.SOA, rec.getDclass(), rec.getTtl(), rec.getData());
                    soaRecords.put(newRec.getName().toString(), newRec);
                }
            }
        } catch (Exception e) {
            LOGGER.error("Failed to load SOA records from config service.");
        }
    }
    Record retVal = null;
    if (soaRecords.size() > 0) {
        // look for the record by question name
        retVal = soaRecords.get(questionName);
        if (retVal == null) {
            // start taking apart the question name . by .
            int index = -1;
            while ((index = questionName.indexOf(".")) > 0 && index < (questionName.length() - 1)) {
                questionName = questionName.substring(index + 1);
                retVal = soaRecords.get(questionName);
                if (retVal != null)
                    break;
            }
        }
    }
    return retVal;
}
Also used : CERTRecord(org.xbill.DNS.CERTRecord) Record(org.xbill.DNS.Record) DnsRecord(org.nhind.config.DnsRecord) DnsRecord(org.nhind.config.DnsRecord) CertificateConversionException(org.nhindirect.config.model.exceptions.CertificateConversionException)

Example 20 with DnsRecord

use of org.nhind.config.DnsRecord in project nhin-d by DirectProject.

the class AddHardcodedRecord method main.

public static void main(String[] args) {
    try {
        ConfigurationServiceProxy proxy = new ConfigurationServiceProxy("http://securehealthemail.com:8080/config-service/ConfigurationService");
        // clean everything
        DnsRecord[] recs = proxy.getDNSByType(Type.ANY);
        if (recs != null && recs.length > 0)
            proxy.removeDNS(recs);
        recs = proxy.getDNSByType(Type.ANY);
        assertNull(recs);
        // now add
        ArrayList<DnsRecord> recsAdd = new ArrayList<DnsRecord>();
        DnsRecord rec = DNSRecordUtil.createARecord("direct.securehealthemail.com", "184.73.173.57");
        recsAdd.add(rec);
        rec = DNSRecordUtil.createARecord("ns1.direct.securehealthemail.com", "184.73.173.57");
        recsAdd.add(rec);
        rec = DNSRecordUtil.createARecord("mail1.direct.securehealthemail.com", "184.73.173.57");
        recsAdd.add(rec);
        rec = DNSRecordUtil.createSOARecord("direct.securehealthemail.com", "ns1.direct.securehealthemail.com", "greg.meyer@direct.securehealthemail.com");
        recsAdd.add(rec);
        rec = DNSRecordUtil.createMXRecord("direct.securehealthemail.com", "mail1.direct.securehealthemail.com", 0);
        recsAdd.add(rec);
        proxy.addDNS(recsAdd.toArray(new DnsRecord[recsAdd.size()]));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ArrayList(java.util.ArrayList) DnsRecord(org.nhind.config.DnsRecord) ConfigurationServiceProxy(org.nhind.config.ConfigurationServiceProxy)

Aggregations

DnsRecord (org.nhind.config.DnsRecord)32 Command (org.nhindirect.dns.tools.utils.Command)14 Record (org.xbill.DNS.Record)7 ArrayList (java.util.ArrayList)6 RemoteException (java.rmi.RemoteException)4 CertificateConversionException (org.nhindirect.config.model.exceptions.CertificateConversionException)3 CERTRecord (org.xbill.DNS.CERTRecord)3 SOARecord (org.xbill.DNS.SOARecord)3 File (java.io.File)2 List (java.util.List)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 BaseTestPlan (org.nhindirect.dns.util.BaseTestPlan)2 ARecord (org.xbill.DNS.ARecord)2 MXRecord (org.xbill.DNS.MXRecord)2 Test (org.junit.Test)1 ConfigurationServiceProxy (org.nhind.config.ConfigurationServiceProxy)1 DNSRecord (org.nhindirect.config.store.DNSRecord)1 RRset (org.xbill.DNS.RRset)1