RepositoryPermissionChecker { public List<Repository> userCanBrowseRepositories(final Repository... repositories) { Subject subject = securityHelper.subject(); List<Repository> filteredRepositories = new ArrayList<>(Arrays.asList(repositories)); List<Repository> permittedRepositories = userHasPermission(r -> new RepositoryViewPermission(r, BROWSE), repositories); filteredRepositories.removeAll(permittedRepositories); if (!filteredRepositories.isEmpty()) { permittedRepositories.addAll(subjectHasAnyContentSelectorAccessTo(subject, filteredRepositories)); } return permittedRepositories; } @Inject  RepositoryPermissionChecker(final SecurityHelper securityHelper, final SelectorManager selectorManager); boolean userCanBrowseRepository(final Repository repository); boolean userCanDeleteInRepository(final Repository repository); List<Repository> userCanBrowseRepositories(final Repository... repositories); void ensureUserHasAnyPermissionOrAdminAccess(
      final Iterable<Permission> permissions,
      final String action,
      final Iterable<Repository> repositories); List<Repository> userCanBrowseRepositories(final Iterable<Repository> repositories); List<Repository> userHasRepositoryAdminPermission(
      final Iterable<Repository> repositories,
      final String... actions); void ensureUserCanAdmin(final String action, final Repository repository); void ensureUserCanAdmin(final String action, final String format, final String repositoryName);  }
@Test public void testUserCanBrowseRepositories() { when(securityHelper.anyPermitted(eq(subject), any(RepositoryContentSelectorPermission.class))).then(i -> { RepositoryContentSelectorPermission p = (RepositoryContentSelectorPermission) i.getArguments()[1]; return REPOSITORY_NAME_2.equals(p.getName()); }); List<Repository> permittedRepositories = underTest.userCanBrowseRepositories(repository, repository1, repository2); assertThat(permittedRepositories, contains(repository, repository2)); permittedRepositories = underTest.userCanBrowseRepositories(Arrays.asList(repository, repository1, repository2)); assertThat(permittedRepositories, contains(repository, repository2)); }