author | mbalao |
Wed, 05 Jun 2019 01:42:11 -0300 | |
changeset 55258 | d65d3c37232c |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
14327
diff
changeset
|
2 |
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
12047 | 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.Collection; |
|
30 |
import java.util.Hashtable; |
|
31 |
import java.util.Vector; |
|
32 |
||
33 |
||
34 |
public class SCDynamicStoreConfig { |
|
35 |
private static native void installNotificationCallback(); |
|
36 |
private static native Hashtable<String, Object> getKerberosConfig(); |
|
14327 | 37 |
private static boolean DEBUG = sun.security.krb5.internal.Krb5.DEBUG; |
12047 | 38 |
|
39 |
static { |
|
14327 | 40 |
boolean isMac = java.security.AccessController.doPrivileged( |
41 |
new java.security.PrivilegedAction<Boolean>() { |
|
42 |
public Boolean run() { |
|
43 |
String osname = System.getProperty("os.name"); |
|
44 |
if (osname.contains("OS X")) { |
|
22951
5fd21112b2b6
8034043: Native methods for preferences API should not be in libjava
alanb
parents:
14342
diff
changeset
|
45 |
System.loadLibrary("osxkrb5"); |
14327 | 46 |
return true; |
47 |
} |
|
48 |
return false; |
|
12559
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
12047
diff
changeset
|
49 |
} |
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
12047
diff
changeset
|
50 |
}); |
14327 | 51 |
if (isMac) installNotificationCallback(); |
12047 | 52 |
} |
53 |
||
14327 | 54 |
private static Vector<String> unwrapHost( |
55 |
Collection<Hashtable<String, String>> c) { |
|
12047 | 56 |
Vector<String> vector = new Vector<String>(); |
57 |
for (Hashtable<String, String> m : c) { |
|
58 |
vector.add(m.get("host")); |
|
59 |
} |
|
60 |
return vector; |
|
61 |
} |
|
62 |
||
63 |
/** |
|
64 |
* convertRealmConfigs: Maps the Object graph that we get from JNI to the |
|
65 |
* object graph that Config expects. Also the items inside the kdc array |
|
66 |
* are wrapped inside Hashtables |
|
67 |
*/ |
|
68 |
@SuppressWarnings("unchecked") |
|
14327 | 69 |
private static Hashtable<String, Object> |
70 |
convertRealmConfigs(Hashtable<String, ?> configs) { |
|
12047 | 71 |
Hashtable<String, Object> realmsTable = new Hashtable<String, Object>(); |
72 |
||
73 |
for (String realm : configs.keySet()) { |
|
74 |
// get the kdc |
|
14327 | 75 |
Hashtable<String, Collection<?>> map = |
76 |
(Hashtable<String, Collection<?>>) configs.get(realm); |
|
77 |
Hashtable<String, Vector<String>> realmMap = |
|
78 |
new Hashtable<String, Vector<String>>(); |
|
12047 | 79 |
|
80 |
// put the kdc into the realmMap |
|
14327 | 81 |
Collection<Hashtable<String, String>> kdc = |
82 |
(Collection<Hashtable<String, String>>) map.get("kdc"); |
|
12047 | 83 |
if (kdc != null) realmMap.put("kdc", unwrapHost(kdc)); |
84 |
||
85 |
// put the admin server into the realmMap |
|
14327 | 86 |
Collection<Hashtable<String, String>> kadmin = |
87 |
(Collection<Hashtable<String, String>>) map.get("kadmin"); |
|
12047 | 88 |
if (kadmin != null) realmMap.put("admin_server", unwrapHost(kadmin)); |
89 |
||
90 |
// add the full entry to the realmTable |
|
91 |
realmsTable.put(realm, realmMap); |
|
92 |
} |
|
93 |
||
94 |
return realmsTable; |
|
95 |
} |
|
96 |
||
97 |
/** |
|
98 |
* Calls down to JNI to get the raw Kerberos Config and maps the object |
|
99 |
* graph to the one that Kerberos Config in Java expects |
|
100 |
* |
|
101 |
* @return |
|
102 |
* @throws IOException |
|
103 |
*/ |
|
104 |
public static Hashtable<String, Object> getConfig() throws IOException { |
|
105 |
Hashtable<String, Object> stanzaTable = getKerberosConfig(); |
|
106 |
if (stanzaTable == null) { |
|
14327 | 107 |
throw new IOException( |
108 |
"Could not load configuration from SCDynamicStore"); |
|
12047 | 109 |
} |
14327 | 110 |
if (DEBUG) System.out.println("Raw map from JNI: " + stanzaTable); |
111 |
return convertNativeConfig(stanzaTable); |
|
112 |
} |
|
12047 | 113 |
|
14327 | 114 |
@SuppressWarnings("unchecked") |
115 |
private static Hashtable<String, Object> convertNativeConfig( |
|
28564
be13305854f5
8071313: krb5.conf not read if SCDynamicStore krb5 config is empty
weijun
parents:
25859
diff
changeset
|
116 |
Hashtable<String, Object> stanzaTable) throws IOException { |
12047 | 117 |
// convert SCDynamicStore realm structure to Java realm structure |
14327 | 118 |
Hashtable<String, ?> realms = |
119 |
(Hashtable<String, ?>) stanzaTable.get("realms"); |
|
28564
be13305854f5
8071313: krb5.conf not read if SCDynamicStore krb5 config is empty
weijun
parents:
25859
diff
changeset
|
120 |
if (realms == null || realms.isEmpty()) { |
be13305854f5
8071313: krb5.conf not read if SCDynamicStore krb5 config is empty
weijun
parents:
25859
diff
changeset
|
121 |
throw new IOException( |
be13305854f5
8071313: krb5.conf not read if SCDynamicStore krb5 config is empty
weijun
parents:
25859
diff
changeset
|
122 |
"SCDynamicStore contains an empty Kerberos setting"); |
12047 | 123 |
} |
28564
be13305854f5
8071313: krb5.conf not read if SCDynamicStore krb5 config is empty
weijun
parents:
25859
diff
changeset
|
124 |
stanzaTable.remove("realms"); |
be13305854f5
8071313: krb5.conf not read if SCDynamicStore krb5 config is empty
weijun
parents:
25859
diff
changeset
|
125 |
Hashtable<String, Object> realmsTable = convertRealmConfigs(realms); |
be13305854f5
8071313: krb5.conf not read if SCDynamicStore krb5 config is empty
weijun
parents:
25859
diff
changeset
|
126 |
stanzaTable.put("realms", realmsTable); |
14327 | 127 |
WrapAllStringInVector(stanzaTable); |
128 |
if (DEBUG) System.out.println("stanzaTable : " + stanzaTable); |
|
12047 | 129 |
return stanzaTable; |
130 |
} |
|
14327 | 131 |
|
132 |
@SuppressWarnings("unchecked") |
|
133 |
private static void WrapAllStringInVector( |
|
134 |
Hashtable<String, Object> stanzaTable) { |
|
135 |
for (String s: stanzaTable.keySet()) { |
|
136 |
Object v = stanzaTable.get(s); |
|
137 |
if (v instanceof Hashtable) { |
|
138 |
WrapAllStringInVector((Hashtable<String,Object>)v); |
|
139 |
} else if (v instanceof String) { |
|
140 |
Vector<String> vec = new Vector<>(); |
|
141 |
vec.add((String)v); |
|
142 |
stanzaTable.put(s, vec); |
|
143 |
} |
|
144 |
} |
|
145 |
} |
|
12047 | 146 |
} |