1 package javax.naming.ldap; 2 3 import java.util.Hashtable; 4 import javax.naming.ldap.LdapDnsProviderResult; 5 6 /** 7 * DNS provider abstract class whose concrete implementations are used by 8 * {@code com.sun.jndi.ldap.LdapCtxFactory.getUsingURL()} to resolve ldap 9 * server urls. 10 * 11 * The ServiceLoader is used to create and register implementations of 12 * {@code LdapDnsProvider}. 13 * 14 * A DNS provider must subclass the {@link LdapDnsProvider} class. 15 * In addition, the provider class must be public and must have a 16 * public constructor that accepts no parameters. 17 */ 18 public abstract class LdapDnsProvider { 19 20 /** 21 * The {@code RuntimePermission("ldapDnsProvider")} is 22 * necessary to subclass and instantiate the {@code LdapDnsProvider} class. 23 */ 24 public static final RuntimePermission DNSPROVIDER_PERMISSION = 25 new RuntimePermission("ldapDnsProvider"); 26 27 /** 28 * Creates a new instance of {@code LdapDnsProvider}. 29 * 30 * @throws SecurityException if a security manager is present and its 31 * {@code checkPermission} method doesn't allow the 32 * {@code RuntimePermission("ldapDnsProvider")}. 33 */ 34 protected LdapDnsProvider() { 35 this(checkPermission()); 36 } 37 38 private LdapDnsProvider(Void unused) { 39 // nothing to do. 40 } 41 42 private static Void checkPermission() { 43 final SecurityManager sm = System.getSecurityManager(); 44 if (sm != null) { 45 sm.checkPermission(DNSPROVIDER_PERMISSION); 46 } 47 return null; 48 } 49 50 /** 51 * The {@code lookupEndpoints(String url, Hashtable<?,?> env)} method 52 * takes two parameters: 53 * 54 * @param url The {@code Context.PROVIDER_URL} 55 * @param env The LdapCtx environment properties. 56 * 57 * @return an {@link LdapDnsProviderResult}. 58 */ 59 public abstract LdapDnsProviderResult lookupEndpoints( 60 String url, Hashtable<?,?> env); 61 62 }