Search in sources :

Example 6 with Name

use of org.xbill.DNS.Name in project nhin-d by DirectProject.

the class LDAPPublicCertUtil_createLDAPUrl_Test method testCreateLDAPUrl_multipleSRVRecord_ascendingPriority_assertPriorityOrderDesc.

public void testCreateLDAPUrl_multipleSRVRecord_ascendingPriority_assertPriorityOrderDesc() throws Exception {
    LdapPublicCertUtilImpl impl = new LdapPublicCertUtilImpl();
    SRVRecord rec1 = new SRVRecord(new Name("test.com."), DClass.IN, 3600, 1, 1, 339, new Name("ldap1.test.com."));
    SRVRecord rec2 = new SRVRecord(new Name("test.com."), DClass.IN, 3600, 0, 1, 339, new Name("ldap2.test.com."));
    String url = impl.createLDAPUrl(new Record[] { rec1, rec2 });
    String[] urls = url.split(" ");
    assertEquals(2, urls.length);
    assertTrue(urls[0].startsWith("ldap://ldap2.test.com"));
    assertTrue(urls[1].startsWith("ldap://ldap1.test.com"));
}
Also used : SRVRecord(org.xbill.DNS.SRVRecord) Name(org.xbill.DNS.Name)

Example 7 with Name

use of org.xbill.DNS.Name in project nhin-d by DirectProject.

the class LDAPPublicCertUtil_createLDAPUrl_Test method testCreateLDAPUrl_multipleSRVRecord_descendingPriority_assertPriorityOrderDesc.

public void testCreateLDAPUrl_multipleSRVRecord_descendingPriority_assertPriorityOrderDesc() throws Exception {
    LdapPublicCertUtilImpl impl = new LdapPublicCertUtilImpl();
    SRVRecord rec1 = new SRVRecord(new Name("test.com."), DClass.IN, 3600, 0, 1, 339, new Name("ldap1.test.com."));
    SRVRecord rec2 = new SRVRecord(new Name("test.com."), DClass.IN, 3600, 1, 1, 339, new Name("ldap2.test.com."));
    String url = impl.createLDAPUrl(new Record[] { rec1, rec2 });
    String[] urls = url.split(" ");
    assertEquals(2, urls.length);
    assertTrue(urls[0].startsWith("ldap://ldap1.test.com"));
    assertTrue(urls[1].startsWith("ldap://ldap2.test.com"));
}
Also used : SRVRecord(org.xbill.DNS.SRVRecord) Name(org.xbill.DNS.Name)

Example 8 with Name

use of org.xbill.DNS.Name in project nhin-d by DirectProject.

the class WSSmtpAgentConfigFunctional_Test method setUp.

/**
     * Initialize the servers- LDAP and HTTP.
     */
@SuppressWarnings("unchecked")
@Override
public void setUp() throws Exception {
    // check for Windows... it doens't like file://<drive>... turns it into FTP
    File file = new File("./src/test/resources/bundles/testBundle.p7b");
    if (file.getAbsolutePath().contains(":/"))
        filePrefix = "file:///";
    else
        filePrefix = "file:///";
    CertCacheFactory.getInstance().flushAll();
    /*
		 * Setup the LDAP Server
		 */
    MutablePartitionConfiguration pcfg = new MutablePartitionConfiguration();
    pcfg.setName("lookupTest");
    pcfg.setSuffix("cn=lookupTest");
    // Create some indices
    Set<String> indexedAttrs = new HashSet<String>();
    indexedAttrs.add("objectClass");
    indexedAttrs.add("cn");
    pcfg.setIndexedAttributes(indexedAttrs);
    // Create a first entry associated to the partition
    Attributes attrs = new BasicAttributes(true);
    // First, the objectClass attribute
    Attribute attr = new BasicAttribute("objectClass");
    attr.add("top");
    attrs.put(attr);
    // Associate this entry to the partition
    pcfg.setContextEntry(attrs);
    // As we can create more than one partition, we must store
    // each created partition in a Set before initialization
    Set<MutablePartitionConfiguration> pcfgs = new HashSet<MutablePartitionConfiguration>();
    pcfgs.add(pcfg);
    //
    //
    //
    // add the lookupTestPublic
    //
    //
    pcfg = new MutablePartitionConfiguration();
    pcfg.setName("lookupTestPublic");
    pcfg.setSuffix("cn=lookupTestPublic");
    // Create some indices
    indexedAttrs = new HashSet<String>();
    indexedAttrs.add("objectClass");
    indexedAttrs.add("cn");
    pcfg.setIndexedAttributes(indexedAttrs);
    // Create a first entry associated to the partition
    attrs = new BasicAttributes(true);
    // First, the objectClass attribute
    attr = new BasicAttribute("objectClass");
    attr.add("top");
    attrs.put(attr);
    // Associate this entry to the partition
    pcfg.setContextEntry(attrs);
    // As we can create more than one partition, we must store
    // each created partition in a Set before initialization
    pcfgs.add(pcfg);
    configuration.setContextPartitionConfigurations(pcfgs);
    this.configuration.setWorkingDirectory(new File("LDAP-TEST"));
    // add the private key schema
    ///
    Set<AbstractBootstrapSchema> schemas = configuration.getBootstrapSchemas();
    schemas.add(new PrivkeySchema());
    configuration.setBootstrapSchemas(schemas);
    super.setUp();
    // import the ldif file
    InputStream stream = TestUtils.class.getResourceAsStream("/ldifs/privCertsOnly.ldif");
    if (stream == null)
        throw new IOException("Failed to load ldif file");
    importLdif(stream);
    // setup the mock DNS SRV adapter
    mockLookup = mock(Lookup.class);
    LookupFactory.getFactory().addOverrideImplementation(mockLookup);
    SRVRecord srvRecord = new SRVRecord(new Name("_ldap._tcp.example.com."), DClass.IN, 3600, 0, 1, port, new Name("localhost."));
    when(mockLookup.run()).thenReturn(new Record[] { srvRecord });
    // create the web service and proxy
    ConfigServiceRunner.startConfigService();
    proxy = new ConfigurationServiceProxy(ConfigServiceRunner.getConfigServiceURL());
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) Attribute(javax.naming.directory.Attribute) BasicAttribute(javax.naming.directory.BasicAttribute) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) IOException(java.io.IOException) PrivkeySchema(org.nhindirect.ldap.PrivkeySchema) Name(org.xbill.DNS.Name) AbstractBootstrapSchema(org.apache.directory.server.core.schema.bootstrap.AbstractBootstrapSchema) MutablePartitionConfiguration(org.apache.directory.server.core.configuration.MutablePartitionConfiguration) Lookup(org.nhindirect.stagent.cert.impl.util.Lookup) SRVRecord(org.xbill.DNS.SRVRecord) File(java.io.File) ConfigurationServiceProxy(org.nhind.config.ConfigurationServiceProxy) HashSet(java.util.HashSet)

Example 9 with Name

use of org.xbill.DNS.Name in project nhin-d by DirectProject.

the class ConfigServiceDNSStore method get.

/**
	 * {@inheritDoc}
	 */
@SuppressWarnings("unchecked")
@Override
public Message get(Message request) throws DNSException {
    LOGGER.trace("get(Message) Entered");
    /* for testing time out cases
		try
		{
			Thread.sleep(1000000);
		}
		catch (Exception e)
		{

		}
	    */
    if (request == null)
        throw new DNSException(DNSError.newError(Rcode.FORMERR));
    Header header = request.getHeader();
    if (header.getFlag(Flags.QR) || header.getRcode() != Rcode.NOERROR)
        throw new DNSException(DNSError.newError(Rcode.FORMERR));
    if (header.getOpcode() != Opcode.QUERY)
        throw new DNSException(DNSError.newError(Rcode.NOTIMP));
    Record question = request.getQuestion();
    if (question == null || question.getDClass() != DClass.IN) {
        throw new DNSException(DNSError.newError(Rcode.NOTIMP));
    }
    Record queryRecord = request.getQuestion();
    Name name = queryRecord.getName();
    int type = queryRecord.getType();
    if (LOGGER.isDebugEnabled()) {
        StringBuilder builder = new StringBuilder("Recieved Query Request:");
        builder.append("\r\n\tName: " + name.toString());
        builder.append("\r\n\tType: " + type);
        builder.append("\r\n\tDClass: " + queryRecord.getDClass());
        LOGGER.debug(builder.toString());
    }
    Collection<Record> lookupRecords = null;
    switch(question.getType()) {
        case Type.A:
        case Type.MX:
        case Type.SOA:
        case Type.SRV:
        case Type.NS:
        case Type.CNAME:
            {
                try {
                    final RRset set = processGenericRecordRequest(name.toString(), type);
                    if (set != null) {
                        lookupRecords = new ArrayList<Record>();
                        Iterator<Record> iter = set.rrs();
                        while (iter.hasNext()) lookupRecords.add(iter.next());
                    }
                } catch (Exception e) {
                    throw new DNSException(DNSError.newError(Rcode.SERVFAIL), "DNS service proxy call failed: " + e.getMessage(), e);
                }
                break;
            }
        case Type.CERT:
            {
                final RRset set = processCERTRecordRequest(name.toString());
                if (set != null) {
                    lookupRecords = new ArrayList<Record>();
                    Iterator<Record> iter = set.rrs();
                    while (iter.hasNext()) lookupRecords.add(iter.next());
                }
                break;
            }
        case Type.ANY:
            {
                Collection<Record> genRecs = processGenericANYRecordRequest(name.toString());
                RRset certRecs = processCERTRecordRequest(name.toString());
                if (genRecs != null || certRecs != null) {
                    lookupRecords = new ArrayList<Record>();
                    if (genRecs != null)
                        lookupRecords.addAll(genRecs);
                    if (certRecs != null) {
                        Iterator<Record> iter = certRecs.rrs();
                        while (iter.hasNext()) lookupRecords.add(iter.next());
                    }
                }
                break;
            }
        default:
            {
                LOGGER.debug("Query Type " + type + " not implemented");
                throw new DNSException(DNSError.newError(Rcode.NOTIMP), "Query Type " + type + " not implemented");
            }
    }
    if (lookupRecords == null || lookupRecords.size() == 0) {
        LOGGER.debug("No records found.");
        return null;
    }
    final Message response = new Message(request.getHeader().getID());
    response.getHeader().setFlag(Flags.QR);
    if (request.getHeader().getFlag(Flags.RD))
        response.getHeader().setFlag(Flags.RD);
    response.addRecord(queryRecord, Section.QUESTION);
    final Iterator<Record> iter = lookupRecords.iterator();
    while (iter.hasNext()) response.addRecord(iter.next(), Section.ANSWER);
    // we are authoritative only
    response.getHeader().setFlag(Flags.AA);
    // look for an SOA record
    final Record soaRecord = checkForSoaRecord(name.toString());
    if (soaRecord != null)
        response.addRecord(soaRecord, Section.AUTHORITY);
    LOGGER.trace("get(Message) Exit");
    return response;
}
Also used : Message(org.xbill.DNS.Message) RRset(org.xbill.DNS.RRset) ArrayList(java.util.ArrayList) CertificateConversionException(org.nhindirect.config.model.exceptions.CertificateConversionException) Name(org.xbill.DNS.Name) Header(org.xbill.DNS.Header) Iterator(java.util.Iterator) Collection(java.util.Collection) CERTRecord(org.xbill.DNS.CERTRecord) Record(org.xbill.DNS.Record) DnsRecord(org.nhind.config.DnsRecord)

Example 10 with Name

use of org.xbill.DNS.Name in project nhin-d by DirectProject.

the class DNSConnectionTest method performLookup.

private static void performLookup() throws Exception {
    // turn on debug settings for the DNS client
    Options.set("verbose", "true");
    Cache ch = Lookup.getDefaultCache(DClass.IN);
    ch.clearCache();
    if (servers == null || servers.length == 0)
        servers = ResolverConfig.getCurrentConfig().servers();
    System.out.println("\r\nConfigure DNS resolvers:");
    for (String server : servers) {
        System.out.println("\t" + server);
    }
    System.out.println("\r\nLookup up record " + lookupRec);
    Lookup lu = new Lookup(new Name(lookupRec), recType);
    ExtendedResolver resolver = new ExtendedResolver(servers);
    resolver.setTCP(useTCP);
    lu.setResolver(resolver);
    Record[] retRecords = lu.run();
    if (retRecords != null && retRecords.length > 0)
        System.out.println(retRecords.length + " records found.");
    else
        System.out.println("No records found.");
}
Also used : ExtendedResolver(org.xbill.DNS.ExtendedResolver) Lookup(org.xbill.DNS.Lookup) Record(org.xbill.DNS.Record) Cache(org.xbill.DNS.Cache) Name(org.xbill.DNS.Name)

Aggregations

Name (org.xbill.DNS.Name)35 Record (org.xbill.DNS.Record)16 Message (org.xbill.DNS.Message)8 ARecord (org.xbill.DNS.ARecord)7 SRVRecord (org.xbill.DNS.SRVRecord)7 UnknownHostException (java.net.UnknownHostException)6 ExtendedResolver (org.xbill.DNS.ExtendedResolver)6 IOException (java.io.IOException)5 CNAMERecord (org.xbill.DNS.CNAMERecord)5 Lookup (org.xbill.DNS.Lookup)5 NSRecord (org.xbill.DNS.NSRecord)5 TextParseException (org.xbill.DNS.TextParseException)5 Zone (org.xbill.DNS.Zone)5 ArrayList (java.util.ArrayList)4 JSONArray (org.json.JSONArray)4 JSONException (org.json.JSONException)4 JSONObject (org.json.JSONObject)4 Lookup (org.nhindirect.stagent.cert.impl.util.Lookup)4 File (java.io.File)3 InputStream (java.io.InputStream)3