@Test public void testApiKeyValidity() throws Exception { Path users = _folder.newFile("users").toPath(); Path perms = _folder.newFile("perms").toPath(); Files.write(users, generateUsers("key1").getBytes()); Files.write(perms, "{\"perms\": []}".getBytes()); Authorizer authorizer = new FileAuthorizer(users, perms, _logger); assertTrue(authorizer.isValidWorkApiKey("key1")); assertFalse(authorizer.isValidWorkApiKey("key2")); Files.write(users, generateUsers("key1", "key2").getBytes()); assertTrue(authorizer.isValidWorkApiKey("key1")); assertTrue(authorizer.isValidWorkApiKey("key2")); assertFalse(authorizer.isValidWorkApiKey("key3")); assertFalse(authorizer.isValidWorkApiKey("KEY1")); }
@Override public boolean isValidWorkApiKey(String apiKey) { Users allUsers = loadUsers(); boolean validUser = allUsers.users.stream().anyMatch(u -> apiKey.equals(u.apikey)); _logger.infof("Authorizer: %s is %s valid API key\n", apiKey, validUser ? "a" : "NOT a"); return validUser; }
FileAuthorizer implements Authorizer { @Override public boolean isValidWorkApiKey(String apiKey) { Users allUsers = loadUsers(); boolean validUser = allUsers.users.stream().anyMatch(u -> apiKey.equals(u.apikey)); _logger.infof("Authorizer: %s is %s valid API key\n", apiKey, validUser ? "a" : "NOT a"); return validUser; } }
FileAuthorizer implements Authorizer { @Override public boolean isValidWorkApiKey(String apiKey) { Users allUsers = loadUsers(); boolean validUser = allUsers.users.stream().anyMatch(u -> apiKey.equals(u.apikey)); _logger.infof("Authorizer: %s is %s valid API key\n", apiKey, validUser ? "a" : "NOT a"); return validUser; } FileAuthorizer(Path usersFile, Path permsFile, BatfishLogger logger); }
FileAuthorizer implements Authorizer { @Override public boolean isValidWorkApiKey(String apiKey) { Users allUsers = loadUsers(); boolean validUser = allUsers.users.stream().anyMatch(u -> apiKey.equals(u.apikey)); _logger.infof("Authorizer: %s is %s valid API key\n", apiKey, validUser ? "a" : "NOT a"); return validUser; } 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 isValidWorkApiKey(String apiKey) { Users allUsers = loadUsers(); boolean validUser = allUsers.users.stream().anyMatch(u -> apiKey.equals(u.apikey)); _logger.infof("Authorizer: %s is %s valid API key\n", apiKey, validUser ? "a" : "NOT a"); return validUser; } 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();  }