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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations