Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.naming/share/classes/com/sun/jndi/ldap/LdapSearchEnumeration.java
41161 views
1
/*
2
* Copyright (c) 1999, 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 com.sun.jndi.ldap;
27
28
import java.security.AccessControlContext;
29
import java.security.AccessController;
30
import java.security.PrivilegedActionException;
31
import java.security.PrivilegedExceptionAction;
32
import java.util.Vector;
33
import javax.naming.*;
34
import javax.naming.directory.*;
35
import javax.naming.spi.*;
36
import javax.naming.ldap.*;
37
import javax.naming.ldap.LdapName;
38
39
import com.sun.jndi.toolkit.ctx.Continuation;
40
41
final class LdapSearchEnumeration
42
extends AbstractLdapNamingEnumeration<SearchResult> {
43
44
private Name startName; // prefix of names of search results
45
private LdapCtx.SearchArgs searchArgs = null;
46
47
@SuppressWarnings("removal")
48
private final AccessControlContext acc = AccessController.getContext();
49
50
LdapSearchEnumeration(LdapCtx homeCtx, LdapResult search_results,
51
String starter, LdapCtx.SearchArgs args, Continuation cont)
52
throws NamingException {
53
54
super(homeCtx, search_results,
55
args.name, /* listArg */
56
cont);
57
58
// fully qualified name of starting context of search
59
startName = new LdapName(starter);
60
searchArgs = args;
61
}
62
63
@SuppressWarnings("removal")
64
@Override
65
protected SearchResult createItem(String dn, Attributes attrs,
66
Vector<Control> respCtls)
67
throws NamingException {
68
69
Object obj = null;
70
71
String relStart; // name relative to starting search context
72
String relHome; // name relative to homeCtx.currentDN
73
boolean relative = true; // whether relative to currentDN
74
75
// need to strip off all but lowest component of dn
76
// so that is relative to current context (currentDN)
77
78
try {
79
Name parsed = new LdapName(dn);
80
// System.err.println("dn string: " + dn);
81
// System.err.println("dn name: " + parsed);
82
83
if (startName != null && parsed.startsWith(startName)) {
84
relStart = parsed.getSuffix(startName.size()).toString();
85
relHome = parsed.getSuffix(homeCtx.currentParsedDN.size()).toString();
86
} else {
87
relative = false;
88
relHome = relStart =
89
LdapURL.toUrlString(homeCtx.hostname, homeCtx.port_number,
90
dn, homeCtx.hasLdapsScheme);
91
}
92
} catch (NamingException e) {
93
// could not parse name
94
relative = false;
95
relHome = relStart =
96
LdapURL.toUrlString(homeCtx.hostname, homeCtx.port_number,
97
dn, homeCtx.hasLdapsScheme);
98
}
99
100
// Name relative to search context
101
CompositeName cn = new CompositeName();
102
if (!relStart.isEmpty()) {
103
cn.add(relStart);
104
}
105
106
// Name relative to homeCtx
107
CompositeName rcn = new CompositeName();
108
if (!relHome.isEmpty()) {
109
rcn.add(relHome);
110
}
111
//System.err.println("relStart: " + cn);
112
//System.err.println("relHome: " + rcn);
113
114
// Fix attributes to be able to get schema
115
homeCtx.setParents(attrs, rcn);
116
117
// only generate object when requested
118
if (searchArgs.cons.getReturningObjFlag()) {
119
120
if (attrs.get(Obj.JAVA_ATTRIBUTES[Obj.CLASSNAME]) != null) {
121
// Entry contains Java-object attributes (ser/ref object)
122
// serialized object or object reference
123
try {
124
PrivilegedExceptionAction<Object> pea = () -> Obj.decodeObject(attrs);
125
obj = AccessController.doPrivileged(pea, acc);
126
} catch (PrivilegedActionException e) {
127
throw (NamingException)e.getException();
128
}
129
}
130
if (obj == null) {
131
obj = new LdapCtx(homeCtx, dn);
132
}
133
134
// Call getObjectInstance before removing unrequested attributes
135
try {
136
// rcn is either relative to homeCtx or a fully qualified DN
137
obj = DirectoryManager.getObjectInstance(
138
obj, rcn, (relative ? homeCtx : null),
139
homeCtx.envprops, attrs);
140
} catch (NamingException e) {
141
throw e;
142
} catch (Exception e) {
143
NamingException ne =
144
new NamingException(
145
"problem generating object using object factory");
146
ne.setRootCause(e);
147
throw ne;
148
}
149
150
// remove Java attributes from result, if necessary
151
// Even if CLASSNAME attr not there, there might be some
152
// residual attributes
153
154
String[] reqAttrs;
155
if ((reqAttrs = searchArgs.reqAttrs) != null) {
156
// create an attribute set for those requested
157
Attributes rattrs = new BasicAttributes(true); // ignore case
158
for (int i = 0; i < reqAttrs.length; i++) {
159
rattrs.put(reqAttrs[i], null);
160
}
161
for (int i = 0; i < Obj.JAVA_ATTRIBUTES.length; i++) {
162
// Remove Java-object attributes if not requested
163
if (rattrs.get(Obj.JAVA_ATTRIBUTES[i]) == null) {
164
attrs.remove(Obj.JAVA_ATTRIBUTES[i]);
165
}
166
}
167
}
168
169
}
170
171
/*
172
* name in search result is either the stringified composite name
173
* relative to the search context that can be passed directly to
174
* methods of the search context, or the fully qualified DN
175
* which can be used with the initial context.
176
*/
177
SearchResult sr;
178
if (respCtls != null) {
179
sr = new SearchResultWithControls(
180
(relative ? cn.toString() : relStart), obj, attrs,
181
relative, homeCtx.convertControls(respCtls));
182
} else {
183
sr = new SearchResult(
184
(relative ? cn.toString() : relStart),
185
obj, attrs, relative);
186
}
187
sr.setNameInNamespace(dn);
188
return sr;
189
}
190
191
@Override
192
public void appendUnprocessedReferrals(LdapReferralException ex) {
193
194
// a referral has been followed so do not create relative names
195
startName = null;
196
super.appendUnprocessedReferrals(ex);
197
}
198
199
@Override
200
protected AbstractLdapNamingEnumeration<? extends NameClassPair> getReferredResults(
201
LdapReferralContext refCtx) throws NamingException {
202
// repeat the original operation at the new context
203
return (AbstractLdapNamingEnumeration<? extends NameClassPair>)refCtx.search(
204
searchArgs.name, searchArgs.filter, searchArgs.cons);
205
}
206
207
@Override
208
protected void update(AbstractLdapNamingEnumeration<? extends NameClassPair> ne) {
209
super.update(ne);
210
211
// Update search-specific variables
212
LdapSearchEnumeration se = (LdapSearchEnumeration)ne;
213
startName = se.startName;
214
}
215
216
void setStartName(Name nm) {
217
startName = nm;
218
}
219
}
220
221