Search in sources :

Example 1 with EmbeddedServer

use of org.teiid.runtime.EmbeddedServer 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();
}
Also used : DummyBaseTransactionManager(org.infinispan.transaction.tm.DummyBaseTransactionManager) EmbeddedServer(org.teiid.runtime.EmbeddedServer) LoopbackExecutionFactory(org.teiid.translator.loopback.LoopbackExecutionFactory) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) Before(org.junit.Before)

Example 2 with EmbeddedServer

use of org.teiid.runtime.EmbeddedServer 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);
}
Also used : SourceMappingMetadata(org.teiid.adminapi.impl.SourceMappingMetadata) EmbeddedServer(org.teiid.runtime.EmbeddedServer) LoopbackExecutionFactory(org.teiid.translator.loopback.LoopbackExecutionFactory) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) BeforeClass(org.junit.BeforeClass)

Example 3 with EmbeddedServer

use of org.teiid.runtime.EmbeddedServer in project teiid by teiid.

the class TestMaterializationPerformance method setup.

@Before
public void setup() {
    es = new EmbeddedServer();
    es.start(new EmbeddedConfiguration());
}
Also used : EmbeddedServer(org.teiid.runtime.EmbeddedServer) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) Before(org.junit.Before)

Example 4 with EmbeddedServer

use of org.teiid.runtime.EmbeddedServer in project teiid by teiid.

the class TestTeiidPlatform method init.

@BeforeClass
public static void init() throws VirtualDatabaseException, ConnectorManagerException, TranslatorException, FileNotFoundException, IOException, ResourceException, SQLException {
    server = new EmbeddedServer();
    FileExecutionFactory executionFactory = new FileExecutionFactory();
    server.addTranslator("file", executionFactory);
    FileManagedConnectionFactory fileManagedconnectionFactory = new FileManagedConnectionFactory();
    fileManagedconnectionFactory.setParentDirectory(UnitTestUtil.getTestDataPath() + File.separator + "file");
    ConnectionFactory connectionFactory = fileManagedconnectionFactory.createConnectionFactory();
    ConnectionFactoryProvider<ConnectionFactory> connectionFactoryProvider = new EmbeddedServer.SimpleConnectionFactoryProvider<ConnectionFactory>(connectionFactory);
    server.addConnectionFactoryProvider("java:/marketdata-file", connectionFactoryProvider);
    EmbeddedConfiguration config = new EmbeddedConfiguration();
    server.start(config);
    DriverManager.registerDriver(server.getDriver());
    server.deployVDB(new FileInputStream(UnitTestUtil.getTestDataFile("vdb" + File.separator + "marketdata-vdb.xml")));
    factory = Persistence.createEntityManagerFactory("org.teiid.eclipselink.test");
}
Also used : ConnectionFactory(javax.resource.cci.ConnectionFactory) FileManagedConnectionFactory(org.teiid.resource.adapter.file.FileManagedConnectionFactory) FileExecutionFactory(org.teiid.translator.file.FileExecutionFactory) EmbeddedServer(org.teiid.runtime.EmbeddedServer) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) FileManagedConnectionFactory(org.teiid.resource.adapter.file.FileManagedConnectionFactory) FileInputStream(java.io.FileInputStream) BeforeClass(org.junit.BeforeClass)

Example 5 with EmbeddedServer

use of org.teiid.runtime.EmbeddedServer 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));
}
Also used : Group(java.security.acl.Group) Table(org.teiid.metadata.Table) Statement(java.sql.Statement) EmbeddedServer(org.teiid.runtime.EmbeddedServer) Connection(java.sql.Connection) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) DoNothingSecurityHelper(org.teiid.runtime.DoNothingSecurityHelper) Subject(javax.security.auth.Subject) FileInputStream(java.io.FileInputStream) MetadataFactory(org.teiid.metadata.MetadataFactory) Column(org.teiid.metadata.Column) ResultSet(java.sql.ResultSet) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) Identity(java.security.Identity) Vector(java.util.Vector) Principal(java.security.Principal) Test(org.junit.Test)

Aggregations

EmbeddedConfiguration (org.teiid.runtime.EmbeddedConfiguration)6 EmbeddedServer (org.teiid.runtime.EmbeddedServer)6 Before (org.junit.Before)3 FileInputStream (java.io.FileInputStream)2 BeforeClass (org.junit.BeforeClass)2 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)2 MetadataFactory (org.teiid.metadata.MetadataFactory)2 Table (org.teiid.metadata.Table)2 HardCodedExecutionFactory (org.teiid.runtime.HardCodedExecutionFactory)2 LoopbackExecutionFactory (org.teiid.translator.loopback.LoopbackExecutionFactory)2 Identity (java.security.Identity)1 Principal (java.security.Principal)1 Group (java.security.acl.Group)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 Vector (java.util.Vector)1 ConnectionFactory (javax.resource.cci.ConnectionFactory)1 Subject (javax.security.auth.Subject)1 DummyBaseTransactionManager (org.infinispan.transaction.tm.DummyBaseTransactionManager)1