Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/jndi/ldap/LdapName/EmptyNameSearch.java
41155 views
1
/*
2
* Copyright (c) 2011, 2020, 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.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/**
25
* @test
26
* @bug 6997561
27
* @summary A request for better error handling in JNDI
28
* @library ../lib/ /test/lib
29
*/
30
31
import java.net.Socket;
32
import java.io.*;
33
import javax.naming.*;
34
import javax.naming.directory.*;
35
import javax.naming.ldap.*;
36
import java.util.Collections;
37
import java.util.Hashtable;
38
import jdk.test.lib.net.URIBuilder;
39
40
public class EmptyNameSearch {
41
42
private static final byte[] bindResponse = {
43
0x30, 0x0C, 0x02, 0x01, 0x01, 0x61, 0x07, 0x0A,
44
0x01, 0x00, 0x04, 0x00, 0x04, 0x00
45
};
46
private static final byte[] searchResponse = {
47
0x30, 0x0C, 0x02, 0x01, 0x02, 0x65, 0x07, 0x0A,
48
0x01, 0x02, 0x04, 0x00, 0x04, 0x00
49
};
50
51
public static void main(String[] args) throws Exception {
52
53
// Start the LDAP server
54
var ldapServer = new BaseLdapServer() {
55
@Override
56
protected void handleRequest(Socket socket, LdapMessage request,
57
OutputStream out) throws IOException {
58
switch (request.getOperation()) {
59
case BIND_REQUEST:
60
out.write(bindResponse);
61
break;
62
case SEARCH_REQUEST:
63
out.write(searchResponse);
64
break;
65
default:
66
break;
67
}
68
}
69
}.start();
70
Thread.sleep(3000);
71
72
// Setup JNDI parameters
73
Hashtable<Object, Object> env = new Hashtable<>();
74
env.put(Context.INITIAL_CONTEXT_FACTORY,
75
"com.sun.jndi.ldap.LdapCtxFactory");
76
env.put(Context.PROVIDER_URL, URIBuilder.newBuilder()
77
.scheme("ldap")
78
.loopback()
79
.port(ldapServer.getPort())
80
.build().toString());
81
82
try (ldapServer) {
83
84
// Create initial context
85
System.out.println("Client: connecting...");
86
DirContext ctx = new InitialDirContext(env);
87
88
System.out.println("Client: performing search...");
89
ctx.search(new LdapName(Collections.emptyList()), "cn=*", null);
90
ctx.close();
91
92
// Exit
93
throw new RuntimeException();
94
95
} catch (NamingException e) {
96
System.err.println("Passed: caught the expected Exception - " + e);
97
98
} catch (Exception e) {
99
System.err.println("Failed: caught an unexpected Exception - " + e);
100
throw e;
101
}
102
}
103
}
104
105