Calling next() is required for mysql
@@ -206,12 +206,15 @@ public class DbAuthorizer implements Authorizer {
"SELECT COUNT(*) FROM %s WHERE %s = ? AND %s = ?",
TABLE_PERMISSIONS, COLUMN_APIKEY, COLUMN_CONTAINER_NAME);
ResultSet rs;
- boolean authorized;
+ boolean authorized = false;
try (PreparedStatement ps = _dbConn.prepareStatement(selectPermittedContainerString)) {
ps.setString(1, apiKey);
ps.setString(2, containerName);
rs = executeQuery(ps);
- authorized = rs != null && rs.getInt(1) == 1;
+ if (rs != null) {
+ rs.next();
+ authorized = rs.getInt(1) == 1;
+ }
} catch (SQLException e) {
throw new BatfishException("Could not query permissions table successfully", e);
}
@@ -268,11 +271,14 @@ public class DbAuthorizer implements Authorizer {
try (PreparedStatement ps = _dbConn.prepareStatement(selectApiKeyRowString)) {
ps.setString(1, apiKey);
rs = executeQuery(ps);
- authorized = rs != null && rs.getInt(1) == 1;
+ if (rs == null) {
+ return false;
+ }
+ rs.next();
+ authorized = rs.getInt(1) == 1;
} catch (SQLException e) {
throw new BatfishException("Could not query users table", e);
}
-
if (authorized) {
insertInCache(_cacheApiKeys, apiKey);
return true;
