Rather than connecting to JDBC using “jdbcUrl", “jdbcUser", “jdbcPassword” operands of the JDBC adapter you could instead connect to a data source. Write a class that implements javax.sql.DataSource, and include the class name in the model with a “dataSource” operand.
Your class can authenticate with the back-end database any way it likes. Julian > On Oct 1, 2017, at 5:06 AM, Alexey Roytman <[email protected]> wrote: > > Dear colleagues, I'm doing my first steps in creating custom SchemaFactory > for accessing some endpoint. > My question is as following: > if I do DriverManager.getConnection(url, user, password); > why then: > SchemaFactory.create(SchemaPlus, String, Map<String, Object>) > gets the map without user and password? > > I shall not create a model file (because it's a plain text with password); I > shall not pass username and password in URL (e.g. > ";schema.username=...;schema.password=..." or model inline) because it's > saved as plain text. > > I cannot change the call from DriverManager.getConnection(url, user, > password) to DriverManager.getConnection(url, Properties info) with custom > Properties, as I don't control that code. > > My test code basically does this: > String user; > String password; > String url; > ... > // got user, password and url from somewhere > // the url is of form: "jdbc:calcite:schemaFactory=MySchemaFactory" > Class.forName("org.apache.calcite.jdbc.Driver"); > java.sql.Connection conn = DriverManager.getConnection(url, user, > password); > > And the MySchemaFactory.java looks like this: > --- > public class MySchemaFactory implements > org.apache.calcite.schema.SchemaFactory { > public MySchemaFactory() { > System.out.println("Factory"); > } > @Override > public Schema create(SchemaPlus schemaPlus, String s, > java.util.Map<String, Object> map) { > String url = (String)map.get("url"); > String username = (String)map.get("username"); > String password = (String)map.get("password"); > // do something with url, username and password... > return null; // just for demonstration > } > } > --- > > Instead of MySchemaFactory I can use > org.apache.calcite.adapter.cassandra.CassandraSchemaFactory, with same > result: the map has no credentials. > > Does anyone have any idea of a secure way of passing credentials?.. > Maybe, I need to write my own class extending org.apache.calcite.jdbc.Driver? > What the right Calcite's way? > > - Alexey. >
