@Test public void testAuthorizerCorrectness() throws Exception { Path users = _folder.newFile("users").toPath(); Path perms = _folder.newFile("perms").toPath(); Files.write(users, "{\"users\": []}".getBytes()); Files.write(perms, "{\"perms\": [{\"apikey\": \"key\", \"container\": \"cont\"}]}".getBytes()); Authorizer authorizer = new FileAuthorizer(users, perms, _logger); assertTrue(authorizer.isAccessibleNetwork("key", "cont", false)); assertFalse(authorizer.isAccessibleNetwork("key", "nocont", false)); assertFalse(authorizer.isAccessibleNetwork("nokey", "cont", false)); assertFalse(authorizer.isAccessibleNetwork("kEy", "cont", false)); assertFalse(authorizer.isAccessibleNetwork("key", "CONT", false)); }
@Override public boolean isAccessibleNetwork(String apiKey, String containerName, boolean logError) { Permissions allPerms = loadPermissions(); boolean allowed = accessAllowed(apiKey, containerName, allPerms); if (!allowed && logError) { _logger.infof("Authorizer: %s is NOT allowed to access %s\n", apiKey, containerName); } return allowed; }
FileAuthorizer implements Authorizer { @Override public boolean isAccessibleNetwork(String apiKey, String containerName, boolean logError) { Permissions allPerms = loadPermissions(); boolean allowed = accessAllowed(apiKey, containerName, allPerms); if (!allowed && logError) { _logger.infof("Authorizer: %s is NOT allowed to access %s\n", apiKey, containerName); } return allowed; } }
FileAuthorizer implements Authorizer { @Override public boolean isAccessibleNetwork(String apiKey, String containerName, boolean logError) { Permissions allPerms = loadPermissions(); boolean allowed = accessAllowed(apiKey, containerName, allPerms); if (!allowed && logError) { _logger.infof("Authorizer: %s is NOT allowed to access %s\n", apiKey, containerName); } return allowed; } FileAuthorizer(Path usersFile, Path permsFile, BatfishLogger logger); }
FileAuthorizer implements Authorizer { @Override public boolean isAccessibleNetwork(String apiKey, String containerName, boolean logError) { Permissions allPerms = loadPermissions(); boolean allowed = accessAllowed(apiKey, containerName, allPerms); if (!allowed && logError) { _logger.infof("Authorizer: %s is NOT allowed to access %s\n", apiKey, containerName); } return allowed; } FileAuthorizer(Path usersFile, Path permsFile, BatfishLogger logger); static FileAuthorizer createFromSettings(Settings settings); @Override synchronized void authorizeContainer(String apiKey, String containerName); @Override boolean isAccessibleNetwork(String apiKey, String containerName, boolean logError); @Override boolean isValidWorkApiKey(String apiKey); @Override String toString(); }
FileAuthorizer implements Authorizer { @Override public boolean isAccessibleNetwork(String apiKey, String containerName, boolean logError) { Permissions allPerms = loadPermissions(); boolean allowed = accessAllowed(apiKey, containerName, allPerms); if (!allowed && logError) { _logger.infof("Authorizer: %s is NOT allowed to access %s\n", apiKey, containerName); } return allowed; } FileAuthorizer(Path usersFile, Path permsFile, BatfishLogger logger); static FileAuthorizer createFromSettings(Settings settings); @Override synchronized void authorizeContainer(String apiKey, String containerName); @Override boolean isAccessibleNetwork(String apiKey, String containerName, boolean logError); @Override boolean isValidWorkApiKey(String apiKey); @Override String toString();  }