Search in sources :

Example 1 with CustomDatasetApp

use of co.cask.cdap.data2.dataset2.customds.CustomDatasetApp in project cdap by caskdata.

the class DatasetClassRewriterTest method testDatasetAccessRecorder.

@Test
public void testDatasetAccessRecorder() throws Exception {
    ByteCodeClassLoader classLoader = new ByteCodeClassLoader(getClass().getClassLoader());
    classLoader.addClass(rewrite(TopLevelExtendsDataset.class));
    classLoader.addClass(rewrite(TopLevelDirectDataset.class));
    classLoader.addClass(rewrite(TopLevelDataset.class));
    classLoader.addClass(rewrite(DefaultTopLevelExtendsDataset.class));
    classLoader.addClass(rewrite(CustomDatasetApp.InnerStaticInheritDataset.class));
    classLoader.addClass(rewrite(CustomDatasetApp.InnerDataset.class));
    InMemoryAccessRecorder accessRecorder = new InMemoryAccessRecorder();
    TestAuthorizationEnforcer authEnforcer = new TestAuthorizationEnforcer(EnumSet.allOf(Action.class));
    testDatasetAccessRecord(accessRecorder, createDataset(accessRecorder, authEnforcer, TopLevelDataset.class.getName(), classLoader));
    accessRecorder.clear();
    testDatasetAccessRecord(accessRecorder, createDataset(accessRecorder, authEnforcer, DefaultTopLevelExtendsDataset.class.getName(), classLoader));
    accessRecorder.clear();
    Dataset delegate = createDataset(accessRecorder, authEnforcer, TopLevelDataset.class.getName(), classLoader);
    testDatasetAccessRecord(accessRecorder, createDataset(accessRecorder, authEnforcer, DelegatingDataset.class.getName(), classLoader, new Class<?>[] { CustomOperations.class }, new Object[] { delegate }));
    accessRecorder.clear();
    testDatasetAccessRecord(accessRecorder, createDataset(accessRecorder, authEnforcer, CustomDatasetApp.InnerStaticInheritDataset.class.getName(), classLoader));
    accessRecorder.clear();
    testDatasetAccessRecord(accessRecorder, createDataset(accessRecorder, authEnforcer, CustomDatasetApp.InnerDataset.class.getName(), classLoader, new Class<?>[] { CustomDatasetApp.class }, new Object[] { new CustomDatasetApp() }));
}
Also used : ByteCodeClassLoader(co.cask.cdap.internal.asm.ByteCodeClassLoader) Action(co.cask.cdap.proto.security.Action) TopLevelDataset(co.cask.cdap.data2.dataset2.customds.TopLevelDataset) TopLevelDataset(co.cask.cdap.data2.dataset2.customds.TopLevelDataset) DelegatingDataset(co.cask.cdap.data2.dataset2.customds.DelegatingDataset) TopLevelDirectDataset(co.cask.cdap.data2.dataset2.customds.TopLevelDirectDataset) Dataset(co.cask.cdap.api.dataset.Dataset) DefaultTopLevelExtendsDataset(co.cask.cdap.data2.dataset2.customds.DefaultTopLevelExtendsDataset) TopLevelExtendsDataset(co.cask.cdap.data2.dataset2.customds.TopLevelExtendsDataset) DefaultTopLevelExtendsDataset(co.cask.cdap.data2.dataset2.customds.DefaultTopLevelExtendsDataset) TopLevelExtendsDataset(co.cask.cdap.data2.dataset2.customds.TopLevelExtendsDataset) CustomDatasetApp(co.cask.cdap.data2.dataset2.customds.CustomDatasetApp) CustomOperations(co.cask.cdap.data2.dataset2.customds.CustomOperations) TopLevelDirectDataset(co.cask.cdap.data2.dataset2.customds.TopLevelDirectDataset) DefaultTopLevelExtendsDataset(co.cask.cdap.data2.dataset2.customds.DefaultTopLevelExtendsDataset) Test(org.junit.Test)

Example 2 with CustomDatasetApp

use of co.cask.cdap.data2.dataset2.customds.CustomDatasetApp in project cdap by caskdata.

the class DatasetClassRewriterTest method testDatasetAuthorization.

@Test
public void testDatasetAuthorization() throws Exception {
    ByteCodeClassLoader classLoader = new ByteCodeClassLoader(getClass().getClassLoader());
    classLoader.addClass(rewrite(TopLevelExtendsDataset.class));
    classLoader.addClass(rewrite(TopLevelDirectDataset.class));
    classLoader.addClass(rewrite(TopLevelDataset.class));
    classLoader.addClass(rewrite(DefaultTopLevelExtendsDataset.class));
    classLoader.addClass(rewrite(CustomDatasetApp.InnerStaticInheritDataset.class));
    classLoader.addClass(rewrite(CustomDatasetApp.InnerDataset.class));
    InMemoryAccessRecorder accessRecorder = new InMemoryAccessRecorder();
    // Test no access
    TestAuthorizationEnforcer authEnforcer = new TestAuthorizationEnforcer(EnumSet.noneOf(Action.class));
    testNoAccess(createDataset(accessRecorder, authEnforcer, TopLevelDataset.class.getName(), classLoader));
    testNoAccess(createDataset(accessRecorder, authEnforcer, DefaultTopLevelExtendsDataset.class.getName(), classLoader));
    Dataset delegate = createDataset(accessRecorder, authEnforcer, TopLevelDataset.class.getName(), classLoader);
    testNoAccess(createDataset(accessRecorder, authEnforcer, DelegatingDataset.class.getName(), classLoader, new Class<?>[] { CustomOperations.class }, new Object[] { delegate }));
    testNoAccess(createDataset(accessRecorder, authEnforcer, CustomDatasetApp.InnerStaticInheritDataset.class.getName(), classLoader));
    testNoAccess(createDataset(accessRecorder, authEnforcer, CustomDatasetApp.InnerDataset.class.getName(), classLoader, new Class<?>[] { CustomDatasetApp.class }, new Object[] { new CustomDatasetApp() }));
    // Test read only access
    authEnforcer = new TestAuthorizationEnforcer(EnumSet.of(Action.READ));
    testReadOnlyAccess(createDataset(accessRecorder, authEnforcer, TopLevelDataset.class.getName(), classLoader));
    testReadOnlyAccess(createDataset(accessRecorder, authEnforcer, DefaultTopLevelExtendsDataset.class.getName(), classLoader));
    delegate = createDataset(accessRecorder, authEnforcer, TopLevelDataset.class.getName(), classLoader);
    testReadOnlyAccess(createDataset(accessRecorder, authEnforcer, DelegatingDataset.class.getName(), classLoader, new Class<?>[] { CustomOperations.class }, new Object[] { delegate }));
    testReadOnlyAccess(createDataset(accessRecorder, authEnforcer, CustomDatasetApp.InnerStaticInheritDataset.class.getName(), classLoader));
    testReadOnlyAccess(createDataset(accessRecorder, authEnforcer, CustomDatasetApp.InnerDataset.class.getName(), classLoader, new Class<?>[] { CustomDatasetApp.class }, new Object[] { new CustomDatasetApp() }));
    // Test write only access
    authEnforcer = new TestAuthorizationEnforcer(EnumSet.of(Action.WRITE));
    testWriteOnlyAccess(createDataset(accessRecorder, authEnforcer, TopLevelDataset.class.getName(), classLoader));
    testWriteOnlyAccess(createDataset(accessRecorder, authEnforcer, DefaultTopLevelExtendsDataset.class.getName(), classLoader));
    delegate = createDataset(accessRecorder, authEnforcer, TopLevelDataset.class.getName(), classLoader);
    testWriteOnlyAccess(createDataset(accessRecorder, authEnforcer, DelegatingDataset.class.getName(), classLoader, new Class<?>[] { CustomOperations.class }, new Object[] { delegate }));
    testWriteOnlyAccess(createDataset(accessRecorder, authEnforcer, CustomDatasetApp.InnerStaticInheritDataset.class.getName(), classLoader));
    testWriteOnlyAccess(createDataset(accessRecorder, authEnforcer, CustomDatasetApp.InnerDataset.class.getName(), classLoader, new Class<?>[] { CustomDatasetApp.class }, new Object[] { new CustomDatasetApp() }));
}
Also used : ByteCodeClassLoader(co.cask.cdap.internal.asm.ByteCodeClassLoader) Action(co.cask.cdap.proto.security.Action) TopLevelDataset(co.cask.cdap.data2.dataset2.customds.TopLevelDataset) TopLevelDataset(co.cask.cdap.data2.dataset2.customds.TopLevelDataset) DelegatingDataset(co.cask.cdap.data2.dataset2.customds.DelegatingDataset) TopLevelDirectDataset(co.cask.cdap.data2.dataset2.customds.TopLevelDirectDataset) Dataset(co.cask.cdap.api.dataset.Dataset) DefaultTopLevelExtendsDataset(co.cask.cdap.data2.dataset2.customds.DefaultTopLevelExtendsDataset) TopLevelExtendsDataset(co.cask.cdap.data2.dataset2.customds.TopLevelExtendsDataset) DefaultTopLevelExtendsDataset(co.cask.cdap.data2.dataset2.customds.DefaultTopLevelExtendsDataset) TopLevelExtendsDataset(co.cask.cdap.data2.dataset2.customds.TopLevelExtendsDataset) CustomDatasetApp(co.cask.cdap.data2.dataset2.customds.CustomDatasetApp) CustomOperations(co.cask.cdap.data2.dataset2.customds.CustomOperations) TopLevelDirectDataset(co.cask.cdap.data2.dataset2.customds.TopLevelDirectDataset) DefaultTopLevelExtendsDataset(co.cask.cdap.data2.dataset2.customds.DefaultTopLevelExtendsDataset) Test(org.junit.Test)

Aggregations

Dataset (co.cask.cdap.api.dataset.Dataset)2 CustomDatasetApp (co.cask.cdap.data2.dataset2.customds.CustomDatasetApp)2 CustomOperations (co.cask.cdap.data2.dataset2.customds.CustomOperations)2 DefaultTopLevelExtendsDataset (co.cask.cdap.data2.dataset2.customds.DefaultTopLevelExtendsDataset)2 DelegatingDataset (co.cask.cdap.data2.dataset2.customds.DelegatingDataset)2 TopLevelDataset (co.cask.cdap.data2.dataset2.customds.TopLevelDataset)2 TopLevelDirectDataset (co.cask.cdap.data2.dataset2.customds.TopLevelDirectDataset)2 TopLevelExtendsDataset (co.cask.cdap.data2.dataset2.customds.TopLevelExtendsDataset)2 ByteCodeClassLoader (co.cask.cdap.internal.asm.ByteCodeClassLoader)2 Action (co.cask.cdap.proto.security.Action)2 Test (org.junit.Test)2