|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
package sun.security.krb5; |
|
|
|
import java.io.IOException; |
|
import java.util.Collection; |
|
import java.util.Hashtable; |
|
import java.util.Vector; |
|
|
|
|
|
public class SCDynamicStoreConfig { |
|
private static native void installNotificationCallback(); |
|
private static native Hashtable<String, Object> getKerberosConfig(); |
|
private static boolean DEBUG = sun.security.krb5.internal.Krb5.DEBUG; |
|
|
|
static { |
|
boolean isMac = java.security.AccessController.doPrivileged( |
|
new java.security.PrivilegedAction<Boolean>() { |
|
public Boolean run() { |
|
String osname = System.getProperty("os.name"); |
|
if (osname.contains("OS X")) { |
|
System.loadLibrary("osx"); |
|
return true; |
|
} |
|
return false; |
|
} |
|
}); |
|
if (isMac) installNotificationCallback(); |
|
} |
|
|
|
private static Vector<String> unwrapHost( |
|
Collection<Hashtable<String, String>> c) { |
|
Vector<String> vector = new Vector<String>(); |
|
for (Hashtable<String, String> m : c) { |
|
vector.add(m.get("host")); |
|
} |
|
return vector; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@SuppressWarnings("unchecked") |
|
private static Hashtable<String, Object> |
|
convertRealmConfigs(Hashtable<String, ?> configs) { |
|
Hashtable<String, Object> realmsTable = new Hashtable<String, Object>(); |
|
|
|
for (String realm : configs.keySet()) { |
|
|
|
Hashtable<String, Collection<?>> map = |
|
(Hashtable<String, Collection<?>>) configs.get(realm); |
|
Hashtable<String, Vector<String>> realmMap = |
|
new Hashtable<String, Vector<String>>(); |
|
|
|
|
|
Collection<Hashtable<String, String>> kdc = |
|
(Collection<Hashtable<String, String>>) map.get("kdc"); |
|
if (kdc != null) realmMap.put("kdc", unwrapHost(kdc)); |
|
|
|
|
|
Collection<Hashtable<String, String>> kadmin = |
|
(Collection<Hashtable<String, String>>) map.get("kadmin"); |
|
if (kadmin != null) realmMap.put("admin_server", unwrapHost(kadmin)); |
|
|
|
|
|
realmsTable.put(realm, realmMap); |
|
} |
|
|
|
return realmsTable; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static Hashtable<String, Object> getConfig() throws IOException { |
|
Hashtable<String, Object> stanzaTable = getKerberosConfig(); |
|
if (stanzaTable == null) { |
|
throw new IOException( |
|
"Could not load configuration from SCDynamicStore"); |
|
} |
|
if (DEBUG) System.out.println("Raw map from JNI: " + stanzaTable); |
|
return convertNativeConfig(stanzaTable); |
|
} |
|
|
|
@SuppressWarnings("unchecked") |
|
private static Hashtable<String, Object> convertNativeConfig( |
|
Hashtable<String, Object> stanzaTable) { |
|
|
|
Hashtable<String, ?> realms = |
|
(Hashtable<String, ?>) stanzaTable.get("realms"); |
|
if (realms != null) { |
|
stanzaTable.remove("realms"); |
|
Hashtable<String, Object> realmsTable = convertRealmConfigs(realms); |
|
stanzaTable.put("realms", realmsTable); |
|
} |
|
WrapAllStringInVector(stanzaTable); |
|
if (DEBUG) System.out.println("stanzaTable : " + stanzaTable); |
|
return stanzaTable; |
|
} |
|
|
|
@SuppressWarnings("unchecked") |
|
private static void WrapAllStringInVector( |
|
Hashtable<String, Object> stanzaTable) { |
|
for (String s: stanzaTable.keySet()) { |
|
Object v = stanzaTable.get(s); |
|
if (v instanceof Hashtable) { |
|
WrapAllStringInVector((Hashtable<String,Object>)v); |
|
} else if (v instanceof String) { |
|
Vector<String> vec = new Vector<>(); |
|
vec.add((String)v); |
|
stanzaTable.put(s, vec); |
|
} |
|
} |
|
} |
|
} |