/** * Create Kerberos principal for a given service and hostname. It converts * hostname to lower case. If hostname is null or "0.0.0.0", it uses * dynamically looked-up fqdn of the current host instead. * * @param service * Service for which you want to generate the principal. * @param hostname * Fully-qualified domain name. * @return Converted Kerberos principal name. * @throws UnknownHostException * If no IP address for the local host could be found. */ public static final String getServicePrincipal(String service, String hostname) throws UnknownHostException { String fqdn = hostname; if (null == fqdn || fqdn.equals("") || fqdn.equals("0.0.0.0")) { fqdn = getLocalHostName(); } // convert hostname to lowercase as kerberos does not work with hostnames // with uppercase characters. return service + "/" + fqdn.toLowerCase(Locale.ENGLISH); }
/** * Create Kerberos principal for a given service and hostname. It converts * hostname to lower case. If hostname is null or "0.0.0.0", it uses * dynamically looked-up fqdn of the current host instead. * * @param service * Service for which you want to generate the principal. * @param hostname * Fully-qualified domain name. * @return Converted Kerberos principal name. * @throws UnknownHostException * If no IP address for the local host could be found. */ public static final String getServicePrincipal(String service, String hostname) throws UnknownHostException { String fqdn = hostname; if (null == fqdn || fqdn.equals("") || fqdn.equals("0.0.0.0")) { fqdn = getLocalHostName(); } // convert hostname to lowercase as kerberos does not work with hostnames // with uppercase characters. return service + "/" + fqdn.toLowerCase(Locale.ENGLISH); }
/** * Create Kerberos principal for a given service and hostname. It converts * hostname to lower case. If hostname is null or "0.0.0.0", it uses * dynamically looked-up fqdn of the current host instead. * * @param service * Service for which you want to generate the principal. * @param hostname * Fully-qualified domain name. * @return Converted Kerberos principal name. * @throws UnknownHostException * If no IP address for the local host could be found. */ public static final String getServicePrincipal(String service, String hostname) throws UnknownHostException { String fqdn = hostname; if (null == fqdn || fqdn.equals("") || fqdn.equals("0.0.0.0")) { fqdn = getLocalHostName(); } // convert hostname to lowercase as kerberos does not work with hostnames // with uppercase characters. return service + "/" + fqdn.toLowerCase(Locale.US); }
String realmString = null; if (null == fqdn || fqdn.equals("") || fqdn.equals("0.0.0.0")) { fqdn = getLocalHostName();
String realmString = null; if (null == fqdn || fqdn.equals("") || fqdn.equals("0.0.0.0")) { fqdn = getLocalHostName();
String realmString = null; if (null == fqdn || fqdn.equals("") || fqdn.equals("0.0.0.0")) { fqdn = getLocalHostName();
@Test public void testGetServerPrincipal() throws IOException { String service = "TestKerberosUtil"; String localHostname = KerberosUtil.getLocalHostName(); String testHost = "FooBar"; // send null hostname Assert.assertEquals("When no hostname is sent", service + "/" + localHostname.toLowerCase(), KerberosUtil.getServicePrincipal(service, null)); // send empty hostname Assert.assertEquals("When empty hostname is sent", service + "/" + localHostname.toLowerCase(), KerberosUtil.getServicePrincipal(service, "")); // send 0.0.0.0 hostname Assert.assertEquals("When 0.0.0.0 hostname is sent", service + "/" + localHostname.toLowerCase(), KerberosUtil.getServicePrincipal(service, "0.0.0.0")); // send uppercase hostname Assert.assertEquals("When uppercase hostname is sent", service + "/" + testHost.toLowerCase(), KerberosUtil.getServicePrincipal(service, testHost)); // send lowercase hostname Assert.assertEquals("When lowercase hostname is sent", service + "/" + testHost.toLowerCase(), KerberosUtil.getServicePrincipal(service, testHost.toLowerCase())); }
throws IOException, UnknownHostException { String service = "TestKerberosUtil"; String localHostname = KerberosUtil.getLocalHostName(); String testHost = "FooBar"; String defaultRealm = KerberosUtil.getDefaultRealmProtected();
throws IOException, UnknownHostException { String service = "TestKerberosUtil"; String localHostname = KerberosUtil.getLocalHostName(); String testHost = "FooBar"; String defaultRealm = KerberosUtil.getDefaultRealmProtected();