KerberosName { public static void setRuleMechanism(String ruleMech) { if (ruleMech != null && (!ruleMech.equalsIgnoreCase(MECHANISM_HADOOP) && !ruleMech.equalsIgnoreCase(MECHANISM_MIT))) { throw new IllegalArgumentException("Invalid rule mechanism: " + ruleMech); } ruleMechanism = ruleMech; } KerberosName(String name); @VisibleForTesting static void resetDefaultRealm(); static synchronized String getDefaultRealm(); @Override String toString(); String getServiceName(); String getHostName(); String getRealm(); String getShortName(); static String getRules(); static boolean hasRulesBeenSet(); static boolean hasRuleMechanismBeenSet(); static void setRules(String ruleString); static void setRuleMechanism(String ruleMech); static String getRuleMechanism(); static final String MECHANISM_HADOOP; static final String MECHANISM_MIT; static final String DEFAULT_MECHANISM; }
@Test public void testAntiPatterns() throws Exception { KerberosName.setRuleMechanism(KerberosName.MECHANISM_HADOOP); checkBadName("owen/owen/owen@FOO.COM"); checkBadName("owen@foo/bar.com"); checkBadTranslation("foo@ACME.COM"); checkBadTranslation("root/joe@FOO.COM"); KerberosName.setRuleMechanism(KerberosName.MECHANISM_MIT); checkTranslation("foo@ACME.COM", "foo@ACME.COM"); checkTranslation("root/joe@FOO.COM", "root/joe@FOO.COM"); }
@Test(expected = IllegalArgumentException.class) public void testInvalidRuleMechanism() throws Exception { KerberosName.setRuleMechanism("INVALID_MECHANISM"); }