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