Add try catch around kerberos util to make sure SQLException is thrown if error
@@ -85,7 +85,10 @@ public class RefreshableDataSource implements DataSource {
}
public boolean testConnection(String username, String password) throws SQLException {
- return KerberosUtil.runWithOrWithoutKerberos(() -> {
+ boolean isValidConnection = false;
+
+ try {
+ isValidConnection = KerberosUtil.runWithOrWithoutKerberos(() -> {
boolean valid = false;
Connection connection = null;
Statement statement = null;
@@ -105,6 +108,11 @@ public class RefreshableDataSource implements DataSource {
}
return valid;
}, kerberosTicketConfiguration);
+ } catch(Exception e) {
+ // The utility method throws a Runtime Exception so we need to re-throw it as a SQL Exception in our case
+ throw new SQLException(e);
+ }
+ return isValidConnection;
}
private Connection getConnectionForValidation() throws SQLException {
