43 import java.net.InetAddress; |
43 import java.net.InetAddress; |
44 import java.net.UnknownHostException; |
44 import java.net.UnknownHostException; |
45 import java.util.List; |
45 import java.util.List; |
46 import sun.net.dns.ResolverConfiguration; |
46 import sun.net.dns.ResolverConfiguration; |
47 import sun.security.krb5.internal.crypto.EType; |
47 import sun.security.krb5.internal.crypto.EType; |
48 import sun.security.krb5.internal.ktab.*; |
|
49 import sun.security.krb5.internal.Krb5; |
48 import sun.security.krb5.internal.Krb5; |
50 |
49 |
51 /** |
50 /** |
52 * This class maintains key-value pairs of Kerberos configurable constants |
51 * This class maintains key-value pairs of Kerberos configurable constants |
53 * from configuration file or from user specified system properties. |
52 * from configuration file or from user specified system properties. |
231 * @param k the key string. |
230 * @param k the key string. |
232 * @param t stanzaTable or sub hashtable within it. |
231 * @param t stanzaTable or sub hashtable within it. |
233 * @return the value found in config file, returns null if no value |
232 * @return the value found in config file, returns null if no value |
234 * matched with the key is found. |
233 * matched with the key is found. |
235 */ |
234 */ |
236 private String getDefault(String k, Hashtable t) { |
235 private String getDefault(String k, Hashtable<String, Object> t) { |
237 String result = null; |
236 String result = null; |
238 String key; |
237 String key; |
239 if (stanzaTable != null) { |
238 if (stanzaTable != null) { |
240 for (Enumeration e = t.keys(); e.hasMoreElements(); ) { |
239 for (Enumeration<String> e = t.keys(); e.hasMoreElements(); ) { |
241 key = (String)e.nextElement(); |
240 key = e.nextElement(); |
242 Object ob = t.get(key); |
241 Object ob = t.get(key); |
243 if (ob instanceof Hashtable) { |
242 if (ob instanceof Hashtable) { |
244 result = getDefault(k, (Hashtable)ob); |
243 @SuppressWarnings("unchecked") // Checked with an instanceof check |
|
244 Hashtable<String, Object> table = |
|
245 (Hashtable<String, Object>)ob; |
|
246 result = getDefault(k, table); |
245 if (result != null) { |
247 if (result != null) { |
246 return result; |
248 return result; |
247 } |
249 } |
248 } else if (key.equalsIgnoreCase(k)) { |
250 } else if (key.equalsIgnoreCase(k)) { |
249 if (ob instanceof String) { |
251 if (ob instanceof String) { |
274 * <br>This method is quicker by using the section name as the search key. |
276 * <br>This method is quicker by using the section name as the search key. |
275 * @param name the name. |
277 * @param name the name. |
276 * @param section the name of the section. |
278 * @param section the name of the section. |
277 * @return the default value, null is returned if it cannot be found. |
279 * @return the default value, null is returned if it cannot be found. |
278 */ |
280 */ |
|
281 // stanzaTable leads to a lot of unchecked casts since its value type is |
|
282 // STANZATABLE = String | Hashtable<String, STANZATABLE> |
|
283 @SuppressWarnings("unchecked") |
279 public String getDefault(String name, String section) { |
284 public String getDefault(String name, String section) { |
280 String stanzaName; |
285 String stanzaName; |
281 String result = null; |
286 String result = null; |
282 Hashtable subTable; |
287 Hashtable<String, Object> subTable; |
283 |
288 |
284 if (stanzaTable != null) { |
289 if (stanzaTable != null) { |
285 for (Enumeration e = stanzaTable.keys(); e.hasMoreElements(); ) { |
290 for (Enumeration<String> e = stanzaTable.keys(); |
286 stanzaName = (String)e.nextElement(); |
291 e.hasMoreElements(); ) { |
287 subTable = (Hashtable)stanzaTable.get(stanzaName); |
292 stanzaName = e.nextElement(); |
|
293 subTable = (Hashtable<String, Object>) |
|
294 stanzaTable.get(stanzaName); |
288 if (stanzaName.equalsIgnoreCase(section)) { |
295 if (stanzaName.equalsIgnoreCase(section)) { |
289 if (subTable.containsKey(name)) { |
296 if (subTable.containsKey(name)) { |
290 return (String)(subTable.get(name)); |
297 return (String)(subTable.get(name)); |
291 } |
298 } |
292 } else if (subTable.containsKey(section)) { |
299 } else if (subTable.containsKey(section)) { |
293 Object ob = subTable.get(section); |
300 Object ob = subTable.get(section); |
294 if (ob instanceof Hashtable) { |
301 if (ob instanceof Hashtable) { |
295 Hashtable temp = (Hashtable)ob; |
302 Hashtable<String, Object> temp = |
|
303 (Hashtable<String, Object>)ob; |
296 if (temp.containsKey(name)) { |
304 if (temp.containsKey(name)) { |
297 Object object = temp.get(name); |
305 Object object = temp.get(name); |
298 if (object instanceof Vector) { |
306 if (object instanceof Vector) { |
299 result = ""; |
307 result = ""; |
300 int length = ((Vector)object).size(); |
308 int length = ((Vector)object).size(); |
835 */ |
843 */ |
836 public void listTable() { |
844 public void listTable() { |
837 listTable(stanzaTable); |
845 listTable(stanzaTable); |
838 } |
846 } |
839 |
847 |
840 private void listTable(Hashtable table) { |
848 // stanzaTable leads to a lot of unchecked casts since its value type is |
841 Vector v = new Vector(); |
849 // STANZATABLE = String | Hashtable<String, STANZATABLE> |
|
850 @SuppressWarnings("unchecked") |
|
851 private void listTable(Hashtable<String, Object> table) { |
|
852 Vector<String> v = new Vector<String>(); |
842 String key; |
853 String key; |
843 if (stanzaTable != null) { |
854 if (stanzaTable != null) { |
844 for (Enumeration e = table.keys(); e.hasMoreElements(); ) { |
855 for (Enumeration<String> e = table.keys(); e.hasMoreElements(); ) { |
845 key = (String)e.nextElement(); |
856 key = e.nextElement(); |
846 Object object = table.get(key); |
857 Object object = table.get(key); |
847 if (table == stanzaTable) { |
858 if (table == stanzaTable) { |
848 System.out.println("[" + key + "]"); |
859 System.out.println("[" + key + "]"); |
849 } |
860 } |
850 if (object instanceof Hashtable) { |
861 if (object instanceof Hashtable) { |
851 if (table != stanzaTable) |
862 if (table != stanzaTable) |
852 System.out.println("\t" + key + " = {"); |
863 System.out.println("\t" + key + " = {"); |
853 listTable((Hashtable)object); |
864 listTable((Hashtable<String, Object>)object); |
854 if (table != stanzaTable) |
865 if (table != stanzaTable) |
855 System.out.println("\t}"); |
866 System.out.println("\t}"); |
856 |
867 |
857 } else if (object instanceof String) { |
868 } else if (object instanceof String) { |
858 System.out.println("\t" + key + " = " + |
869 System.out.println("\t" + key + " = " + |
859 (String)table.get(key)); |
870 (String)table.get(key)); |
860 } else if (object instanceof Vector) { |
871 } else if (object instanceof Vector) { |
861 v = (Vector)object; |
872 v = (Vector<String>)object; |
862 for (int i = 0; i < v.size(); i++) { |
873 for (int i = 0; i < v.size(); i++) { |
863 System.out.println("\t" + key + " = " + |
874 System.out.println("\t" + key + " = " + v.elementAt(i)); |
864 (String)v.elementAt(i)); |
|
865 } |
875 } |
866 } |
876 } |
867 } |
877 } |
868 } else { |
878 } else { |
869 System.out.println("Configuration file not found."); |
879 System.out.println("Configuration file not found."); |
1294 if (obj instanceof String) { |
1304 if (obj instanceof String) { |
1295 sb.append(prefix); |
1305 sb.append(prefix); |
1296 sb.append(obj); |
1306 sb.append(obj); |
1297 sb.append('\n'); |
1307 sb.append('\n'); |
1298 } else if (obj instanceof Hashtable) { |
1308 } else if (obj instanceof Hashtable) { |
1299 Hashtable tab = (Hashtable)obj; |
1309 Hashtable<?, ?> tab = (Hashtable<?, ?>)obj; |
1300 for (Object o: tab.keySet()) { |
1310 for (Object o: tab.keySet()) { |
1301 sb.append(prefix); |
1311 sb.append(prefix); |
1302 sb.append(o); |
1312 sb.append(o); |
1303 sb.append(" = {\n"); |
1313 sb.append(" = {\n"); |
1304 toStringIndented(prefix + " ", tab.get(o), sb); |
1314 toStringIndented(prefix + " ", tab.get(o), sb); |
1305 sb.append(prefix + "}\n"); |
1315 sb.append(prefix + "}\n"); |
1306 } |
1316 } |
1307 } else if (obj instanceof Vector) { |
1317 } else if (obj instanceof Vector) { |
1308 Vector v = (Vector)obj; |
1318 Vector<?> v = (Vector<?>)obj; |
1309 for (Object o: v.toArray()) { |
1319 for (Object o: v.toArray()) { |
1310 toStringIndented(prefix + " ", o, sb); |
1320 toStringIndented(prefix + " ", o, sb); |
1311 } |
1321 } |
1312 } |
1322 } |
1313 } |
1323 } |