Search in sources :

Example 31 with DataPolicyMetadata

use of org.teiid.adminapi.impl.DataPolicyMetadata in project teiid by teiid.

the class TestAuthorizationValidationVisitor method testObjectTable.

@Test
public void testObjectTable() throws Exception {
    // $NON-NLS-1$ //$NON-NLS-2$
    helpTest("select * from objecttable(language 'javascript' 'teiid_context' columns x string 'teiid_row.userName') as x", RealMetadataFactory.exampleBQTCached(), new String[] { "OBJECTTABLE(LANGUAGE 'javascript' 'teiid_context' COLUMNS x string 'teiid_row.userName') AS x" }, RealMetadataFactory.exampleBQTVDB(), exampleAuthSvc1);
    DataPolicyMetadata policy = exampleAuthSvc1();
    policy.addPermission(addResource(PermissionType.LANGUAGE, "javascript"));
    // $NON-NLS-1$ //$NON-NLS-2$
    helpTest("select * from objecttable(language 'javascript' 'teiid_context' columns x string 'teiid_row.userName') as x", RealMetadataFactory.exampleBQTCached(), new String[] {}, RealMetadataFactory.exampleBQTVDB(), policy);
}
Also used : DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) Test(org.junit.Test)

Example 32 with DataPolicyMetadata

use of org.teiid.adminapi.impl.DataPolicyMetadata in project teiid by teiid.

the class TestColumnMasking method testSubqueryTableMask.

@Test
public void testSubqueryTableMask() throws Exception {
    DataPolicyMetadata policy1 = new DataPolicyMetadata();
    PermissionMetaData pmd11 = new PermissionMetaData();
    pmd11.setResourceName("pm1.g1.e2");
    // takes presedence
    pmd11.setOrder(1);
    pmd11.setMask("(select min(e2) from pm1.g3)");
    policy1.addPermission(pmd11);
    policy1.setName("other-role");
    context.getAllowedDataPolicies().put("other-role", policy1);
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT pm1.g1.e1 FROM pm1.g1", new List<?>[] { Arrays.asList("a"), Arrays.asList("b") });
    dataManager.addData("SELECT pm1.g3.e2 FROM pm1.g3", new List<?>[] { Arrays.asList(1), Arrays.asList(2) });
    ProcessorPlan plan = helpGetPlan(helpParse("select e1, g2.e2 from pm1.g1 as g2"), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(), context);
    List<?>[] expectedResults = new List<?>[] { Arrays.asList("a", 1), Arrays.asList("b", 1) };
    helpProcess(plan, context, dataManager, expectedResults);
}
Also used : DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) List(java.util.List) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) PermissionMetaData(org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData) Test(org.junit.Test)

Example 33 with DataPolicyMetadata

use of org.teiid.adminapi.impl.DataPolicyMetadata in project teiid by teiid.

the class TestColumnMasking method testInvalidTableMask.

@Test(expected = QueryMetadataException.class)
public void testInvalidTableMask() throws Exception {
    DataPolicyMetadata policy1 = new DataPolicyMetadata();
    PermissionMetaData pmd11 = new PermissionMetaData();
    pmd11.setResourceName("pm1.g1.e2");
    // takes presedence
    pmd11.setOrder(1);
    pmd11.setMask("'a'");
    policy1.addPermission(pmd11);
    policy1.setName("other-role");
    context.getAllowedDataPolicies().put("other-role", policy1);
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1", new List<?>[] { Arrays.asList("a", 1), Arrays.asList("b", 2) });
    ProcessorPlan plan = helpGetPlan(helpParse("select e2 from pm1.g1"), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(), context);
    List<?>[] expectedResults = new List<?>[] { Collections.singletonList(null), Arrays.asList(2) };
    helpProcess(plan, context, dataManager, expectedResults);
}
Also used : DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) List(java.util.List) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) PermissionMetaData(org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData) Test(org.junit.Test)

Example 34 with DataPolicyMetadata

use of org.teiid.adminapi.impl.DataPolicyMetadata in project teiid by teiid.

the class TestColumnMasking method testWindowFunctionViewMask.

@Test(expected = QueryMetadataException.class)
public void testWindowFunctionViewMask() throws Exception {
    DataPolicyMetadata policy1 = new DataPolicyMetadata();
    PermissionMetaData pmd11 = new PermissionMetaData();
    pmd11.setResourceName("vm1.g1.e2");
    pmd11.setMask("min(e2) over ()");
    policy1.addPermission(pmd11);
    policy1.setName("other-role");
    context.getAllowedDataPolicies().put("other-role", policy1);
    HardcodedDataManager dataManager = new HardcodedDataManager();
    ProcessorPlan plan = helpGetPlan(helpParse("select g2.e2 from vm1.g1 as g2"), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(), context);
    helpProcess(plan, context, dataManager, null);
}
Also used : DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) PermissionMetaData(org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData) Test(org.junit.Test)

Example 35 with DataPolicyMetadata

use of org.teiid.adminapi.impl.DataPolicyMetadata in project teiid by teiid.

the class TestColumnMasking method createContext.

private static CommandContext createContext() {
    CommandContext context = createCommandContext();
    DQPWorkContext workContext = new DQPWorkContext();
    HashMap<String, DataPolicy> policies = new HashMap<String, DataPolicy>();
    DataPolicyMetadata policy = new DataPolicyMetadata();
    PermissionMetaData pmd = new PermissionMetaData();
    pmd.setResourceName("pm1.sp1.e1");
    pmd.setMask("case when e2 > 1 then null else e1 end");
    PermissionMetaData pmd1 = new PermissionMetaData();
    pmd1.setResourceName("pm1.g1.e2");
    pmd1.setMask("case when e1 = 'a' then null else e2 end");
    policy.addPermission(pmd, pmd1);
    policy.setName("some-role");
    policies.put("some-role", policy);
    workContext.setPolicies(policies);
    context.setDQPWorkContext(workContext);
    return context;
}
Also used : DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) CommandContext(org.teiid.query.util.CommandContext) HashMap(java.util.HashMap) DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) DataPolicy(org.teiid.adminapi.DataPolicy) PermissionMetaData(org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData)

Aggregations

DataPolicyMetadata (org.teiid.adminapi.impl.DataPolicyMetadata)47 Test (org.junit.Test)26 PermissionMetaData (org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData)24 List (java.util.List)14 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)13 DataPolicy (org.teiid.adminapi.DataPolicy)12 HashMap (java.util.HashMap)7 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)7 Map (java.util.Map)4 AdminProcessingException (org.teiid.adminapi.AdminProcessingException)4 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)3 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)3 DQPWorkContext (org.teiid.dqp.internal.process.DQPWorkContext)3 CommandContext (org.teiid.query.util.CommandContext)3 ArrayList (java.util.ArrayList)2 DataPermission (org.teiid.adminapi.DataPolicy.DataPermission)2 Translator (org.teiid.adminapi.Translator)2 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)2 Permission (org.teiid.metadata.Grant.Permission)2 Expression (org.teiid.query.sql.symbol.Expression)2