--- /dev/null 2017-12-06 15:25:09.752000052 +0000 +++ new/src/java.naming/share/classes/javax/naming/spi/ldap/LdapDnsProvider.java 2017-12-06 17:43:08.087424920 +0000 @@ -0,0 +1,61 @@ +package javax.naming.spi.ldap; + +import java.util.Hashtable; + +/** + * DNS provider abstract class whose concrete implementations are used by + * {@code com.sun.jndi.ldap.LdapCtxFactory.getUsingURL()} to resolve ldap + * server urls. + * + * The ServiceLoader is used to create and register implementations of + * {@code LdapDnsProvider}. + * + * A DNS provider must subclass the {@link LdapDnsProvider} class. + * In addition, the provider class must be public and must have a + * public constructor that accepts no parameters. + */ +public abstract class LdapDnsProvider { + + /** + * The {@code RuntimePermission("ldapDnsProvider")} is + * necessary to subclass and instantiate the {@code LdapDnsProvider} class. + */ + public static final RuntimePermission DNSPROVIDER_PERMISSION = + new RuntimePermission("ldapDnsProvider"); + + /** + * Creates a new instance of {@code LdapDnsProvider}. + * + * @throws SecurityException if a security manager is present and its + * {@code checkPermission} method doesn't allow the + * {@code RuntimePermission("ldapDnsProvider")}. + */ + protected LdapDnsProvider() { + this(checkPermission()); + } + + private LdapDnsProvider(Void unused) { + // nothing to do. + } + + private static Void checkPermission() { + final SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission(DNSPROVIDER_PERMISSION); + } + return null; + } + + /** + * The {@code lookupEndpoints(String url, Hashtable env)} method + * takes two parameters: + * + * @param url The {@code Context.PROVIDER_URL} + * @param env The LdapCtx environment properties. + * + * @return an {@link LdapDnsProviderResult}. + */ + public abstract LdapDnsProviderResult lookupEndpoints( + String url, Hashtable env); + +}