@Test public void testParse() throws IOException { List<String> rules = new ArrayList<>(Arrays.asList( "RULE:[1:$1](App\\..*)s/App\\.(.*)/$1/g", "RULE:[2:$1](App\\..*)s/App\\.(.*)/$1/g", "DEFAULT" )); KerberosShortNamer shortNamer = KerberosShortNamer.fromUnparsedRules("REALM.COM", rules); KerberosName name = KerberosName.parse("App.service-name/example.com@REALM.COM"); assertEquals("App.service-name", name.serviceName()); assertEquals("example.com", name.hostName()); assertEquals("REALM.COM", name.realm()); assertEquals("service-name", shortNamer.shortName(name)); name = KerberosName.parse("App.service-name@REALM.COM"); assertEquals("App.service-name", name.serviceName()); assertNull(name.hostName()); assertEquals("REALM.COM", name.realm()); assertEquals("service-name", shortNamer.shortName(name)); name = KerberosName.parse("user/host@REALM.COM"); assertEquals("user", name.serviceName()); assertEquals("host", name.hostName()); assertEquals("REALM.COM", name.realm()); assertEquals("user", shortNamer.shortName(name)); }
public static KerberosName parse(String principalName) { Matcher match = NAME_PARSER.matcher(principalName); if (!match.matches()) { if (principalName.contains("@")) { throw new IllegalArgumentException("Malformed Kerberos name: " + principalName); } else { return new KerberosName(principalName, null, null); } } else { return new KerberosName(match.group(1), match.group(3), match.group(4)); } }
KerberosName { public static KerberosName parse(String principalName) { Matcher match = NAME_PARSER.matcher(principalName); if (!match.matches()) { if (principalName.contains("@")) { throw new IllegalArgumentException("Malformed Kerberos name: " + principalName); } else { return new KerberosName(principalName, null, null); } } else { return new KerberosName(match.group(1), match.group(3), match.group(4)); } } }
KerberosName { public static KerberosName parse(String principalName) { Matcher match = NAME_PARSER.matcher(principalName); if (!match.matches()) { if (principalName.contains("@")) { throw new IllegalArgumentException("Malformed Kerberos name: " + principalName); } else { return new KerberosName(principalName, null, null); } } else { return new KerberosName(match.group(1), match.group(3), match.group(4)); } } KerberosName(String serviceName, String hostName, String realm); }
KerberosName { public static KerberosName parse(String principalName) { Matcher match = NAME_PARSER.matcher(principalName); if (!match.matches()) { if (principalName.contains("@")) { throw new IllegalArgumentException("Malformed Kerberos name: " + principalName); } else { return new KerberosName(principalName, null, null); } } else { return new KerberosName(match.group(1), match.group(3), match.group(4)); } } KerberosName(String serviceName, String hostName, String realm); static KerberosName parse(String principalName); @Override String toString(); String serviceName(); String hostName(); String realm(); }
KerberosName { public static KerberosName parse(String principalName) { Matcher match = NAME_PARSER.matcher(principalName); if (!match.matches()) { if (principalName.contains("@")) { throw new IllegalArgumentException("Malformed Kerberos name: " + principalName); } else { return new KerberosName(principalName, null, null); } } else { return new KerberosName(match.group(1), match.group(3), match.group(4)); } } KerberosName(String serviceName, String hostName, String realm); static KerberosName parse(String principalName); @Override String toString(); String serviceName(); String hostName(); String realm();  }