use of org.teiid.metadata.MetadataFactory in project teiid by teiid.
the class TestSwaggerMetadataProcessor method getMetadata.
private static MetadataFactory getMetadata(SwaggerExecutionFactory ef, final String file) throws TranslatorException {
SwaggerMetadataProcessor processor = new SwaggerMetadataProcessor(ef) {
protected Swagger getSchema(WSConnection conn) throws TranslatorException {
File f = new File(file);
ObjectMapper objectMapper = new ObjectMapper();
try (FileInputStream fis = new FileInputStream(f)) {
JsonNode rootNode = objectMapper.readTree(fis);
return new SwaggerParser().read(rootNode, true);
} catch (IOException e) {
throw new TranslatorException(e);
}
}
};
processor.setPreferredProduces("application/json");
processor.setPreferredConsumes("application/json");
processor.setPreferredScheme("http");
Properties props = new Properties();
MetadataFactory mf = new MetadataFactory("vdb", 1, "swagger", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
processor.process(mf, null);
return mf;
}
use of org.teiid.metadata.MetadataFactory in project teiid by teiid.
the class TestSwaggerMetadataProcessor method testURI.
@Test
public void testURI() throws TranslatorException {
SwaggerExecutionFactory translator = new SwaggerExecutionFactory();
translator.start();
MetadataFactory mf = swaggerMetadata(translator);
Procedure p = mf.getSchema().getProcedure("addCustomer");
assertNotNull(p);
assertEquals("POST", p.getProperty(RestMetadataExtension.METHOD, false).toUpperCase());
assertEquals("http://localhost:8080/customer", p.getProperty(RestMetadataExtension.URI, false));
assertNull(p.getResultSet());
p = mf.getSchema().getProcedure("getCustomers");
assertNotNull(p);
assertEquals("GET", p.getProperty(RestMetadataExtension.METHOD, false).toUpperCase());
assertEquals("http://localhost:8080/customer/customerList", p.getProperty(RestMetadataExtension.URI, false));
assertEquals("application/xml", p.getProperty(RestMetadataExtension.PRODUCES, false));
assertNull(p.getResultSet());
assertEquals("return", p.getParameters().get(0).getName());
assertEquals("string", p.getParameters().get(0).getRuntimeType());
p = mf.getSchema().getProcedure("removeCustomer");
assertNotNull(p);
assertEquals("DELETE", p.getProperty(RestMetadataExtension.METHOD, false).toUpperCase());
assertEquals("http://localhost:8080/customer/delete/{id}", p.getProperty(RestMetadataExtension.URI, false));
assertEquals("application/json", p.getProperty(RestMetadataExtension.PRODUCES, false));
assertNull(p.getResultSet());
assertEquals("id", p.getParameters().get(0).getName());
assertEquals(1, p.getParameters().size());
}
use of org.teiid.metadata.MetadataFactory 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.metadata.MetadataFactory in project teiid by teiid.
the class TestMatViewAliasing method setUp.
@Before
public void setUp() throws Exception {
server = new FakeServer(true);
VDBRepository vdbRepository = new VDBRepository();
MetadataFactory mf = new MetadataFactory(null, 1, "foo", vdbRepository.getRuntimeTypeMap(), new Properties(), null);
mf.getSchema().setPhysical(false);
Table mat = mf.addTable("mat");
mat.setVirtual(true);
mat.setMaterialized(true);
mat.setSelectTransformation("/*+ cache(ttl:0) */ select 1 as x, 'y' as Name");
mf.addColumn("x", DataTypeManager.DefaultDataTypes.INTEGER, mat);
mf.addColumn("Name", DataTypeManager.DefaultDataTypes.STRING, mat);
MetadataStore ms = mf.asMetadataStore();
server.deployVDB(MATVIEWS, ms);
conn = server.createConnection("jdbc:teiid:" + MATVIEWS);
}
use of org.teiid.metadata.MetadataFactory in project teiid by teiid.
the class AbstractVDBDeployer method createMetadataFactory.
protected MetadataFactory createMetadataFactory(VDBMetaData vdb, MetadataStore store, ModelMetaData model, Map<String, ? extends VDBResource> vdbResources) {
Map<String, Datatype> datatypes = store.getDatatypes();
MetadataFactory factory = new MetadataFactory(vdb.getName(), vdb.getVersion(), datatypes, model);
factory.getSchema().setPhysical(model.isSource());
// for thread safety each factory gets it's own instance.
factory.setParser(new QueryParser());
factory.setVdbResources(vdbResources);
return factory;
}
Aggregations