Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.naming/share/classes/javax/naming/ldap/spi/LdapDnsProvider.java
41161 views
1
/*
2
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package javax.naming.ldap.spi;
27
28
import javax.naming.Context;
29
import javax.naming.NamingException;
30
import java.util.Map;
31
import java.util.Optional;
32
33
/**
34
* Service-provider class for DNS lookups when performing LDAP operations.
35
*
36
* <p> An LDAP DNS provider is a concrete subclass of this class that
37
* has a zero-argument constructor. LDAP DNS providers are located using the
38
* ServiceLoader facility, as specified by
39
* {@linkplain javax.naming.directory.InitialDirContext InitialDirectContext}.
40
*
41
* The
42
* {@link java.util.ServiceLoader ServiceLoader} is used to create and register
43
* implementations of {@code LdapDnsProvider}.
44
*
45
* <p> An LDAP DNS provider can be used in environments where the default
46
* DNS resolution mechanism is not sufficient to accurately pinpoint the
47
* correct LDAP servers needed to perform LDAP operations. For example, in an
48
* environment containing a mix of {@code ldap} and {@code ldaps} servers
49
* you may want the {@linkplain javax.naming.ldap.LdapContext LdapContext}
50
* to query {@code ldaps} servers only.
51
*
52
* @since 12
53
*/
54
public abstract class LdapDnsProvider {
55
56
// The {@code RuntimePermission("ldapDnsProvider")} is
57
// necessary to subclass and instantiate the {@code LdapDnsProvider} class.
58
private static final RuntimePermission DNSPROVIDER_PERMISSION =
59
new RuntimePermission("ldapDnsProvider");
60
61
/**
62
* Creates a new instance of {@code LdapDnsProvider}.
63
*
64
* @throws SecurityException if a security manager is present and its
65
* {@code checkPermission} method doesn't allow
66
* the {@code RuntimePermission("ldapDnsProvider")}.
67
*/
68
protected LdapDnsProvider() {
69
this(checkPermission());
70
}
71
72
private LdapDnsProvider(Void unused) {
73
// nothing to do.
74
}
75
76
private static Void checkPermission() {
77
@SuppressWarnings("removal")
78
final SecurityManager sm = System.getSecurityManager();
79
if (sm != null) {
80
sm.checkPermission(DNSPROVIDER_PERMISSION);
81
}
82
return null;
83
}
84
85
/**
86
* Lookup the endpoints and domain name for the given {@link Context}
87
* {@link Context#PROVIDER_URL provider URL} and environment. The resolved
88
* endpoints and domain name are returned as an
89
* {@link LdapDnsProviderResult}.
90
*
91
* <p> An endpoint is a {@code String} representation of an LDAP URL which
92
* points to an LDAP server to be used for LDAP operations. The syntax of
93
* an LDAP URL is defined by <a href="http://www.ietf.org/rfc/rfc2255.txt">
94
* <i>RFC&nbsp;2255: The LDAP URL Format</i></a>.
95
*
96
* @param url The {@link Context} {@link Context#PROVIDER_URL provider URL}
97
* @param env The {@link Context} environment.
98
*
99
* @return an {@link LdapDnsProviderResult} or empty {@code Optional}
100
* if the lookup fails.
101
*
102
* @throws NamingException if the {@code url} is not valid or an error
103
* occurred while performing the lookup.
104
* @throws NullPointerException if either {@code url} or {@code env} are
105
* {@code null}.
106
*/
107
public abstract Optional<LdapDnsProviderResult> lookupEndpoints(
108
String url, Map<?,?> env) throws NamingException;
109
}
110
111