@Test public void testEnsureUserHasAnyPermissionOrAdminAccess() { Permission[] repositoryPermissions = createAdminPermissions(READ, RepositoryAdminPermission::new, repository, repository1, repository2); ApplicationPermission appPerm = new ApplicationPermission("blobstores", READ); Iterable<Permission> appPermissions = singletonList(appPerm); Iterable<Repository> repositories = Arrays.asList(repository, repository1, repository2); when(securityHelper.anyPermitted(same(subject), eq(appPermissions))).thenReturn(true); underTest.ensureUserHasAnyPermissionOrAdminAccess(appPermissions, READ, repositories); verify(securityHelper, never()).ensureAnyPermitted(subject, repositoryPermissions); Iterable<Permission> multipleAppPermissions = Arrays .asList(appPerm, new ApplicationPermission("blobstores", DELETE)); when(securityHelper.anyPermitted(same(subject), eq(multipleAppPermissions))).thenReturn(true); underTest.ensureUserHasAnyPermissionOrAdminAccess(multipleAppPermissions, READ, repositories); verify(securityHelper, never()).ensureAnyPermitted(subject, repositoryPermissions); when(securityHelper.anyPermitted(same(subject), eq(appPermissions))).thenReturn(false); underTest.ensureUserHasAnyPermissionOrAdminAccess(appPermissions, READ, repositories); verify(securityHelper).ensureAnyPermitted(subject, repositoryPermissions); }
public void ensureUserHasAnyPermissionOrAdminAccess( final Iterable<Permission> permissions, final String action, final Iterable<Repository> repositories) { Subject subject = securityHelper.subject(); if (securityHelper.anyPermitted(subject, permissions)) { return; } Permission[] actionPermissions = StreamSupport.stream(repositories.spliterator(), false) .map(r -> new RepositoryAdminPermission(r, action)) .toArray(Permission[]::new); securityHelper.ensureAnyPermitted(subject, actionPermissions); }
RepositoryPermissionChecker { public void ensureUserHasAnyPermissionOrAdminAccess( final Iterable<Permission> permissions, final String action, final Iterable<Repository> repositories) { Subject subject = securityHelper.subject(); if (securityHelper.anyPermitted(subject, permissions)) { return; } Permission[] actionPermissions = StreamSupport.stream(repositories.spliterator(), false) .map(r -> new RepositoryAdminPermission(r, action)) .toArray(Permission[]::new); securityHelper.ensureAnyPermitted(subject, actionPermissions); } }
RepositoryPermissionChecker { public void ensureUserHasAnyPermissionOrAdminAccess( final Iterable<Permission> permissions, final String action, final Iterable<Repository> repositories) { Subject subject = securityHelper.subject(); if (securityHelper.anyPermitted(subject, permissions)) { return; } Permission[] actionPermissions = StreamSupport.stream(repositories.spliterator(), false) .map(r -> new RepositoryAdminPermission(r, action)) .toArray(Permission[]::new); securityHelper.ensureAnyPermitted(subject, actionPermissions); } @Inject  RepositoryPermissionChecker(final SecurityHelper securityHelper, final SelectorManager selectorManager); }
RepositoryPermissionChecker { public void ensureUserHasAnyPermissionOrAdminAccess( final Iterable<Permission> permissions, final String action, final Iterable<Repository> repositories) { Subject subject = securityHelper.subject(); if (securityHelper.anyPermitted(subject, permissions)) { return; } Permission[] actionPermissions = StreamSupport.stream(repositories.spliterator(), false) .map(r -> new RepositoryAdminPermission(r, action)) .toArray(Permission[]::new); securityHelper.ensureAnyPermitted(subject, actionPermissions); } @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); }
RepositoryPermissionChecker { public void ensureUserHasAnyPermissionOrAdminAccess( final Iterable<Permission> permissions, final String action, final Iterable<Repository> repositories) { Subject subject = securityHelper.subject(); if (securityHelper.anyPermitted(subject, permissions)) { return; } Permission[] actionPermissions = StreamSupport.stream(repositories.spliterator(), false) .map(r -> new RepositoryAdminPermission(r, action)) .toArray(Permission[]::new); securityHelper.ensureAnyPermitted(subject, actionPermissions); } @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);  }