Search in sources :

Example 11 with EmbeddedConfiguration

use of org.teiid.runtime.EmbeddedConfiguration 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 12 with EmbeddedConfiguration

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

the class TestPassthroughAuthentication method oneTimeSetup.

@BeforeClass
public static void oneTimeSetup() throws Exception {
    server.setUseCallingThread(true);
    server.start(new EmbeddedConfiguration() {

        @Override
        public SecurityHelper getSecurityHelper() {
            return securityHelper;
        }
    }, false);
}
Also used : EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) SecurityHelper(org.teiid.security.SecurityHelper) BeforeClass(org.junit.BeforeClass)

Example 13 with EmbeddedConfiguration

use of org.teiid.runtime.EmbeddedConfiguration 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)

Example 14 with EmbeddedConfiguration

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

the class TestExternalMatViews method createServer.

private FakeServer createServer(String nodeName, String ispn, String jgroups) throws Exception {
    FakeServer server = new FakeServer(false);
    EmbeddedConfiguration config = new EmbeddedConfiguration();
    config.setInfinispanConfigFile(ispn);
    config.setJgroupsConfigFile(jgroups);
    config.setNodeName(nodeName);
    config.setTransactionManager(new DummyTransactionManager());
    server.start(config, true);
    return server;
}
Also used : DummyTransactionManager(org.infinispan.transaction.tm.DummyTransactionManager) FakeServer(org.teiid.jdbc.FakeServer) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration)

Example 15 with EmbeddedConfiguration

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

the class TestReplication method createServer.

private FakeServer createServer(String ispn, String jgroups) throws Exception {
    FakeServer server = new FakeServer(false);
    EmbeddedConfiguration config = new EmbeddedConfiguration();
    config.setInfinispanConfigFile(ispn);
    config.setJgroupsConfigFile(jgroups);
    config.setTransactionManager(new DummyTransactionManager());
    server.start(config, true);
    return server;
}
Also used : DummyTransactionManager(org.infinispan.transaction.tm.DummyTransactionManager) FakeServer(org.teiid.jdbc.FakeServer) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration)

Aggregations

EmbeddedConfiguration (org.teiid.runtime.EmbeddedConfiguration)26 Test (org.junit.Test)12 Connection (java.sql.Connection)9 BeforeClass (org.junit.BeforeClass)8 FakeServer (org.teiid.jdbc.FakeServer)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 FileInputStream (java.io.FileInputStream)7 ResultSet (java.sql.ResultSet)6 EmbeddedServer (org.teiid.runtime.EmbeddedServer)6 Statement (java.sql.Statement)5 InetSocketAddress (java.net.InetSocketAddress)4 DummyTransactionManager (org.infinispan.transaction.tm.DummyTransactionManager)3 Before (org.junit.Before)3 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)3 HardCodedExecutionFactory (org.teiid.runtime.HardCodedExecutionFactory)3 File (java.io.File)2 SQLException (java.sql.SQLException)2 Properties (java.util.Properties)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Subject (javax.security.auth.Subject)2