// Check default timeout is 30s. Use real KDC only, otherwise too // slow to wait for timeout. Each request (without preauth and with // preauth) might be retried 3 times, and could fail if one fails for // all 3 times.
writeConf(-1, -1, p3);
test("(c30000){2,6}|(c30000){3,6}-");
// 1. Default policy is tryLast //Security.setProperty("krb5.kdc.bad.policy", "tryLast");
// Need a real KDC, otherwise there is no last good. // This test waste 3 seconds waiting for d1 to timeout. // It is possible the real KDC cannot fulfil the request // in 3s, so it might fail (either 1st time or 2nd time).
writeConf(1, 3000, p1, p3);
test("a3000c3000c3000|a3000c3000-|a3000c3000c3000a3000-");
// If a test case won't use a real KDC, it can be sped up.
writeConf(3, 5, p1, p2);
test("a5a5a5b5b5b5-"); // default max_retries == 3
test("a5a5a5b5b5b5-"); // all bad means no bad
// 2. No policy.
Security.setProperty("krb5.kdc.bad.policy", "");
Config.refresh();
// This case needs a real KDC, otherwise, all bad means no // bad and we cannot tell the difference. This case waste 3 // seconds on d1 to timeout twice. It is possible the real KDC // cannot fulfil the request within 3s, so it might fail // (either 1st time or 2nd time).
writeConf(1, 3000, p1, p3);
test("a3000c3000a3000c3000|a3000c3000-|a3000c3000a3000c3000-");
// 3. tryLess with no argument means tryLess:1,5000
Security.setProperty("krb5.kdc.bad.policy", "tryLess");
// This case will waste 11s. We are checking that the default // value of 5000 in tryLess is only used if it's less than timeout // in krb5.conf
writeConf(1, 6000, p1);
test("a6000-"); // timeout in krb5.conf is 6s
test("a5000-"); // tryLess to 5s. This line can be made faster if // d1 is a read KDC, but we have no existing method // to start KDC on an existing ServerSocket (port).
writeConf(-1, 4, p1, p2);
test("a4a4a4b4b4b4-"); // default max_retries == 3
test("a4b4-"); // tryLess to 1. And since 4 < 5000, use 4.
Config.refresh();
test("a4a4a4b4b4b4-");
/** *Writesakrb5.conffile. *@parammaxmax_retries,-1ifnotset *@paramtokdc_timeout,-1ifnotset *@paramportswhereKDCslistenon
*/ staticvoid writeConf(int max, int to, int... ports) throws Exception {
// content of krb5.conf
String conf = "";
// Extra settings in [libdefaults]
String inDefaults = "";
// Extra settings in [realms]
String inRealm = "";
// We will randomly put extra settings only in [libdefaults], // or in [realms] but with different values in [libdefaults], // to prove that settings in [realms] override those in [libdefaults].
Random r = new Random();
String[] lines = new String(bo.toByteArray()).split("\n");
StringBuilder sb = new StringBuilder(); for (String line: lines) { if (cm.match(line)) { if (udp != cm.isUDP()) {
sb.append("x");
}
sb.append(cm.kdc()).append(cm.timeout());
}
} if (failed) sb.append('-');
String output = sb.toString();
boolean found = false; for (String ex : expected) { if (output.matches(ex)) {
System.out.println("Expected: " + ex + ", actual " + output);
found = true; break;
}
}
if (!found) {
System.out.println("--------------- ERROR START -------------");
System.out.println(new String(bo.toByteArray()));
System.out.println("--------------- ERROR END ---------------"); thrownew Exception("Does not match. Output is " + output);
}
}
/** *Ahelperclasstomatchthekrb5debugoutput: *>>>KDCCommunication:kdc=hostUDP:11555,timeout=200,Attempt=1,#bytes=138 * *Example: *DebugMatchercm=newDebugMatcher(); *cm.addPort(12345).addPort(11555); *for(Stringline:debugOutput){ *if(cm.match(line)){ *System.out.printf("%c%d\n",cm.kdc(),cm.timeout()); *// shows b200 for the example above *} *}
*/ staticclass DebugMatcher {
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.