Skip to content

Commit

Permalink
Use crednetial information instead of property when user is empty str…
Browse files Browse the repository at this point in the history
…ing.
  • Loading branch information
Leemoonsoo committed Apr 21, 2017
1 parent 7a0cb6c commit 1de7ea6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
11 changes: 5 additions & 6 deletions jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void open() {
logger.debug("propertyKey: {}", propertyKey);
String[] keyValue = propertyKey.split("\\.", 2);
if (2 == keyValue.length) {
logger.info("key: {}, value: {}", keyValue[0], keyValue[1]);
logger.debug("key: {}, value: {}", keyValue[0], keyValue[1]);

Properties prefixProperties;
if (basePropretiesMap.containsKey(keyValue[0])) {
Expand Down Expand Up @@ -249,6 +249,7 @@ private String getJDBCDriverName(String user, String propertyKey) {

private boolean existAccountInBaseProperty(String propertyKey) {
return basePropretiesMap.get(propertyKey).containsKey(USER_KEY) &&
!isEmpty((String) basePropretiesMap.get(propertyKey).get(USER_KEY)) &&
basePropretiesMap.get(propertyKey).containsKey(PASSWORD_KEY);
}

Expand Down Expand Up @@ -295,7 +296,6 @@ private void setUserProperty(String propertyKey, InterpreterContext interpreterC
}
}
jdbcUserConfigurations.setPropertyMap(propertyKey, basePropretiesMap.get(propertyKey));

if (existAccountInBaseProperty(propertyKey)) {
return;
}
Expand Down Expand Up @@ -576,7 +576,7 @@ private void executePrecode(Connection connection, String propertyKey) throws SQ
String precode = getProperty(String.format(PRECODE_KEY_TEMPLATE, propertyKey));
if (StringUtils.isNotBlank(precode)) {
precode = StringUtils.trim(precode);
logger.info("Run SQL precode '{}'", precode);
logger.debug("Run SQL precode '{}'", precode);
try (Statement statement = connection.createStatement()) {
statement.execute(precode);
if (!connection.getAutoCommit()) {
Expand Down Expand Up @@ -720,16 +720,15 @@ private String replaceReservedChars(String str) {

@Override
public InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter) {
logger.info("Run SQL command '{}'", cmd);
logger.debug("Run SQL command '{}'", cmd);
String propertyKey = getPropertyKey(cmd);

if (null != propertyKey && !propertyKey.equals(DEFAULT_KEY)) {
cmd = cmd.substring(propertyKey.length() + 2);
}

cmd = cmd.trim();

logger.info("PropertyKey: {}, SQL command: '{}'", propertyKey, cmd);
logger.debug("PropertyKey: {}, SQL command: '{}'", propertyKey, cmd);
return executeSql(propertyKey, cmd, contextInterpreter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,18 +339,18 @@ public void testMultiTenant() throws SQLException, IOException {
* 'jdbc1' interpreter has user('dbuser')/password('dbpassword') property
* 'jdbc2' interpreter doesn't have user/password property
* 'user1' doesn't have Credential information.
* 'user2' has 'jdbc2' Credential information that is same with database account.
* 'user2' has 'jdbc2' Credential information that is 'user2Id' / 'user2Pw' as id and password
*/

JDBCInterpreter jdbc1 = new JDBCInterpreter(getDBProperty("dbuser", "dbpassword"));
JDBCInterpreter jdbc2 = new JDBCInterpreter(getDBProperty(null, null));
JDBCInterpreter jdbc2 = new JDBCInterpreter(getDBProperty("", ""));

AuthenticationInfo user1Credential = getUserAuth("user1", null, null, null);
AuthenticationInfo user2Credential = getUserAuth("user2", "jdbc.jdbc2", "dbuser", "dbpassword");
AuthenticationInfo user2Credential = getUserAuth("user2", "jdbc.jdbc2", "user2Id","user2Pw");

// user1 runs jdbc1
jdbc1.open();
InterpreterContext ctx1 = new InterpreterContext("", "1", "jdbc.jdbc1", "", "", user1Credential,
InterpreterContext ctx1 = new InterpreterContext("", "1", "jdbc1", "", "", user1Credential,
null, null, null, null, null, null);
jdbc1.interpret("", ctx1);

Expand All @@ -361,7 +361,7 @@ public void testMultiTenant() throws SQLException, IOException {

// user1 runs jdbc2
jdbc2.open();
InterpreterContext ctx2 = new InterpreterContext("", "1", "jdbc.jdbc2", "", "", user1Credential,
InterpreterContext ctx2 = new InterpreterContext("", "1", "jdbc2", "", "", user1Credential,
null, null, null, null, null, null);
jdbc2.interpret("", ctx2);

Expand All @@ -372,7 +372,7 @@ public void testMultiTenant() throws SQLException, IOException {

// user2 runs jdbc1
jdbc1.open();
InterpreterContext ctx3 = new InterpreterContext("", "1", "jdbc.jdbc1", "", "", user2Credential,
InterpreterContext ctx3 = new InterpreterContext("", "1", "jdbc1", "", "", user2Credential,
null, null, null, null, null, null);
jdbc1.interpret("", ctx3);

Expand All @@ -383,13 +383,13 @@ public void testMultiTenant() throws SQLException, IOException {

// user2 runs jdbc2
jdbc2.open();
InterpreterContext ctx4 = new InterpreterContext("", "1", "jdbc.jdbc2", "", "", user2Credential,
InterpreterContext ctx4 = new InterpreterContext("", "1", "jdbc2", "", "", user2Credential,
null, null, null, null, null, null);
jdbc2.interpret("", ctx4);

JDBCUserConfigurations user2JDBC2Conf = jdbc2.getJDBCConfiguration("user2");
assertNull(user2JDBC2Conf.getPropertyMap("default").get("user"));
assertNull(user2JDBC2Conf.getPropertyMap("default").get("password"));
assertEquals("user2Id", user2JDBC2Conf.getPropertyMap("default").get("user"));
assertEquals("user2Pw", user2JDBC2Conf.getPropertyMap("default").get("password"));
jdbc2.close();
}

Expand Down

0 comments on commit 1de7ea6

Please sign in to comment.