1 /*
2 * Copyright (c) 2009, 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 */
86 is.skip(is.available());
87 }
88
89 is.close();
90 os.close();
91 socket.close();
92 serverSock.close();
93 }
94
95 // Define the client side of the test.
96 //
97 // If the server prematurely exits, serverReady will be set to true
98 // to avoid infinite hangs.
99 void doClientSide() throws Exception {
100 // Wait for server to get started.
101 while (!serverReady) {
102 Thread.sleep(50);
103 }
104
105 // set up the environment for creating the initial context
106 Hashtable<Object, Object> env = new Hashtable<Object, Object>();
107 env.put(Context.INITIAL_CONTEXT_FACTORY,
108 "com.sun.jndi.ldap.LdapCtxFactory");
109 env.put(Context.PROVIDER_URL, "ldap://localhost:" + serverPort);
110 env.put("com.sun.jndi.ldap.read.timeout", "1000");
111
112 // env.put(Context.SECURITY_AUTHENTICATION, "simple");
113 // env.put(Context.SECURITY_PRINCIPAL,"cn=root");
114 // env.put(Context.SECURITY_CREDENTIALS,"root");
115
116 // create initial context
117 DirContext context = new InitialDirContext(env);
118
119 // searching
120 SearchControls scs = new SearchControls();
121 scs.setSearchScope(SearchControls.SUBTREE_SCOPE);
122
123 try {
124 NamingEnumeration answer = context.search(
125 "o=sun,c=us", "(&(cn=Bob)))", scs);
126 } catch (InvalidSearchFilterException isfe) {
127 // ignore, it is the expected filter exception.
128 System.out.println("Expected exception: " + isfe.getMessage());
129 } catch (NamingException ne) {
130 // maybe a read timeout exception, as the server does not response.
131 throw new Exception("Expect a InvalidSearchFilterException", ne);
132 }
133
134 try {
135 NamingEnumeration answer = context.search(
136 "o=sun,c=us", ")(&(cn=Bob)", scs);
137 } catch (InvalidSearchFilterException isfe) {
138 // ignore, it is the expected filter exception.
139 System.out.println("Expected exception: " + isfe.getMessage());
140 } catch (NamingException ne) {
141 // maybe a read timeout exception, as the server does not response.
142 throw new Exception("Expect a InvalidSearchFilterException", ne);
143 }
144
145 try {
146 NamingEnumeration answer = context.search(
147 "o=sun,c=us", "(&(cn=Bob))", scs);
148 } catch (InvalidSearchFilterException isfe) {
149 // ignore, it is the expected filter exception.
150 throw new Exception("Unexpected ISFE", isfe);
151 } catch (NamingException ne) {
152 // maybe a read timeout exception, as the server does not response.
153 System.out.println("Expected exception: " + ne.getMessage());
154 }
155
156 context.close();
157 }
158
159 /*
160 * ============================================================
161 * The remainder is just support stuff
162 */
163
164 // client and server thread
165 Thread clientThread = null;
166 Thread serverThread = null;
|
1 /*
2 * Copyright (c) 2009, 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 */
86 is.skip(is.available());
87 }
88
89 is.close();
90 os.close();
91 socket.close();
92 serverSock.close();
93 }
94
95 // Define the client side of the test.
96 //
97 // If the server prematurely exits, serverReady will be set to true
98 // to avoid infinite hangs.
99 void doClientSide() throws Exception {
100 // Wait for server to get started.
101 while (!serverReady) {
102 Thread.sleep(50);
103 }
104
105 // set up the environment for creating the initial context
106 Hashtable<Object, Object> env = new Hashtable<>();
107 env.put(Context.INITIAL_CONTEXT_FACTORY,
108 "com.sun.jndi.ldap.LdapCtxFactory");
109 env.put(Context.PROVIDER_URL, "ldap://localhost:" + serverPort);
110 env.put("com.sun.jndi.ldap.read.timeout", "1000");
111
112 // env.put(Context.SECURITY_AUTHENTICATION, "simple");
113 // env.put(Context.SECURITY_PRINCIPAL,"cn=root");
114 // env.put(Context.SECURITY_CREDENTIALS,"root");
115
116 // create initial context
117 DirContext context = new InitialDirContext(env);
118
119 // searching
120 SearchControls scs = new SearchControls();
121 scs.setSearchScope(SearchControls.SUBTREE_SCOPE);
122
123 try {
124 NamingEnumeration<?> answer = context.search(
125 "o=sun,c=us", "(&(cn=Bob)))", scs);
126 } catch (InvalidSearchFilterException isfe) {
127 // ignore, it is the expected filter exception.
128 System.out.println("Expected exception: " + isfe.getMessage());
129 } catch (NamingException ne) {
130 // maybe a read timeout exception, as the server does not response.
131 throw new Exception("Expect a InvalidSearchFilterException", ne);
132 }
133
134 try {
135 NamingEnumeration<?> answer = context.search(
136 "o=sun,c=us", ")(&(cn=Bob)", scs);
137 } catch (InvalidSearchFilterException isfe) {
138 // ignore, it is the expected filter exception.
139 System.out.println("Expected exception: " + isfe.getMessage());
140 } catch (NamingException ne) {
141 // maybe a read timeout exception, as the server does not response.
142 throw new Exception("Expect a InvalidSearchFilterException", ne);
143 }
144
145 try {
146 NamingEnumeration<?> answer = context.search(
147 "o=sun,c=us", "(&(cn=Bob))", scs);
148 } catch (InvalidSearchFilterException isfe) {
149 // ignore, it is the expected filter exception.
150 throw new Exception("Unexpected ISFE", isfe);
151 } catch (NamingException ne) {
152 // maybe a read timeout exception, as the server does not response.
153 System.out.println("Expected exception: " + ne.getMessage());
154 }
155
156 context.close();
157 }
158
159 /*
160 * ============================================================
161 * The remainder is just support stuff
162 */
163
164 // client and server thread
165 Thread clientThread = null;
166 Thread serverThread = null;
|