assert callbacks.length == 2;
cbUsername = ((NameCallback) callbacks[0]).getName();
if (StringUtilities.checkNullBlankString(cbUsername)) {
throw new FailedLoginException();
}
char[] provided = ((PasswordCallback) callbacks[1]).getPassword();
cbPassword = provided == null ? null : new String(provided);
try {
Connection conn;
if (dataSource != null) {
conn = dataSource.getConnection();
} else if (driver != null) {
conn = driver.connect(connectionURL, properties);
} else {
conn = DriverManager.getConnection(connectionURL, properties);
}
try {
PreparedStatement statement = conn.prepareStatement(userSelect);
try {
int count = statement.getParameterMetaData().getParameterCount();
for (int i = 0; i < count; i++) {
statement.setObject(i + 1, cbUsername);
}
ResultSet result = statement.executeQuery();
try {
boolean found = false;
while (result.next()) {
String userName = result.getString(1);
String userPassword = result.getString(2);
if (cbUsername.equals(userName)) {
found = true;
if (!checkPassword(userPassword, cbPassword)) {
throw new FailedLoginException();
}
break;
}
}
if (!found) {
// User does not exist
throw new FailedLoginException();
}
} finally {
result.close();
}
} finally {