2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
|
2
|
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 |
*
|
5506
|
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.
|
2
|
22 |
*/
|
|
23 |
|
|
24 |
/**
|
|
25 |
* @test
|
|
26 |
* @author Vincent Ryan
|
|
27 |
* @bug 6228412
|
|
28 |
* @summary Check that a Properties object can be passed to the Sasl create
|
|
29 |
* client and create server methods.
|
|
30 |
*/
|
|
31 |
|
|
32 |
import java.util.Hashtable;
|
|
33 |
import java.util.Map;
|
|
34 |
import java.util.Properties;
|
|
35 |
import javax.security.sasl.*;
|
|
36 |
import javax.security.auth.callback.*;
|
|
37 |
import org.ietf.jgss.GSSException;
|
|
38 |
|
|
39 |
public class PassSysProps {
|
|
40 |
|
|
41 |
private static final String PLAIN = "PLAIN";
|
|
42 |
private static final String DIGEST = "DIGEST-MD5";
|
|
43 |
private static final String CRAM = "CRAM-MD5";
|
|
44 |
private static final String EXTERNAL = "EXTERNAL";
|
|
45 |
private static final String GSSAPI = "GSSAPI";
|
|
46 |
|
|
47 |
public static void main(String[] args) throws Exception {
|
|
48 |
|
|
49 |
String authorizationId = null;
|
|
50 |
String protocol = "ldap";
|
|
51 |
String serverName = "server1";
|
|
52 |
|
|
53 |
CallbackHandler callbackHandler = new CallbackHandler(){
|
|
54 |
public void handle(Callback[] callbacks) {
|
|
55 |
}
|
|
56 |
};
|
|
57 |
|
|
58 |
// pass in system properties
|
|
59 |
|
|
60 |
Properties sysprops = System.getProperties();
|
|
61 |
|
|
62 |
SaslClient client1 =
|
|
63 |
Sasl.createSaslClient(new String[]{DIGEST, PLAIN}, authorizationId,
|
|
64 |
protocol, serverName, (Map) sysprops, callbackHandler);
|
|
65 |
System.out.println(client1);
|
|
66 |
|
|
67 |
SaslServer server1 =
|
|
68 |
Sasl.createSaslServer(DIGEST, protocol, serverName, (Map) sysprops,
|
|
69 |
callbackHandler);
|
|
70 |
System.out.println(server1);
|
|
71 |
|
|
72 |
// pass in string-valued props
|
|
73 |
|
|
74 |
Map<String, String> stringProps = new Hashtable<String, String>();
|
|
75 |
stringProps.put(Sasl.POLICY_NOPLAINTEXT, "true");
|
|
76 |
|
|
77 |
try {
|
|
78 |
|
|
79 |
SaslClient client2 =
|
|
80 |
Sasl.createSaslClient(new String[]{GSSAPI, PLAIN},
|
|
81 |
authorizationId, protocol, serverName, stringProps,
|
|
82 |
callbackHandler);
|
|
83 |
System.out.println(client2);
|
|
84 |
|
|
85 |
SaslServer server2 =
|
|
86 |
Sasl.createSaslServer(GSSAPI, protocol, serverName,
|
|
87 |
stringProps, callbackHandler);
|
|
88 |
System.out.println(server2);
|
|
89 |
|
|
90 |
} catch (SaslException se) {
|
|
91 |
Throwable t = se.getCause();
|
|
92 |
if (t instanceof GSSException) {
|
|
93 |
// allow GSSException because kerberos has not been initialized
|
|
94 |
|
|
95 |
} else {
|
|
96 |
throw se;
|
|
97 |
}
|
|
98 |
}
|
|
99 |
|
|
100 |
// pass in object-valued props
|
|
101 |
|
|
102 |
Map<String, Object> objProps = new Hashtable<String, Object>();
|
|
103 |
objProps.put("some.object.valued.property", System.err);
|
|
104 |
|
|
105 |
SaslClient client3 =
|
|
106 |
Sasl.createSaslClient(new String[]{EXTERNAL, CRAM}, authorizationId,
|
|
107 |
protocol, serverName, objProps, callbackHandler);
|
|
108 |
System.out.println(client3);
|
|
109 |
|
|
110 |
SaslServer server3 =
|
|
111 |
Sasl.createSaslServer(CRAM, protocol, serverName, objProps,
|
|
112 |
callbackHandler);
|
|
113 |
System.out.println(server3);
|
|
114 |
|
|
115 |
// pass in raw-type props
|
|
116 |
|
|
117 |
Map rawProps = new Hashtable();
|
|
118 |
rawProps.put(Sasl.POLICY_NOPLAINTEXT, "true");
|
|
119 |
rawProps.put("some.object.valued.property", System.err);
|
|
120 |
|
|
121 |
SaslClient client4 =
|
|
122 |
Sasl.createSaslClient(new String[]{EXTERNAL, CRAM}, authorizationId,
|
|
123 |
protocol, serverName, rawProps, callbackHandler);
|
|
124 |
System.out.println(client4);
|
|
125 |
|
|
126 |
SaslServer server4 =
|
|
127 |
Sasl.createSaslServer(CRAM, protocol, serverName, rawProps,
|
|
128 |
callbackHandler);
|
|
129 |
System.out.println(server4);
|
|
130 |
|
|
131 |
}
|
|
132 |
}
|