use of org.teiid.adminapi.impl.DataPolicyMetadata in project teiid by teiid.
the class TestEmbeddedServerAdmin method testDataRoleMapping.
@Ignore("This test need enable DataRole Configuration in 'adminapi-test-vdb.xml'")
@Test
public void testDataRoleMapping() throws AdminException {
String vdbName = "AdminAPITestVDB";
int vdbVersion = 1;
String policyName = "TestDataRole";
DataPolicyMetadata policy = getPolicy(admin.getVDB(vdbName, vdbVersion), policyName);
assertEquals(1, policy.getMappedRoleNames().size());
admin.addDataRoleMapping(vdbName, vdbVersion, policyName, "test-role-name");
policy = getPolicy(admin.getVDB(vdbName, vdbVersion), policyName);
assertEquals(2, policy.getMappedRoleNames().size());
admin.removeDataRoleMapping(vdbName, vdbVersion, policyName, "test-role-name");
policy = getPolicy(admin.getVDB(vdbName, vdbVersion), policyName);
assertEquals(1, policy.getMappedRoleNames().size());
boolean previous = policy.isAnyAuthenticated();
admin.setAnyAuthenticatedForDataRole(vdbName, vdbVersion, policyName, !previous);
policy = getPolicy(admin.getVDB(vdbName, vdbVersion), policyName);
assertEquals(!previous, policy.isAnyAuthenticated());
admin.setAnyAuthenticatedForDataRole(vdbName, vdbVersion, policyName, previous);
}
use of org.teiid.adminapi.impl.DataPolicyMetadata in project teiid by teiid.
the class TestRowBasedSecurity method testInsertConstraintSubquery.
@Test
public void testInsertConstraintSubquery() throws Exception {
DataPolicyMetadata policy1 = new DataPolicyMetadata();
PermissionMetaData pmd3 = new PermissionMetaData();
pmd3.setResourceName("pm1.g1");
pmd3.setCondition("e1 = (select min(e1) from pm1.g3)");
policy1.addPermission(pmd3);
policy1.setName("some-other-role");
context.getAllowedDataPolicies().put("some-other-role", policy1);
HardcodedDataManager dataManager = new HardcodedDataManager();
dataManager.addData("SELECT g_0.e1 FROM pm1.g3 AS g_0", new List<?>[] { Arrays.asList("a"), Arrays.asList("b") });
dataManager.addData("INSERT INTO pm1.g1 (e1, e2) VALUES ('a', 1)", new List<?>[] { Arrays.asList(1) });
ProcessorPlan plan = helpGetPlan(helpParse("insert into pm1.g1 (e1, e2) values ('a', 1)"), RealMetadataFactory.example1Cached(), TestOptimizer.getGenericFinder(), context);
List<?>[] expectedResults = new List<?>[] { Arrays.asList(1) };
helpProcess(plan, context, dataManager, expectedResults);
}
use of org.teiid.adminapi.impl.DataPolicyMetadata in project teiid by teiid.
the class TestRowBasedSecurity method testSelectFilterOuterJoin1.
@Test
public void testSelectFilterOuterJoin1() throws Exception {
TransformationMetadata tm = RealMetadataFactory.fromDDL("create foreign table t (x string, y integer); create foreign table t1 (x string, y integer); create view v as select t.x, t1.y from t left outer join t1 on t.y = t1.y", "x", "y");
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, false);
caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, false);
caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, false);
CommandContext context = createCommandContext();
DQPWorkContext workContext = new DQPWorkContext();
HashMap<String, DataPolicy> policies = new HashMap<String, DataPolicy>();
DataPolicyMetadata policy = new DataPolicyMetadata();
pmd = new PermissionMetaData();
pmd.setResourceName("y.v");
pmd.setCondition("x = user()");
policy.addPermission(pmd);
policy.setName("some-role");
policies.put("some-role", policy);
workContext.setPolicies(policies);
context.setDQPWorkContext(workContext);
HardcodedDataManager dataManager = new HardcodedDataManager();
dataManager.addData("SELECT g_0.y AS c_0, g_0.x AS c_1 FROM y.t AS g_0 ORDER BY c_0", new List<?>[] { Arrays.asList(1, "a"), Arrays.asList(2, "b") });
dataManager.addData("SELECT g_0.y AS c_0 FROM y.t1 AS g_0 ORDER BY c_0", new List<?>[] { Arrays.asList(1) });
ProcessorPlan plan = helpGetPlan(helpParse("select count(1) from v"), tm, new DefaultCapabilitiesFinder(caps), context);
List<?>[] expectedResults = new List<?>[] { Arrays.asList(0) };
helpProcess(plan, context, dataManager, expectedResults);
plan = helpGetPlan(helpParse("select count(1) from v where y is not null"), tm, new DefaultCapabilitiesFinder(caps), context);
dataManager.addData("SELECT g_0.y FROM y.t AS g_0 WHERE g_0.x = 'user'", new List<?>[] { Arrays.asList(1), Arrays.asList(2) });
dataManager.addData("SELECT g_0.y AS c_0 FROM y.t1 AS g_0 WHERE g_0.y IS NOT NULL ORDER BY c_0", Arrays.asList(1));
expectedResults = new List<?>[] { Arrays.asList(1) };
helpProcess(plan, context, dataManager, expectedResults);
}
use of org.teiid.adminapi.impl.DataPolicyMetadata in project teiid by teiid.
the class TestColumnMasking method testSubqueryProcedureMask.
@Test
public void testSubqueryProcedureMask() throws Exception {
DataPolicyMetadata policy1 = new DataPolicyMetadata();
PermissionMetaData pmd11 = new PermissionMetaData();
pmd11.setResourceName("pm1.sp1.e2");
// takes presedence
pmd11.setOrder(1);
pmd11.setMask("(select min(e2) from pm1.g3 where e1 = pm1.sp1.e2)");
policy1.addPermission(pmd11);
policy1.setName("other-role");
context.getAllowedDataPolicies().put("other-role", policy1);
HardcodedDataManager dataManager = new HardcodedDataManager();
dataManager.addData("EXEC pm1.sp1()", new List<?>[] { Arrays.asList("a", 1), Arrays.asList("b", 2) });
dataManager.addData("SELECT pm1.g3.e1, pm1.g3.e2 FROM pm1.g3", new List<?>[] { Arrays.asList("1", 0), Arrays.asList("2", -1) });
ProcessorPlan plan = helpGetPlan(helpParse("exec pm1.sp1()"), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(), context);
List<?>[] expectedResults = new List<?>[] { Arrays.asList("a", 0), Arrays.asList(null, -1) };
helpProcess(plan, context, dataManager, expectedResults);
}
use of org.teiid.adminapi.impl.DataPolicyMetadata in project teiid by teiid.
the class TestColumnMasking method testViewMaskWithRowFilter.
@Test
public void testViewMaskWithRowFilter() throws Exception {
DataPolicyMetadata policy1 = new DataPolicyMetadata();
PermissionMetaData pmd11 = new PermissionMetaData();
pmd11.setResourceName("vm1.g1.e2");
pmd11.setMask("null");
PermissionMetaData pmd12 = new PermissionMetaData();
pmd12.setResourceName("vm1.g1");
// should be applied before the mask affect, otherwise we'd get no rows
pmd12.setCondition("e2 = 1");
policy1.addPermission(pmd11, pmd12);
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", 1) });
ProcessorPlan plan = helpGetPlan(helpParse("select g2.e2 from vm1.g1 as g2"), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(), context);
List<?>[] expectedResults = new List<?>[] { Collections.singletonList(null) };
helpProcess(plan, context, dataManager, expectedResults);
}
Aggregations