use of co.cask.cdap.security.impersonation.OwnerAdmin in project cdap by caskdata.
the class AuthorizationUtilTest method testGetAppAuthorizingUse.
@Test
public void testGetAppAuthorizingUse() throws Exception {
OwnerAdmin ownerAdmin = getOwnerAdmin();
// test with complete principal (alice/somehost.net@somerealm.net)
String principal = username + "/" + InetAddress.getLocalHost().getHostName() + "@REALM.net";
NamespaceMeta nsMeta = new NamespaceMeta.Builder().setName(namespaceId).setPrincipal(principal).setKeytabURI("doesnotmatter").build();
namespaceClient.create(nsMeta);
Assert.assertEquals(username, AuthorizationUtil.getAppAuthorizingUser(ownerAdmin, authenticationContext, applicationId, null));
// test with principal which is just username (alice)
namespaceClient.delete(namespaceId);
principal = username;
nsMeta = new NamespaceMeta.Builder().setName(namespaceId).setPrincipal(principal).setKeytabURI("doesnotmatter").build();
namespaceClient.create(nsMeta);
Assert.assertEquals(username, AuthorizationUtil.getAppAuthorizingUser(ownerAdmin, authenticationContext, applicationId, null));
// test with principal and realm (alice@somerealm.net)
namespaceClient.delete(namespaceId);
principal = username + "@REALM.net";
nsMeta = new NamespaceMeta.Builder().setName(namespaceId).setPrincipal(principal).setKeytabURI("doesnotmatter").build();
namespaceClient.create(nsMeta);
Assert.assertEquals(username, AuthorizationUtil.getAppAuthorizingUser(ownerAdmin, authenticationContext, applicationId, null));
// clean up
namespaceClient.delete(namespaceId);
}
Aggregations