use of org.apache.hive.jdbc.saml.IJdbcBrowserClient.HiveJdbcBrowserException in project hive by apache.
the class HiveConnection method openSession.
private void openSession() throws SQLException {
LOG.debug("Opening Hive connection session");
TOpenSessionReq openReq = new TOpenSessionReq();
Map<String, String> openConf = new HashMap<>();
// for remote JDBC client, try to set the conf var using 'set foo=bar'
for (Entry<String, String> hiveConf : connParams.getHiveConfs().entrySet()) {
openConf.put("set:hiveconf:" + hiveConf.getKey(), hiveConf.getValue());
}
// For remote JDBC client, try to set the hive var using 'set hivevar:key=value'
for (Entry<String, String> hiveVar : connParams.getHiveVars().entrySet()) {
openConf.put("set:hivevar:" + hiveVar.getKey(), hiveVar.getValue());
}
// switch the database
LOG.debug("Default database: {}", connParams.getDbName());
openConf.put("use:database", connParams.getDbName());
if (wmPool != null) {
openConf.put("set:hivevar:wmpool", wmPool);
}
if (wmApp != null) {
openConf.put("set:hivevar:wmapp", wmApp);
}
// set the session configuration
if (sessConfMap.containsKey(HiveAuthConstants.HS2_PROXY_USER)) {
openConf.put(HiveAuthConstants.HS2_PROXY_USER, sessConfMap.get(HiveAuthConstants.HS2_PROXY_USER));
}
// set create external purge table by default
if (sessConfMap.containsKey(JdbcConnectionParams.CREATE_TABLE_AS_EXTERNAL)) {
openConf.put("set:hiveconf:hive.create.as.external.legacy", sessConfMap.get(JdbcConnectionParams.CREATE_TABLE_AS_EXTERNAL).toLowerCase());
}
if (isHplSqlMode()) {
openConf.put("set:hivevar:mode", HPLSQL);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Dumping initial configuration...");
for (Map.Entry<String, String> entry : openConf.entrySet()) {
LOG.debug("{}={}", entry.getKey(), entry.getValue());
}
}
openReq.setConfiguration(openConf);
// Store the user name in the open request in case no non-sasl authentication
if (JdbcConnectionParams.AUTH_SIMPLE.equals(sessConfMap.get(JdbcConnectionParams.AUTH_TYPE))) {
openReq.setUsername(sessConfMap.get(JdbcConnectionParams.AUTH_USER));
openReq.setPassword(sessConfMap.get(JdbcConnectionParams.AUTH_PASSWD));
}
// explicitly do a HTTP post request and get the response.
try {
int numRetry = 1;
if (isBrowserAuthMode()) {
numRetry = 2;
browserClient.startListening();
}
for (int i = 0; i < numRetry; i++) {
try {
openSession(openReq);
} catch (TException e) {
if (isSamlRedirect(e)) {
boolean success = doBrowserSSO();
if (!success) {
String msg = browserClient.getServerResponse() == null || browserClient.getServerResponse().getMsg() == null ? "" : browserClient.getServerResponse().getMsg();
throw new SQLException("Could not establish connection to " + jdbcUriString + ": " + msg, " 08S01", e);
}
} else {
throw new SQLException("Could not establish connection to " + jdbcUriString + ": " + e.getMessage(), " 08S01", e);
}
}
}
} catch (HiveJdbcBrowserException e) {
throw new SQLException("Could not establish connection to " + jdbcUriString + ": " + e.getMessage(), " 08S01", e);
} finally {
if (browserClient != null) {
try {
browserClient.close();
} catch (IOException e) {
LOG.error("Unable to close the browser SSO client : " + e.getMessage(), e);
}
}
}
isClosed = false;
}
Aggregations