use of org.teiid.runtime.EmbeddedConfiguration in project teiid by teiid.
the class TestODataIntegration method before.
@Before
public void before() throws Exception {
TimestampWithTimezone.resetCalendar(TimeZone.getTimeZone("UTC"));
teiid = new EmbeddedServer();
EmbeddedConfiguration config = new EmbeddedConfiguration();
config.setTransactionManager(new DummyBaseTransactionManager());
teiid.start(config);
ef = new LoopbackExecutionFactory() {
@Override
public boolean supportsRowOffset() {
return false;
}
};
teiid.addTranslator("loopback", ef);
createContext("/odata4", null);
deployVDB();
}
use of org.teiid.runtime.EmbeddedConfiguration in project teiid by teiid.
the class TestASTQueries method setUp.
@BeforeClass
public static void setUp() throws Exception {
server = new EmbeddedServer();
server.start(new EmbeddedConfiguration());
LoopbackExecutionFactory loopy = new LoopbackExecutionFactory();
loopy.setRowCount(10);
loopy.start();
server.addTranslator("l", loopy);
String DDL = "CREATE FOREIGN TABLE G1 (e1 string, e2 integer);";
ModelMetaData model = new ModelMetaData();
model.setName("PM1");
model.setModelType(Model.Type.PHYSICAL);
model.setSchemaSourceType("DDL");
model.setSchemaText(DDL);
SourceMappingMetadata sm = new SourceMappingMetadata();
sm.setName("loopy");
sm.setTranslatorName("l");
model.addSourceMapping(sm);
server.deployVDB("test", model);
}
use of org.teiid.runtime.EmbeddedConfiguration in project teiid by teiid.
the class TestDataRoles method testMetadataWithSecurity.
@Test
public void testMetadataWithSecurity() throws Exception {
es = new ExtendedEmbeddedServer();
EmbeddedConfiguration ec = new EmbeddedConfiguration();
es.start(ec);
es.deployVDB(new ByteArrayInputStream(new String("<vdb name=\"role-1\" version=\"1\">" + "<model name=\"s1\" type=\"virtual\">" + "<metadata type = \"DDL\"><![CDATA[" + "CREATE VIEW t2 (col string primary key) options (x 'y') as select 'a' as col;\n" + "CREATE VIEW t1 (col string, col_hidden string, primary key (col, col_hidden), foreign key (col) references t2) options (x 'y1') as select col, 'b' as col_hidden from t2;\n" + "CREATE virtual procedure proc1 (param1 string) returns table (proc_col string) as begin end;\n" + "]]></metadata></model>" + "<model name=\"s2\" type=\"virtual\">" + "<metadata type = \"DDL\"><![CDATA[" + "CREATE VIEW t3 as select 'a' as col, 'b' as col_hidden;\n" + "CREATE virtual procedure proc2 (param2 string) returns table (proc_col string) as begin end;\n" + "]]></metadata></model>" + "<data-role name=\"y\" any-authenticated=\"true\">" + "<permission><resource-name>s1</resource-name><allow-read>true</allow-read></permission>" + "<permission><resource-name>s1.t1.col_hidden</resource-name><allow-read>false</allow-read></permission>" + "<permission><resource-name>s1.t2</resource-name><allow-read>false</allow-read></permission>" + "<permission><resource-name>sysadmin</resource-name><allow-read>true</allow-read></permission>" + "</data-role></vdb>").getBytes()));
Connection c = es.getDriver().connect("jdbc:teiid:role-1", null);
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("select * from sys.tables where name like 't_'");
// only t1 should be visible
assertTrue(rs.next());
assertEquals("t1", rs.getString("name"));
assertFalse(rs.next());
rs = s.executeQuery("select * from sys.schemas where name like 's_' order by name");
// both are visible for now
assertTrue(rs.next());
assertEquals("s1", rs.getString("name"));
assertTrue(rs.next());
assertEquals("s2", rs.getString("name"));
assertFalse(rs.next());
rs = s.executeQuery("select * from sys.columns where tablename like 't_'");
// only col should be visible
assertTrue(rs.next());
assertEquals("col", rs.getString("name"));
assertFalse(rs.next());
rs = s.executeQuery("select * from sys.procedures where name like 'proc_'");
// only proc1 should be visible
assertTrue(rs.next());
assertEquals("proc1", rs.getString("name"));
assertFalse(rs.next());
rs = s.executeQuery("select * from sys.procedureparams where procedurename like 'proc_'");
// only proc1 should be visible
assertTrue(rs.next());
assertEquals("param1", rs.getString("name"));
assertTrue(rs.next());
assertEquals("proc_col", rs.getString("name"));
assertFalse(rs.next());
rs = s.executeQuery("select * from sysadmin.usage where schemaname like 's_'");
// nothing should be visible
assertFalse(rs.next());
rs = s.executeQuery("select * from sys.properties where name = 'x'");
assertTrue(rs.next());
assertEquals("y1", rs.getString("Value"));
assertFalse(rs.next());
rs = s.executeQuery("select * from sys.keycolumns where tablename = 't1'");
// nothing should be visible
assertFalse(rs.next());
rs = s.executeQuery("select * from sys.keys where tablename = 't1'");
// nothing should be visible
assertFalse(rs.next());
}
use of org.teiid.runtime.EmbeddedConfiguration in project teiid by teiid.
the class TestDataRoles method testExecuteImmediate.
@Test
public void testExecuteImmediate() throws Exception {
es = new ExtendedEmbeddedServer();
EmbeddedConfiguration ec = new EmbeddedConfiguration();
es.start(ec);
es.deployVDB(new ByteArrayInputStream(new String("<vdb name=\"role-1\" version=\"1\">" + "<model name=\"myschema\" type=\"virtual\">" + "<metadata type = \"DDL\"><![CDATA[CREATE VIEW vw as select 'a' as col;]]></metadata></model>" + "<data-role name=\"y\" any-authenticated=\"true\"/></vdb>").getBytes()));
Connection c = es.getDriver().connect("jdbc:teiid:role-1", null);
Statement s = c.createStatement();
s.execute("set autoCommitTxn off");
try {
s.execute("begin execute immediate 'select * from vw'; end");
fail();
} catch (TeiidSQLException e) {
}
// should be valid
s.execute("begin execute immediate 'select 1'; end");
// no temp permission
try {
s.execute("begin execute immediate 'select 1' as x integer into #temp; end");
fail();
} catch (TeiidSQLException e) {
}
// nested should not pass either
try {
s.execute("begin execute immediate 'begin execute immediate ''select * from vw''; end'; end");
fail();
} catch (TeiidSQLException e) {
}
}
use of org.teiid.runtime.EmbeddedConfiguration in project teiid by teiid.
the class TestInternalConnection method testInternalLocal.
@Test
public void testInternalLocal() throws Exception {
EmbeddedConfiguration config = new EmbeddedConfiguration();
config.setSecurityHelper(new ThreadLocalSecurityHelper());
es.start(config);
es.deployVDB(new ByteArrayInputStream(vdb.getBytes()));
Connection conn = null;
try {
TeiidDriver driver = es.getDriver();
conn = driver.connect("jdbc:teiid:test", null);
// execute multiple to check for an id conflict
ResultSet rs = conn.createStatement().executeQuery("select func(2) union all select func(3)");
rs.next();
assertEquals("anonymous@teiid-securityHELLO WORLD2", rs.getString(1));
rs.next();
assertEquals("anonymous@teiid-securityHELLO WORLD3", rs.getString(1));
ResultSetMetaData metadata = rs.getMetaData();
assertNotNull(metadata.getColumnName(1));
} finally {
if (conn != null) {
conn.close();
}
}
}
Aggregations