PrincipalBasedAuthorizationConfiguration extends ConfigurationBase implements AuthorizationConfiguration { @NotNull @Override public PermissionProvider getPermissionProvider(@NotNull Root root, @NotNull String workspaceName, @NotNull Set<Principal> principals) { Filter f = filterProvider.getFilter(getSecurityProvider(), getRootProvider().createReadOnlyRoot(root), NamePathMapper.DEFAULT); if (!f.canHandle(principals)) { return EmptyPermissionProvider.getInstance(); } else { Iterable<String> principalPaths = Iterables.transform(principals, principal -> f.getOakPath(principal)); return new PrincipalBasedPermissionProvider(root, workspaceName, principalPaths, this); } } @SuppressWarnings("UnusedDeclaration")  PrincipalBasedAuthorizationConfiguration(); @NotNull @Override AccessControlManager getAccessControlManager(@NotNull Root root, @NotNull NamePathMapper namePathMapper); @NotNull @Override RestrictionProvider getRestrictionProvider(); @NotNull @Override PermissionProvider getPermissionProvider(@NotNull Root root, @NotNull String workspaceName, @NotNull Set<Principal> principals); @NotNull @Override String getName(); @NotNull @Override RepositoryInitializer getRepositoryInitializer(); @NotNull @Override List<? extends CommitHook> getCommitHooks(@NotNull String workspaceName); @NotNull @Override List<? extends ValidatorProvider> getValidators(@NotNull String workspaceName, @NotNull Set<Principal> principals, @NotNull MoveTracker moveTracker); @NotNull @Override List<ProtectedItemImporter> getProtectedItemImporters(); @NotNull @Override Context getContext(); @Activate void activate(@NotNull BundleContext context, @NotNull Configuration configuration); @Modified void modified(@NotNull BundleContext context, @NotNull Configuration configuration); @Deactivate void deactivate(@NotNull BundleContext context, @NotNull Configuration configuration); @Reference(name = "filterProvider", cardinality = ReferenceCardinality.MANDATORY) void bindFilterProvider(@NotNull FilterProvider filterProvider); void unbindFilterProvider(@NotNull FilterProvider filterProvider); @Reference(name = "mountInfoProvider", cardinality = ReferenceCardinality.MANDATORY) void bindMountInfoProvider(@NotNull MountInfoProvider mountInfoProvider); void unbindMountInfoProvider(@NotNull MountInfoProvider mountInfoProvider);  }
@Test public void testGetPermissionProvider() throws Exception { Filter filter = mock(Filter.class); when(filter.canHandle(any(Set.class))).thenReturn(Boolean.TRUE); when(filter.getOakPath(any(Principal.class))).thenReturn("/some/path"); FilterProvider fp = when(mock(FilterProvider.class).getFilter(any(SecurityProvider.class), any(Root.class), any(NamePathMapper.class))).thenReturn(filter).getMock(); PrincipalBasedAuthorizationConfiguration pbac = new PrincipalBasedAuthorizationConfiguration(); pbac.bindFilterProvider(fp); pbac.setSecurityProvider(getSecurityProvider()); pbac.setRootProvider(getRootProvider()); Set<Principal> principals = ImmutableSet.of(getTestUser().getPrincipal()); PermissionProvider pp = pbac.getPermissionProvider(root, "wspName", principals); assertTrue(pp instanceof PrincipalBasedPermissionProvider); }