public static void go0(String... expected) throws Exception { System.setProperty("sun.security.krb5.debug", "true"); // Make sure KDCs' ports starts with 1 and 2 and 3, // useful for checking debug output. int p1 = 10000 + new java.util.Random().nextInt(10000); int p2 = 20000 + new java.util.Random().nextInt(10000); int p3 = 30000 + new java.util.Random().nextInt(10000); FileWriter fw = new FileWriter("alternative-krb5.conf"); fw.write( "[libdefaults]\n" + "default_realm = " + OneKDC.REALM + "\n" + "kdc_timeout = " + toReal(2000) + "\n"); fw.write( "[realms]\n" + OneKDC.REALM + " = {\n" + "kdc = " + OneKDC.KDCHOST + ":" + p1 + "\n" + "kdc = " + OneKDC.KDCHOST + ":" + p2 + "\n" + "kdc = " + OneKDC.KDCHOST + ":" + p3 + "\n" + "}\n"); fw.close(); System.setProperty("java.security.krb5.conf", "alternative-krb5.conf"); Config.refresh(); // Turn on k3 only KDC k3 = on(p3); test(expected[0]); test(expected[1]); Config.refresh(); test(expected[2]); k3.terminate(); // shutdown k3 on(p2); // k2 is on test(expected[3]); on(p1); // k1 and k2 is on test(expected[4]); }
public static void main(String[] args) throws Exception { File f = new File(System.getProperty("test.src", "."), "unreachable.krb5.conf"); System.setProperty("java.security.krb5.conf", f.getPath()); Config.refresh(); // If PortUnreachableException is not received, the login will consume // about 3*3*30 seconds and the test will timeout. try { Context.fromUserPass("name", "pass".toCharArray(), true); } catch (LoginException le) { // This is OK } }
/** * Creates the KDC and starts it. * * @param etype Encryption type, null if not specified * @throws java.lang.Exception if there's anything wrong */ public OneKDC(String etype) throws Exception { super(REALM, KDCHOST, 0, true); addPrincipal(USER, PASS); addPrincipalRandKey("krbtgt/" + REALM); addPrincipalRandKey(SERVER); addPrincipalRandKey(BACKEND); KDC.saveConfig( KRB5_CONF, this, "forwardable = true", "default_keytab_name = " + KTAB, etype == null ? "" : "default_tkt_enctypes=" + etype + "\ndefault_tgs_enctypes=" + etype); System.setProperty("java.security.krb5.conf", KRB5_CONF); // Whatever krb5.conf had been loaded before, we reload ours now. Config.refresh(); writeKtab(KTAB); new File(KRB5_CONF).deleteOnExit(); new File(KTAB).deleteOnExit(); }