Does JNDI use the DNS search list?

I would like to use JNDI to look up Kerberos SRV records in a local network. I try to guess the local domain in hopefully clever ways. If that fails I would like to look up the plain entry, e.g. `_kerberos._tcp` without any suffix and rely on the DNS domain search list to find the right entry. This works on Windows with `nslookup -type=srv _kerberos._tcp` and Linux with `host -t srv _kerberos._tcp`. The domain `example.test` is appended and the entry is found. Here is an example program to do DNS lookups via JNDI: import java.util.Hashtable; import javax.naming.Context; import javax.naming.NamingEnumeration; import javax.naming.NamingException; import; import; import; import; public class JndiDnsTest { public static void main(String[] args) { if (args.length < 2) { System.out.println("Usage: " + JndiDnsTest.class.getName() + " name record-types..."); return; } String name = args[0]; String[] recordTypes = new String[args.length - 1]; System.arraycopy(args, 1, recordTypes, 0, args.length - 1); Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory"); try { DirContext ctx = new InitialDirContext(env); Attributes dnsQueryResult = ctx.getAttributes(name, recordTypes); if (dnsQueryResult == null) { System.out.println("Not found: '" + name + "'"); } for (String rrType: recordTypes) { Attribute rr = dnsQueryResult.get(rrType); if (rr != null) { for (NamingEnumeration vals = rr.getAll(); vals.hasMoreElements();) { System.out.print(rrType + "\t"); System.out.println(vals.nextElement()); } } } } catch (NamingException e) { e.printStackTrace(System.err); } System.out.println("\nThe DNS search list:"); for (Object entry: { System.out.println(entry); } System.out.println("\ = " + System.getProperty("")); } } It appears to me that JNDI only does one lookup for the direct name. No entry is found where above commands succeed. It seems it does not use the DNS search list. Its contents are printed correctly at the bottom, though. On the other hand the [Networking properties documentation][1] says that > If the property is not defined then the provider will use any domain or domain search list configured in the platform DNS configuration. (The property is not set.) The Java version is Sun Java 1.6.0_20. **Does JNDI use the DNS search list or not?** [1]:

以上就是Does JNDI use the DNS search list?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准