Search in sources :

Example 1 with OwnerStore

use of io.cdap.cdap.security.impersonation.OwnerStore in project cdap by caskdata.

the class OwnerStoreTest method testGetOwners.

@Test
public void testGetOwners() throws IOException, AlreadyExistsException {
    OwnerStore ownerStore = getOwnerStore();
    ownerStore.add(NamespaceId.DEFAULT.dataset("dataset"), new KerberosPrincipalId("ds"));
    ownerStore.add(NamespaceId.DEFAULT.app("app"), new KerberosPrincipalId("app"));
    ownerStore.add(NamespaceId.DEFAULT.artifact("artifact", "1.2.3"), new KerberosPrincipalId("artifact"));
    Set<NamespacedEntityId> ids = ImmutableSet.of(NamespaceId.DEFAULT.dataset("dataset"), NamespaceId.DEFAULT.app("app"), NamespaceId.DEFAULT.artifact("artifact", "1.2.3"), NamespaceId.DEFAULT.app("noowner"));
    Map<NamespacedEntityId, KerberosPrincipalId> owners = ownerStore.getOwners(ids);
    Assert.assertEquals(3, owners.size());
    Assert.assertEquals(new KerberosPrincipalId("ds"), owners.get(NamespaceId.DEFAULT.dataset("dataset")));
    Assert.assertEquals(new KerberosPrincipalId("app"), owners.get(NamespaceId.DEFAULT.app("app")));
    Assert.assertEquals(new KerberosPrincipalId("artifact"), owners.get(NamespaceId.DEFAULT.artifact("artifact", "1.2.3")));
    Assert.assertNull(owners.get(NamespaceId.DEFAULT.app("noowner")));
}
Also used : NamespacedEntityId(io.cdap.cdap.proto.id.NamespacedEntityId) KerberosPrincipalId(io.cdap.cdap.proto.id.KerberosPrincipalId) OwnerStore(io.cdap.cdap.security.impersonation.OwnerStore) Test(org.junit.Test)

Example 2 with OwnerStore

use of io.cdap.cdap.security.impersonation.OwnerStore in project cdap by caskdata.

the class OwnerStoreTest method test.

@Test
public void test() throws Exception {
    OwnerStore ownerStore = getOwnerStore();
    DatasetId datasetId = NamespaceId.DEFAULT.dataset("fooData");
    // No owner info should exist for above stream
    Assert.assertNull(ownerStore.getOwner(datasetId));
    // delete behavior is idempotent, so won't throw NotFoundException
    ownerStore.delete(datasetId);
    // Storing an owner for the first time should work
    KerberosPrincipalId kerberosPrincipalId = new KerberosPrincipalId("alice/somehost@SOMEKDC.NET");
    ownerStore.add(datasetId, kerberosPrincipalId);
    // owner principal should exists
    Assert.assertTrue(ownerStore.exists(datasetId));
    // Should be able to get the principal back
    Assert.assertEquals(kerberosPrincipalId, ownerStore.getOwner(datasetId));
    // Should not be able to update the owner principal
    try {
        ownerStore.add(datasetId, new KerberosPrincipalId("bob@SOMEKDC.NET"));
        Assert.fail();
    } catch (AlreadyExistsException e) {
    // expected
    }
    // Should not be able to update the owner principal
    try {
        ownerStore.add(datasetId, new KerberosPrincipalId("somePrincipal"));
        Assert.fail();
    } catch (AlreadyExistsException e) {
    // expected
    }
    // trying to update with invalid principal should fail early on with IllegalArgumentException
    try {
        ownerStore.add(datasetId, new KerberosPrincipalId("b@ob@SOMEKDC.NET"));
        Assert.fail();
    } catch (IllegalArgumentException e) {
    // expected
    }
    // Trying to store owner information for unsupported type should fail
    try {
        ownerStore.add(NamespaceId.DEFAULT.topic("anotherStream"), new KerberosPrincipalId("somePrincipal"));
        Assert.fail();
    } catch (IllegalArgumentException e) {
    // expected
    }
    // delete the owner information
    ownerStore.delete(datasetId);
    Assert.assertFalse(ownerStore.exists(datasetId));
    Assert.assertNull(ownerStore.getOwner(datasetId));
}
Also used : AlreadyExistsException(io.cdap.cdap.common.AlreadyExistsException) KerberosPrincipalId(io.cdap.cdap.proto.id.KerberosPrincipalId) OwnerStore(io.cdap.cdap.security.impersonation.OwnerStore) DatasetId(io.cdap.cdap.proto.id.DatasetId) Test(org.junit.Test)

Aggregations

KerberosPrincipalId (io.cdap.cdap.proto.id.KerberosPrincipalId)2 OwnerStore (io.cdap.cdap.security.impersonation.OwnerStore)2 Test (org.junit.Test)2 AlreadyExistsException (io.cdap.cdap.common.AlreadyExistsException)1 DatasetId (io.cdap.cdap.proto.id.DatasetId)1 NamespacedEntityId (io.cdap.cdap.proto.id.NamespacedEntityId)1