@Test public void testNoKeytabPath() throws IOException { String user = "alice"; CConfiguration cConf = CConfiguration.create(); // this should throw a null pointer exception with proper message as what to set try { SecurityUtil.getKeytabURIforPrincipal(user, cConf); Assert.fail(); } catch (NullPointerException e) { // expected Assert.assertTrue(e.getMessage().contains(Constants.Security.KEYTAB_PATH)); } } }
@Nullable @Override public ImpersonationInfo getImpersonationInfo(NamespacedEntityId entityId) throws IOException { entityId = getEffectiveEntity(entityId); if (!entityId.getEntityType().equals(EntityType.NAMESPACE)) { KerberosPrincipalId effectiveOwner = ownerStore.getOwner(entityId); if (effectiveOwner != null) { return new ImpersonationInfo(effectiveOwner.getPrincipal(), SecurityUtil.getKeytabURIforPrincipal(effectiveOwner.getPrincipal(), cConf)); } } // (CDAP-8176) Since no owner was found for the entity return namespace principal if present. NamespaceConfig nsConfig = getNamespaceConfig(entityId.getNamespaceId()); return nsConfig.getPrincipal() == null ? null : new ImpersonationInfo(nsConfig.getPrincipal(), nsConfig.getKeytabURI()); }
@Test public void testGetKeytabURIforUser() throws IOException { String user = "alice"; String confPath = "/dir1/dir2/${name}/${name}.keytab"; String expectedPath = "/dir1/dir2/alice/alice.keytab"; CConfiguration cConf = CConfiguration.create(); cConf.set(Constants.Security.KEYTAB_PATH, confPath); cConf.set("user", "blah blah"); String path = SecurityUtil.getKeytabURIforPrincipal(user, cConf); Assert.assertEquals(expectedPath, path); }