Я пытаюсь подключиться к Impala, используя аутентификацию JDBC и Kerberos в Java. У меня есть 2 класса, первый создает соединения, используя UserGroupInformation
и JDBC. Этот класс имеет следующий код
static final String JDBC_IMPALA_URL = "jdbc:impala://cdwork05-zzz.com:21050;"
+ "AuthMech=1;KrbRealm=XXX.COM;KrbHostFQDN=cdwork05-zzz.com;"
+ "KrbServiceName=impala;"
+ "SSL=1;AllowSelfSignedCerts=1;";
static final String JDBC_DRIVER_IMPALA ="com.cloudera.impala.jdbc41.Driver";
public Connection crearConexion2() throws ClassNotFoundException, SQLException {
Class.forName(JDBC_DRIVER_IMPALA);
con = DriverManager.getConnection(JDBC_IMPALA_URL);
return con;
}
public UserGroupInformation autenticarUsuario() throws IOException {
Configuration conf = new Configuration();
conf.set("hadoop.security.authentication", "Kerberos");
UserGroupInformation.setConfiguration(conf);
UserGroupInformation.loginUserFromKeytab( "User@XXX.COM", "/etc/security/keytabs/User.keytab");
return UserGroupInformation.getLoginUser();
}
Второй класс вызывает методы из класса подключения, этот класс имеет следующий код:
public class func_traer extends UDF{
connections connectionsutls;
Statement stmt;
public String evaluate(String fecha) {
String tb="";
String regs="";
connectionsutls = new connections();
try {
UserGroupInformation ugi = connectionsutls.autenticarUsuario();
Connection con = (Connection) ugi.doAs(new PrivilegedExceptionAction<Object>() {
public Object run() {
Connection tcon = null;
try {
tcon = connectionsutls.crearConexion2();
}catch (Exception e) {
e.printStackTrace();
}
return tcon;
}
}
);
try {
stmt = con.createStatement();
try {
String query1= "select table_name,historic_registers " +
"from statistics.incremental_statistics " +
"where table_name like 'simon.a2000160' " +
"and date_incremental like '"+fecha+"'" +
";";
ResultSet rs = stmt.executeQuery(query1);
while(rs.next()) {
tb = rs.getString("table_name");
regs = rs.getString("historic_registers");
}
connectionsutls.cerrarConexion(stmt);
return "la tabla "+tb+" tiene "+regs+" registros";
}catch (Exception e) {
return "no se ejecuto debido a :"+e;
}
}catch (Exception e) {
return "no se creo el statement "+e;
}
} catch (Exception e) {
e.printStackTrace();
return "no se pudo autenticar "+e;
}
}
}
Когда я запускаю это, я получаю исключение:
org.apache.hadoop.security.KerberosAuthException: Login failure for user: XXXX from keytab /etc/security/keytabs/XXXX.keytab javax.security.auth.login.LoginException: Pre-authentication information was invalid (24)
at org.apache.hadoop.security.UserGroupInformation.loginUserFromKeytab(UserGroupInformation.java:1134)
at woombat.connections.autenticarUsuario(connections.java:47)
at woombat.func_traer.evaluate(func_traer.java:30)
at woombat.test.main(test.java:10)
Caused by: javax.security.auth.login.LoginException: Pre-authentication information was invalid (24)
at com.sun.security.auth.module.Krb5LoginModule.attemptAuthentication(Krb5LoginModule.java:804)
at com.sun.security.auth.module.Krb5LoginModule.login(Krb5LoginModule.java:617)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at javax.security.auth.login.LoginContext.invoke(LoginContext.java:755)
at javax.security.auth.login.LoginContext.access$000(LoginContext.java:195)
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:682)
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680)
at javax.security.auth.login.LoginContext.login(LoginContext.java:587)
at org.apache.hadoop.security.UserGroupInformation.loginUserFromKeytab(UserGroupInformation.java:1125)
... 3 more
Caused by: KrbException: Pre-authentication information was invalid (24)
at sun.security.krb5.KrbAsRep.<init>(KrbAsRep.java:76)
at sun.security.krb5.KrbAsReqBuilder.send(KrbAsReqBuilder.java:316)
at sun.security.krb5.KrbAsReqBuilder.action(KrbAsReqBuilder.java:361)
at com.sun.security.auth.module.Krb5LoginModule.attemptAuthentication(Krb5LoginModule.java:776)
... 16 more
Caused by: KrbException: Identifier doesn't match expected value (906)
at sun.security.krb5.internal.KDCRep.init(KDCRep.java:140)
at sun.security.krb5.internal.ASRep.init(ASRep.java:64)
at sun.security.krb5.internal.ASRep.<init>(ASRep.java:59)
at sun.security.krb5.KrbAsRep.<init>(KrbAsRep.java:60)
... 19 more
Как мне решить эту проблему?