@Test public void testAuthorizeContainer() { String contName = "test_container"; _authorizer.authorizeContainer(KEY1, contName); assertThat(_authorizer.isAccessibleNetwork(KEY1, contName, false), is(true)); assertThat(_authorizer.isAccessibleNetwork(KEY2, contName, false), is(false)); assertThat(_authorizer.isAccessibleNetwork(KEY3, contName, false), is(false)); assertThat(_authorizer.isAccessibleNetwork(KEY1, "gibberish", false), is(false)); assertThat(_authorizer.isAccessibleNetwork(KEY1.toUpperCase(), contName, false), is(false)); assertThat(_authorizer.isAccessibleNetwork(KEY1, contName.toUpperCase(), false), is(false)); }
@Override public void authorizeContainer(String apiKey, String containerName) { _logger.infof("Authorizing %s for %s\n", apiKey, containerName); java.sql.Date now = new java.sql.Date(new Date().getTime()); String insertContainersString = String.format( "REPLACE INTO %s (%s, %s, %s) VALUES (?, ?, ?)", TABLE_CONTAINERS, COLUMN_CONTAINER_NAME, COLUMN_DATE_CREATED, COLUMN_DATE_LAST_ACCESSED); int numInsertRows; try (PreparedStatement insertContainers = _dbConn.prepareStatement(insertContainersString)) { insertContainers.setString(1, containerName); insertContainers.setDate(2, now); insertContainers.setDate(3, now); numInsertRows = executeUpdate(insertContainers); } catch (SQLException e) { throw new BatfishException("Could not update containers table", e); } if (numInsertRows == 1) { _logger.infof("New container added\n"); } if (isAccessibleNetwork(apiKey, containerName, false)) { return; } int numRows; String insertPermissionsString = String.format( "INSERT INTO %s (%s, %s) VALUES (?, ?)", TABLE_PERMISSIONS, COLUMN_APIKEY, COLUMN_CONTAINER_NAME); try (PreparedStatement insertPermissions = _dbConn.prepareStatement(insertPermissionsString)) { insertPermissions.setString(1, apiKey); insertPermissions.setString(2, containerName); numRows = executeUpdate(insertPermissions); } catch (SQLException e) { throw new BatfishException("Could not update permissions table", e); } if (numRows > 0) { String cacheKey = getPermsCacheKey(apiKey, containerName); _cachePermissions.put(cacheKey, Boolean.TRUE); _logger.infof("Authorization successful\n"); } }
DbAuthorizer implements Authorizer { @Override public void authorizeContainer(String apiKey, String containerName) { _logger.infof("Authorizing %s for %s\n", apiKey, containerName); java.sql.Date now = new java.sql.Date(new Date().getTime()); String insertContainersString = String.format( "REPLACE INTO %s (%s, %s, %s) VALUES (?, ?, ?)", TABLE_CONTAINERS, COLUMN_CONTAINER_NAME, COLUMN_DATE_CREATED, COLUMN_DATE_LAST_ACCESSED); int numInsertRows; try (PreparedStatement insertContainers = _dbConn.prepareStatement(insertContainersString)) { insertContainers.setString(1, containerName); insertContainers.setDate(2, now); insertContainers.setDate(3, now); numInsertRows = executeUpdate(insertContainers); } catch (SQLException e) { throw new BatfishException("Could not update containers table", e); } if (numInsertRows == 1) { _logger.infof("New container added\n"); } if (isAccessibleNetwork(apiKey, containerName, false)) { return; } int numRows; String insertPermissionsString = String.format( "INSERT INTO %s (%s, %s) VALUES (?, ?)", TABLE_PERMISSIONS, COLUMN_APIKEY, COLUMN_CONTAINER_NAME); try (PreparedStatement insertPermissions = _dbConn.prepareStatement(insertPermissionsString)) { insertPermissions.setString(1, apiKey); insertPermissions.setString(2, containerName); numRows = executeUpdate(insertPermissions); } catch (SQLException e) { throw new BatfishException("Could not update permissions table", e); } if (numRows > 0) { String cacheKey = getPermsCacheKey(apiKey, containerName); _cachePermissions.put(cacheKey, Boolean.TRUE); _logger.infof("Authorization successful\n"); } } }
DbAuthorizer implements Authorizer { @Override public void authorizeContainer(String apiKey, String containerName) { _logger.infof("Authorizing %s for %s\n", apiKey, containerName); java.sql.Date now = new java.sql.Date(new Date().getTime()); String insertContainersString = String.format( "REPLACE INTO %s (%s, %s, %s) VALUES (?, ?, ?)", TABLE_CONTAINERS, COLUMN_CONTAINER_NAME, COLUMN_DATE_CREATED, COLUMN_DATE_LAST_ACCESSED); int numInsertRows; try (PreparedStatement insertContainers = _dbConn.prepareStatement(insertContainersString)) { insertContainers.setString(1, containerName); insertContainers.setDate(2, now); insertContainers.setDate(3, now); numInsertRows = executeUpdate(insertContainers); } catch (SQLException e) { throw new BatfishException("Could not update containers table", e); } if (numInsertRows == 1) { _logger.infof("New container added\n"); } if (isAccessibleNetwork(apiKey, containerName, false)) { return; } int numRows; String insertPermissionsString = String.format( "INSERT INTO %s (%s, %s) VALUES (?, ?)", TABLE_PERMISSIONS, COLUMN_APIKEY, COLUMN_CONTAINER_NAME); try (PreparedStatement insertPermissions = _dbConn.prepareStatement(insertPermissionsString)) { insertPermissions.setString(1, apiKey); insertPermissions.setString(2, containerName); numRows = executeUpdate(insertPermissions); } catch (SQLException e) { throw new BatfishException("Could not update permissions table", e); } if (numRows > 0) { String cacheKey = getPermsCacheKey(apiKey, containerName); _cachePermissions.put(cacheKey, Boolean.TRUE); _logger.infof("Authorization successful\n"); } } DbAuthorizer(String connectionString, @Nullable String driverClass, long cacheTimeout); }
DbAuthorizer implements Authorizer { @Override public void authorizeContainer(String apiKey, String containerName) { _logger.infof("Authorizing %s for %s\n", apiKey, containerName); java.sql.Date now = new java.sql.Date(new Date().getTime()); String insertContainersString = String.format( "REPLACE INTO %s (%s, %s, %s) VALUES (?, ?, ?)", TABLE_CONTAINERS, COLUMN_CONTAINER_NAME, COLUMN_DATE_CREATED, COLUMN_DATE_LAST_ACCESSED); int numInsertRows; try (PreparedStatement insertContainers = _dbConn.prepareStatement(insertContainersString)) { insertContainers.setString(1, containerName); insertContainers.setDate(2, now); insertContainers.setDate(3, now); numInsertRows = executeUpdate(insertContainers); } catch (SQLException e) { throw new BatfishException("Could not update containers table", e); } if (numInsertRows == 1) { _logger.infof("New container added\n"); } if (isAccessibleNetwork(apiKey, containerName, false)) { return; } int numRows; String insertPermissionsString = String.format( "INSERT INTO %s (%s, %s) VALUES (?, ?)", TABLE_PERMISSIONS, COLUMN_APIKEY, COLUMN_CONTAINER_NAME); try (PreparedStatement insertPermissions = _dbConn.prepareStatement(insertPermissionsString)) { insertPermissions.setString(1, apiKey); insertPermissions.setString(2, containerName); numRows = executeUpdate(insertPermissions); } catch (SQLException e) { throw new BatfishException("Could not update permissions table", e); } if (numRows > 0) { String cacheKey = getPermsCacheKey(apiKey, containerName); _cachePermissions.put(cacheKey, Boolean.TRUE); _logger.infof("Authorization successful\n"); } } DbAuthorizer(String connectionString, @Nullable String driverClass, long cacheTimeout); static DbAuthorizer createFromSettings(Settings settings); @Override void authorizeContainer(String apiKey, String containerName); @Override boolean isAccessibleNetwork(String apiKey, String containerName, boolean logError); @Override boolean isValidWorkApiKey(String apiKey); @Override String toString(); }
DbAuthorizer implements Authorizer { @Override public void authorizeContainer(String apiKey, String containerName) { _logger.infof("Authorizing %s for %s\n", apiKey, containerName); java.sql.Date now = new java.sql.Date(new Date().getTime()); String insertContainersString = String.format( "REPLACE INTO %s (%s, %s, %s) VALUES (?, ?, ?)", TABLE_CONTAINERS, COLUMN_CONTAINER_NAME, COLUMN_DATE_CREATED, COLUMN_DATE_LAST_ACCESSED); int numInsertRows; try (PreparedStatement insertContainers = _dbConn.prepareStatement(insertContainersString)) { insertContainers.setString(1, containerName); insertContainers.setDate(2, now); insertContainers.setDate(3, now); numInsertRows = executeUpdate(insertContainers); } catch (SQLException e) { throw new BatfishException("Could not update containers table", e); } if (numInsertRows == 1) { _logger.infof("New container added\n"); } if (isAccessibleNetwork(apiKey, containerName, false)) { return; } int numRows; String insertPermissionsString = String.format( "INSERT INTO %s (%s, %s) VALUES (?, ?)", TABLE_PERMISSIONS, COLUMN_APIKEY, COLUMN_CONTAINER_NAME); try (PreparedStatement insertPermissions = _dbConn.prepareStatement(insertPermissionsString)) { insertPermissions.setString(1, apiKey); insertPermissions.setString(2, containerName); numRows = executeUpdate(insertPermissions); } catch (SQLException e) { throw new BatfishException("Could not update permissions table", e); } if (numRows > 0) { String cacheKey = getPermsCacheKey(apiKey, containerName); _cachePermissions.put(cacheKey, Boolean.TRUE); _logger.infof("Authorization successful\n"); } } DbAuthorizer(String connectionString, @Nullable String driverClass, long cacheTimeout); static DbAuthorizer createFromSettings(Settings settings); @Override void authorizeContainer(String apiKey, String containerName); @Override boolean isAccessibleNetwork(String apiKey, String containerName, boolean logError); @Override boolean isValidWorkApiKey(String apiKey); @Override String toString();  }