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;
}
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();
}
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;
}
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;
}
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();
}
}
Aggregations