Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.security.jgss/share/classes/sun/security/krb5/SCDynamicStoreConfig.java
41159 views
1
/*
2
* Copyright (c) 2011, 2021, 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package sun.security.krb5;
27
28
import java.io.IOException;
29
import java.util.Hashtable;
30
import java.util.Iterator;
31
import java.util.List;
32
import java.util.Vector;
33
34
35
public class SCDynamicStoreConfig {
36
private static native void installNotificationCallback();
37
38
/**
39
* Returns the dynamic store setting for kerberos in a string array.
40
* (realm kdc* null) null (mapping-domain mapping-realm)*
41
*/
42
private static native List<String> getKerberosConfig();
43
private static boolean DEBUG = sun.security.krb5.internal.Krb5.DEBUG;
44
45
static {
46
@SuppressWarnings("removal")
47
boolean isMac = java.security.AccessController.doPrivileged(
48
new java.security.PrivilegedAction<Boolean>() {
49
public Boolean run() {
50
String osname = System.getProperty("os.name");
51
if (osname.contains("OS X")) {
52
System.loadLibrary("osxkrb5");
53
return true;
54
}
55
return false;
56
}
57
});
58
if (isMac) installNotificationCallback();
59
}
60
61
/**
62
* Calls down to JNI to get the raw Kerberos Config and maps the object
63
* graph to the one that Kerberos Config in Java expects
64
*
65
* @return
66
* @throws IOException
67
*/
68
public static Hashtable<String, Object> getConfig() throws IOException {
69
List<String> list = getKerberosConfig();
70
if (list == null) {
71
throw new IOException(
72
"Could not load configuration from SCDynamicStore");
73
}
74
if (DEBUG) System.out.println("Raw map from JNI: " + list);
75
76
Hashtable<String,Object> v = new Hashtable<>();
77
Hashtable<String,Object> realms = new Hashtable<>();
78
Iterator<String> iterator = list.iterator();
79
String defaultRealm = null;
80
81
while (true) {
82
String nextRealm = iterator.next();
83
if (nextRealm == null) {
84
break;
85
}
86
if (defaultRealm == null) {
87
defaultRealm = nextRealm;
88
Hashtable<String,Object> dr = new Hashtable<>();
89
dr.put("default_realm", v1(defaultRealm));
90
v.put("libdefaults", dr);
91
}
92
Vector<String> kdcs = new Vector<>();
93
while (true) {
94
String nextKdc = iterator.next();
95
if (nextKdc == null) {
96
break;
97
}
98
kdcs.add(nextKdc);
99
}
100
if (!kdcs.isEmpty()) {
101
Hashtable<String,Object> ri = new Hashtable<>();
102
ri.put("kdc", kdcs);
103
realms.put(nextRealm, ri);
104
}
105
}
106
if (!realms.isEmpty()) {
107
v.put("realms", realms);
108
}
109
Hashtable<String,Object> mapping = new Hashtable<>();
110
while (true) {
111
if (!iterator.hasNext()) {
112
break;
113
}
114
mapping.put(iterator.next(), v1(iterator.next()));
115
}
116
if (!mapping.isEmpty()) {
117
v.put("domain_realm", mapping);
118
}
119
return v;
120
}
121
122
// Make a single value Vector. Config's stanzaTable always
123
// use Vector as end values.
124
private static Vector<String> v1(String s) {
125
Vector<String> out = new Vector<>();
126
out.add(s);
127
return out;
128
}
129
}
130
131