我的应用程序使用 Spring Framework 运行,并且必须使用 Kerberos 身份验证和 HikariCP 连接到 Hive 服务器。
我查看了 Spring Security Kerberos 的示例,但无法将其与 Hikari CP 联系起来。以下是获取与 DriverManager 的连接的代码。如何使用 DataSource 和 HikariCP ?
private String getHadoopJDBCUrl() throws IOException {
System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
System.setProperty("java.security.krb5.conf", enviroment.getProperty(KERBEROS_CONFIG_FILE));
org.apache.hadoop.conf.Configuration configuration = new org.apache.hadoop.conf.Configuration();
configuration.set("hadoop.security.authentication", "kerberos");
configuration.set("hadoop.security.auth_to_local", connectionDetails.getSecurityAuth());
UserGroupInformation.setConfiguration(configuration);
if (!(connectionDetails.getKerberosUserName().equalsIgnoreCase(Utility.EMPTY_STRING)
|| connectionDetails.getKerberosPassword().equalsIgnoreCase(Utility.EMPTY_STRING))) {
UserGroupInformation.loginUserFromKeytab(connectionDetails.getKerberosUserName(),
connectionDetails.getKerberosPassword());
}
return String.join("", connectionDetails.getJdbcURL(), "/", aggregateDetails.getDatabaseName(), ";",
connectionDetails.getPrincipal());
}
public ConnectionDetails getConnectionDetails()
throws ParseException, ClassNotFoundException, SQLException, IOException {
String JDBCUrl = Utility.EMPTY_STRING;
Class.forName(connectionDetails.getDriver());
if (connectionDetails.getType().equalsIgnoreCase(ConnectionDetails.HADOOP_PERSISTENCE)) {
JDBCUrl = getHadoopJDBCUrl();
}
connectionDetails.setConnection(DriverManager.getConnection(JDBCUrl));
return connectionDetails;
}