/** * * @return true, if the account has user privileges */ public static Predicate<User> isUserAccount() { return accountTypeEquals(Account.Type.USER); }
@Override public User get() { Iterable<User> users = Iterables.concat(client.getAccountApi().listAccounts()); Predicate<User> apiKeyMatches = UserPredicates.apiKeyEquals(creds.get().identity); User currentUser = null; try { currentUser = Iterables.find(users, apiKeyMatches); } catch (NoSuchElementException e) { throw new NoSuchElementException(String.format("none of the following users match %s: %s", apiKeyMatches, users)); } return currentUser; } }
@Test(dataProvider = "accountType") public void testAccountType(Account.Type type, boolean isUser, boolean isDomainAdmin, boolean isAdmin) { User testUser = User.builder().id("someid").accountType(type).build(); assertEquals(isUserAccount().apply(testUser), isUser); assertEquals(isDomainAdminAccount().apply(testUser), isDomainAdmin); assertEquals(isAdminAccount().apply(testUser), isAdmin); }
@Override public User get() { Iterable<User> users = Iterables.concat(client.getAccountClient().listAccounts()); Predicate<User> apiKeyMatches = UserPredicates.apiKeyEquals(creds.get().identity); User currentUser = null; try { currentUser = Iterables.find(users, apiKeyMatches); } catch (NoSuchElementException e) { throw new NoSuchElementException(String.format("none of the following users match %s: %s", apiKeyMatches, users)); } return currentUser; } }
@Test(dataProvider = "accountType") public void testAccountType(Account.Type type, boolean isUser, boolean isDomainAdmin, boolean isAdmin) { User testUser = User.builder().id("someid").accountType(type).build(); assertEquals(isUserAccount().apply(testUser), isUser); assertEquals(isDomainAdminAccount().apply(testUser), isDomainAdmin); assertEquals(isAdminAccount().apply(testUser), isAdmin); }
@Override public User get() { Iterable<User> users = Iterables.concat(client.getAccountClient().listAccounts()); Predicate<User> apiKeyMatches = UserPredicates.apiKeyEquals(creds.get().identity); User currentUser = null; try { currentUser = Iterables.find(users, apiKeyMatches); } catch (NoSuchElementException e) { throw new NoSuchElementException(String.format("none of the following users match %s: %s", apiKeyMatches, users)); } return currentUser; } }
/** * * @return true, if the user is a global admin */ public static Predicate<User> isAdminAccount() { return accountTypeEquals(Account.Type.ADMIN); } }
private static User verifyCurrentUserIsOfType(String identity, AccountClient accountClient, Account.Type type) { Iterable<User> users = Iterables.concat(accountClient.listAccounts()); Predicate<User> apiKeyMatches = UserPredicates.apiKeyEquals(identity); User currentUser; try { currentUser = Iterables.find(users, apiKeyMatches); } catch (NoSuchElementException e) { throw new NoSuchElementException(String.format("none of the following users match %s: %s", apiKeyMatches, users)); } if (currentUser.getAccountType() != type) { Logger.getAnonymousLogger().warning( String.format("Expecting an user with type %s. Got: %s", type.toString(), currentUser.toString())); } return currentUser; }
/** * @return true, is the user is a domain admin */ public static Predicate<User> isDomainAdminAccount() { return accountTypeEquals(Type.DOMAIN_ADMIN); }
@Test public void testMatchApiKey() { assertTrue(apiKeyEquals("random-text").apply( User.builder().id("random-id").apiKey("random-text").build() )); assertFalse(apiKeyEquals("something-different").apply( User.builder().id("random-id").apiKey("random-text").build() )); }
/** * @return true, is the user is a domain admin */ public static Predicate<User> isDomainAdminAccount() { return accountTypeEquals(Type.DOMAIN_ADMIN); }
private static User verifyCurrentUserIsOfType(String identity, AccountApi accountClient, Account.Type type) { Iterable<User> users = Iterables.concat(accountClient.listAccounts()); Predicate<User> apiKeyMatches = UserPredicates.apiKeyEquals(identity); User currentUser; try { currentUser = Iterables.find(users, apiKeyMatches); } catch (NoSuchElementException e) { throw new NoSuchElementException(String.format("none of the following users match %s: %s", apiKeyMatches, users)); } if (currentUser.getAccountType() != type) { Logger.getAnonymousLogger().warning( String.format("Expecting an user with type %s. Got: %s", type.toString(), currentUser.toString())); } return currentUser; }
/** * * @return true, if the account has user privileges */ public static Predicate<User> isUserAccount() { return accountTypeEquals(Account.Type.USER); }
@Test public void testMatchApiKey() { assertTrue(apiKeyEquals("random-text").apply( User.builder().id("random-id").apiKey("random-text").build() )); assertFalse(apiKeyEquals("something-different").apply( User.builder().id("random-id").apiKey("random-text").build() )); }
/** * * @return true, if the user is a global admin */ public static Predicate<User> isAdminAccount() { return accountTypeEquals(Account.Type.ADMIN); } }
/** * * @return true, if the account has user privileges */ public static Predicate<User> isUserAccount() { return accountTypeEquals(Account.Type.USER); }
/** * * @return true, if the user is a global admin */ public static Predicate<User> isAdminAccount() { return accountTypeEquals(Account.Type.ADMIN); } }
/** * @return true, is the user is a domain admin */ public static Predicate<User> isDomainAdminAccount() { return accountTypeEquals(Type.DOMAIN_ADMIN); }