Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/jndi/ldap/blits/AddTests/AddNewEntry.java
41161 views
1
/*
2
* Copyright (c) 2018, 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 8196770
27
* @summary Verify capability to add a new entry to the directory using the
28
* ADD operation.
29
* @modules java.naming/com.sun.jndi.ldap
30
* @library /test/lib ../../lib/ /javax/naming/module/src/test/test/
31
* @build LDAPServer LDAPTestUtils
32
* @run main/othervm AddNewEntry
33
*/
34
35
import javax.naming.NamingEnumeration;
36
import javax.naming.directory.Attribute;
37
import javax.naming.directory.Attributes;
38
import javax.naming.directory.BasicAttribute;
39
import javax.naming.directory.BasicAttributes;
40
import javax.naming.directory.DirContext;
41
import javax.naming.directory.InitialDirContext;
42
import javax.naming.directory.SearchControls;
43
import javax.naming.directory.SearchResult;
44
import java.net.InetAddress;
45
import java.net.InetSocketAddress;
46
import java.net.ServerSocket;
47
import java.net.SocketAddress;
48
import java.util.Hashtable;
49
import jdk.test.lib.net.URIBuilder;
50
51
public class AddNewEntry {
52
53
public static void main(String[] args) throws Exception {
54
// Create unbound server socket
55
ServerSocket serverSocket = new ServerSocket();
56
57
// Bind it to the loopback address
58
SocketAddress sockAddr = new InetSocketAddress(
59
InetAddress.getLoopbackAddress(), 0);
60
serverSocket.bind(sockAddr);
61
62
// Construct the provider URL for LDAPTestUtils
63
String providerURL = URIBuilder.newBuilder()
64
.scheme("ldap")
65
.loopback()
66
.port(serverSocket.getLocalPort())
67
.buildUnchecked().toString();
68
69
Hashtable<Object, Object> env;
70
71
// initialize test
72
env = LDAPTestUtils.initEnv(serverSocket, providerURL,
73
AddNewEntry.class.getName(), args, true);
74
75
/* Build attribute set */
76
String[] ids = { "objectClass", "sn", "cn", "telephoneNumber", "mail",
77
"description", "uid" };
78
Attribute objectClass = new BasicAttribute(ids[0]);
79
objectClass.add("top");
80
objectClass.add("person");
81
objectClass.add("organizationalPerson");
82
objectClass.add("inetOrgPerson");
83
84
Attribute sn = new BasicAttribute(ids[1], "Powers");
85
Attribute cn = new BasicAttribute(ids[2],
86
"Austin \\\"Danger\\\" Powers");
87
Attribute telephoneNumber = new BasicAttribute(ids[3], "+44 582 10101");
88
Attribute mail = new BasicAttribute(ids[4], "[email protected]");
89
Attribute description = new BasicAttribute(ids[5], "Yea Baby!!");
90
description.add("Behave!");
91
Attribute uid = new BasicAttribute(ids[6], "secret_agent_man");
92
93
Attributes attrs = new BasicAttributes();
94
attrs.put(objectClass);
95
attrs.put(sn);
96
attrs.put(cn);
97
attrs.put(telephoneNumber);
98
attrs.put(mail);
99
attrs.put(description);
100
attrs.put(uid);
101
102
DirContext ctx = null;
103
String[] bases = new String[] { (String) env.get("client"),
104
(String) env.get("vendor"), "Add" };
105
String baseDN = LDAPTestUtils.buildDN(bases, (String) env.get("root"));
106
String entryDN = "cn=Austin Powers," + baseDN;
107
String expect = ""; // relative name
108
109
try {
110
// connect to server
111
ctx = new InitialDirContext(env);
112
113
// add entry
114
ctx.createSubcontext(entryDN, attrs);
115
116
// specify base search
117
SearchControls constraints = new SearchControls();
118
constraints.setSearchScope(SearchControls.OBJECT_SCOPE);
119
120
NamingEnumeration<SearchResult> results = ctx
121
.search(entryDN, "(objectclass=*)", constraints);
122
123
int found = LDAPTestUtils.checkResult(results, expect);
124
125
if (found != 1) {
126
throw new RuntimeException(
127
"Check result failed, expect found 1 but actual is "
128
+ found);
129
}
130
131
} finally {
132
LDAPTestUtils.cleanupSubcontext(ctx, entryDN);
133
LDAPTestUtils.cleanup(ctx);
134
}
135
}
136
}
137
138