use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestRowBasedSecurity method testSecurity.
@Test
public void testSecurity() throws Exception {
es = new EmbeddedServer();
EmbeddedConfiguration ec = new EmbeddedConfiguration();
final Vector<Principal> v = new Vector<Principal>();
v.add(new Identity("myrole") {
});
final Subject subject = new Subject();
Group g = Mockito.mock(Group.class);
Mockito.stub(g.getName()).toReturn("Roles");
Mockito.stub(g.members()).toReturn((Enumeration) v.elements());
subject.getPrincipals().add(g);
ec.setSecurityHelper(new DoNothingSecurityHelper() {
@Override
public Subject getSubjectInContext(String securityDomain) {
return subject;
}
@Override
public Subject getSubjectInContext(Object context) {
return subject;
}
});
es.start(ec);
HardCodedExecutionFactory hcef = new HardCodedExecutionFactory() {
@Override
public void getMetadata(MetadataFactory metadataFactory, Object conn) throws TranslatorException {
Table t = metadataFactory.addTable("x");
Column col = metadataFactory.addColumn("col", TypeFacility.RUNTIME_NAMES.STRING, t);
metadataFactory.addColumn("col2", TypeFacility.RUNTIME_NAMES.STRING, t);
metadataFactory.addPermission("y", t, null, null, Boolean.TRUE, null, null, null, "col = 'a'", null);
metadataFactory.addColumnPermission("y", col, null, null, null, null, "null", null);
t = metadataFactory.addTable("y");
col = metadataFactory.addColumn("col", TypeFacility.RUNTIME_NAMES.STRING, t);
metadataFactory.addColumn("col2", TypeFacility.RUNTIME_NAMES.STRING, t);
metadataFactory.addPermission("z", t, null, null, null, null, null, null, "col = 'e'", null);
Table v = metadataFactory.addTable("v");
metadataFactory.addPermission("y", v, null, null, Boolean.TRUE, null, null, null, null, null);
col = metadataFactory.addColumn("col", TypeFacility.RUNTIME_NAMES.STRING, v);
metadataFactory.addColumn("col2", TypeFacility.RUNTIME_NAMES.STRING, v);
v.setTableType(Type.View);
v.setVirtual(true);
v.setSelectTransformation("/*+ cache(scope:session) */ select col, col2 from y");
}
@Override
public boolean isSourceRequiredForMetadata() {
return false;
}
};
hcef.addData("SELECT x.col, x.col2 FROM x", Arrays.asList(Arrays.asList("a", "b"), Arrays.asList("c", "d")));
hcef.addData("SELECT y.col, y.col2 FROM y", Arrays.asList(Arrays.asList("e", "f"), Arrays.asList("h", "g")));
es.addTranslator("hc", hcef);
es.deployVDB(new FileInputStream(UnitTestUtil.getTestDataFile("roles-vdb.xml")));
Connection c = es.getDriver().connect("jdbc:teiid:z;PassthroughAuthentication=true", null);
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("select * from x");
rs.next();
// masking
assertEquals(null, rs.getString(1));
assertEquals("b", rs.getString(2));
// row filter
assertFalse(rs.next());
rs.close();
s = c.createStatement();
rs = s.executeQuery("select lookup('myschema.x', 'col', 'col2', 'b')");
rs.next();
// global scoped
assertEquals(null, rs.getString(1));
s = c.createStatement();
rs = s.executeQuery("select count(col2) from v where col is not null");
rs.next();
assertEquals(1, rs.getInt(1));
// different session with different roles
v.clear();
c = es.getDriver().connect("jdbc:teiid:z;PassthroughAuthentication=true", null);
s = c.createStatement();
rs = s.executeQuery("select count(col2) from v where col is not null");
rs.next();
assertEquals(2, rs.getInt(1));
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestExternalMatViews method testNodeFailure.
@Test
public void testNodeFailure() throws Exception {
FakeServer server1 = createServer("server1", "infinispan-replicated-config.xml", "tcp-shared.xml");
HardCodedExecutionFactory hcef = setupData(server1);
ModelMetaData sourceModel = setupSourceModel();
ModelMetaData matViewModel = setupMatViewModel();
ModelMetaData viewModel = new ModelMetaData();
viewModel.setName("view1");
viewModel.setModelType(Type.VIRTUAL);
viewModel.addSourceMetadata("DDL", "CREATE VIEW v1 (col integer primary key, col1 string) " + "OPTIONS (MATERIALIZED true, " + "MATERIALIZED_TABLE 'matview.MAT_V2', " + "\"teiid_rel:MATVIEW_TTL\" 30000, " + "\"teiid_rel:ALLOW_MATVIEW_MANAGEMENT\" true, " + "\"teiid_rel:MATVIEW_SHARE_SCOPE\" 'FULL', " + "\"teiid_rel:MATVIEW_STATUS_TABLE\" 'matview.STATUS', " + "\"teiid_rel:MATVIEW_LOADNUMBER_COLUMN\" 'loadnum') " + "AS select col, col1 from source.physicalTbl");
server1.deployVDB("comp", sourceModel, viewModel, matViewModel);
Thread.sleep(1000);
FakeServer server2 = createServer("server2", "infinispan-replicated-config-1.xml", "tcp-shared.xml");
setupData(server2);
server2.deployVDB("comp", sourceModel, viewModel, matViewModel);
Thread.sleep(5000);
Connection c = h2DataSource.getConnection();
ResultSet rs = c.createStatement().executeQuery("SELECT LoadState, Nodename FROM Status WHERE VDBName = 'comp'");
rs.next();
assertEquals("LOADED", rs.getString(1));
assertEquals("server1", rs.getString(2));
int update = c.createStatement().executeUpdate("UPDATE Status SET LoadState = 'LOADING' WHERE VDBName = 'comp' AND Nodename = 'server1'");
assertEquals(1, update);
server1.stop();
Thread.sleep(1000);
rs = c.createStatement().executeQuery("SELECT LoadState, Nodename FROM Status WHERE VDBName = 'comp'");
rs.next();
assertEquals("LOADED", rs.getString(1));
assertEquals("server2", rs.getString(2));
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestExternalMatViews method internalWithSameExternalProcedures.
private void internalWithSameExternalProcedures(boolean useUpdateScript) throws Exception {
HardCodedExecutionFactory hcef = setupData(server);
ModelMetaData sourceModel = setupSourceModel();
ModelMetaData matViewModel = setupMatViewModel();
ModelMetaData viewModel = new ModelMetaData();
viewModel.setName("view1");
viewModel.setModelType(Type.VIRTUAL);
viewModel.addSourceMetadata("DDL", "CREATE VIEW v1 (col integer primary key, col1 string) " + "OPTIONS (MATERIALIZED true, " + "\"teiid_rel:MATVIEW_TTL\" 3000, " + "\"teiid_rel:MATVIEW_UPDATABLE\" true, " + "\"teiid_rel:MATVIEW_STATUS_TABLE\" 'matview.STATUS', " + "\"teiid_rel:ALLOW_MATVIEW_MANAGEMENT\" true) " + "AS select col, col1 from source.physicalTbl");
server.deployVDB("comp", sourceModel, viewModel, matViewModel);
Thread.sleep(1000);
assertTest(useUpdateScript, hcef);
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestExternalMatViews method withSwapScripts.
private void withSwapScripts(boolean useUpdateScript) throws Exception {
HardCodedExecutionFactory hcef = setupData(server);
ModelMetaData sourceModel = setupSourceModel();
ModelMetaData matViewModel = setupMatViewModel();
ModelMetaData viewModel = new ModelMetaData();
viewModel.setName("view1");
viewModel.setModelType(Type.VIRTUAL);
viewModel.addSourceMetadata("DDL", "CREATE VIEW v1 (col integer primary key, col1 string) " + "OPTIONS (MATERIALIZED true, " + "MATERIALIZED_TABLE 'matview.MAT_V1', " + "\"teiid_rel:MATVIEW_TTL\" 3000, " + "\"teiid_rel:ALLOW_MATVIEW_MANAGEMENT\" true, " + "\"teiid_rel:MATVIEW_STATUS_TABLE\" 'matview.STATUS', " + "\"teiid_rel:MATERIALIZED_STAGE_TABLE\" 'matview.MAT_V1_STAGE', " + "\"teiid_rel:MATVIEW_BEFORE_LOAD_SCRIPT\" 'execute matview.native(''truncate table MAT_V1_STAGE'')', " + "\"teiid_rel:MATVIEW_AFTER_LOAD_SCRIPT\" " + "'begin " + "execute matview.native(''ALTER TABLE MAT_V1 RENAME TO MAT_V1_TEMP'');" + "execute matview.native(''ALTER TABLE MAT_V1_STAGE RENAME TO MAT_V1'');" + "execute matview.native(''ALTER TABLE MAT_V1_TEMP RENAME TO MAT_V1_STAGE''); " + "end', " + "\"teiid_rel:MATVIEW_ONERROR_ACTION\" 'THROW_EXCEPTION') " + "AS select col, col1 from source.physicalTbl");
server.deployVDB("comp", sourceModel, viewModel, matViewModel);
Thread.sleep(1000);
assertTest(useUpdateScript, hcef);
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestExternalMatViews method testRestartServerInMiddleOfLoading.
@Test
public void testRestartServerInMiddleOfLoading() throws Exception {
HardCodedExecutionFactory hcef = setupData(server);
ModelMetaData sourceModel = setupSourceModel();
ModelMetaData matViewModel = setupMatViewModel();
ModelMetaData viewModel = new ModelMetaData();
viewModel.setName("view1");
viewModel.setModelType(Type.VIRTUAL);
viewModel.addSourceMetadata("DDL", "CREATE VIEW v1 (col integer primary key, col1 string) " + "OPTIONS (MATERIALIZED true, " + "MATERIALIZED_TABLE 'matview.MAT_V2', " + "\"teiid_rel:MATVIEW_TTL\" 3000, " + "\"teiid_rel:ALLOW_MATVIEW_MANAGEMENT\" true, " + "\"teiid_rel:MATVIEW_STATUS_TABLE\" 'matview.STATUS', " + "\"teiid_rel:MATVIEW_LOADNUMBER_COLUMN\" 'loadnum') " + "AS select col, col1 from source.physicalTbl");
server.deployVDB("comp", sourceModel, viewModel, matViewModel);
Thread.sleep(1000);
// test that the matview loaded
conn = server.createConnection("jdbc:teiid:comp");
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("select * from view1.v1 order by col");
rs.next();
assertEquals(1, rs.getInt(1));
assertEquals("town", rs.getString(2));
// now change the status table underneath
h2DataSource = getDatasource();
Connection c = h2DataSource.getConnection();
assertNotNull(c);
Statement stmt = c.createStatement();
boolean update = stmt.execute("UPDATE status SET LOADSTATE = 'LOADING' WHERE NAME = 'v1'");
// this is update
assertFalse(update);
assertEquals(1, stmt.getUpdateCount());
rs = c.createStatement().executeQuery("SELECT LOADSTATE, NODENAME FROM status");
assertTrue(rs.next());
assertEquals("LOADING", rs.getString(1));
assertEquals("localhost", rs.getString(2));
server.stop();
server = new FakeServer(true);
setupData(server);
setupSourceModel();
setupMatViewModel();
server.deployVDB("comp", sourceModel, viewModel, matViewModel);
Thread.sleep(1000);
rs = c.createStatement().executeQuery("SELECT LOADSTATE, NODENAME FROM STATUS WHERE NAME = 'v1'");
assertTrue(rs.next());
assertEquals("LOADED", rs.getString(1));
assertEquals("localhost", rs.getString(2));
}
Aggregations